L

Learn AI

Track progress · learn offline

Open

Lesson 2 of 7

Function calling, deeply

7 min read

How does a text model actually do something — send an email, hit an API, run a query? It never touches your systems. It just asks.

The model asks; your code acts

Function calling — also called tool use — is the whole trick. You describe your functions to the model as a schema: name, parameters, what each does. When the model wants one, it doesn't run it — it emits a structured call (search_inbox({q:'launch'})). Your code runs it and hands the result back. The model reads that result and continues.

The model never executes anything. It emits a structured request; your runtime executes and returns the result. That gap is the entire security and reliability boundary of an agent.

Schemas are the contract

The quality of a tool call is the quality of its schema. Clear names, typed parameters, and a one-line description of when to use it do more for reliability than any prompt trick. Vague schemas cause wrong calls, hallucinated arguments, and silent failures. Treat tool definitions like a public API — because to the model, they are one.

A tool is an API contract the model reads. Invest in the schema: precise names, typed params, and a crisp "use this when…". Garbage schema in, garbage calls out.

Never trust a tool's arguments blindly. The model can hallucinate a parameter or be steered by injected text, so validate inputs and check permissions in your code before the call runs — especially for anything that writes or spends.

The shape of it

The model returns a call to `charge_card({amount: 9999})` you didn't expect. Where does the safety check belong?

Continue in the app

Take the whole AI Agents in Production course — tracked

Get your personalized path, progress and streaks in the app — this lesson and every next one, in order.