100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Tool Use, Function Calling & MCP
30 minadvanced

The Function Calling Contract

Every tool-using system rests on one fact that is easy to forget once the wiring works: the model never runs anything. Claude Opus 5 (`claude-opus-5`) can decide that a database needs querying or a flight needs looking up, and it can describe exactly how it wants that done, but the query itself, the HTTP request, the disk read -- all of that happens in your process, in code you wrote, under permissions you granted. The function calling contract is the agreement that makes this division workable: you promise the model a name, a description, and a parameter schema for each capability you're willing to expose, and the model promises to emit calls that conform to that schema, or to not call at all when nothing fits.

Calling it a contract rather than an "interface" or a "function signature" is deliberate. A contract has two parties, each with obligations, and it can be broken from either side. Your side breaks when the schema you publish doesn't match what your handler actually expects -- a field marked optional that your code treats as required, a type your validator never checks. The model's side breaks when it emits a call that doesn't conform: a required field left out, a string where an integer belongs, a tool name that was never declared. Almost every production bug in a tool-using system is one of these two failures, and naming the contract explicitly is what makes it possible to ask, when something goes wrong, which side broke it.

This lesson stays entirely at the level of the contract itself: what each party promises, how a single exchange is structured across a conversation's history, and how to handle the moment either party fails to hold up its end. Later lessons in this course cover the anatomy of a tool declaration, JSON Schema for parameters, and the full request-execute-return lifecycle in depth. Here, the goal is to fix the mental model before any of the syntax: two parties, two promises, one shared history that has to stay internally consistent.

Analogy🏏Cricket
🏏 Think of it like cricket: When an on-field umpire is unsure about a tight run-out at the Chinnaswamy, he does not walk over and re-run the replay himself. He raises his hands in the TV-signal shape and refers the decision to the third umpire -- but only for the exact thing the match protocol allows him to ask, decided before a ball was bowled: is the batter in the crease or out of it, using ball-tracking or the stump camera, nothing more. That protocol is agreed between the ICC and the broadcaster before the series starts: here is exactly what technology exists, here is exactly what question it answers, here is exactly what format the verdict comes back in. The on-field umpire's job is to decide WHETHER a review is needed and WHAT question to ask. The third umpire's job is to actually run the technology and return a verdict -- out, not out, or umpire's call. Neither side improvises: the on-field umpire cannot invent a new replay angle on the spot, and the third umpire cannot ignore the specific question asked and rule on something else. When Kohli is given out caught behind on a referral, the scoreboard only updates once both halves happen -- the referral and the verdict. That is the whole contract: one side promises what is available and how it is invoked, the other side promises to use it exactly as specified, and the outcome comes back paired to the question that was asked.
Lesson 2 of 35
0% complete