Function Calling Overview
From talk to action
Function calling lets an LLM request an action instead of writing prose about it. You declare tools; the model emits structured tool-call arguments; your code executes and feeds results back. That round trip turns chat into an interface.
What you will learn
- Explain the function-call round trip
- Describe how tools are declared to the model
- Handle basic tool-call execution safely
What is this?
Function calling is a structured flow: you pass tool definitions (name, description, JSON-schema arguments) to the model; when appropriate the model returns a tool_call (not free text) naming a function and precise arguments; your app executes the function with strict validation; the result goes back into the conversation. Chat becomes capable of doing things.
Why do you need it?
- Structured calls beat 'please run X and tell me' — no prose to parse.
- The model decides latency/scope: it only calls when the plan requires data.
- Arguments arrive schema-shaped, so execution is type-safe by design.
- It's the reliable primitive underneath agents and tool-using products.
Mental model
A concierge desk
Function calling
You don't hand the concierge your life; you ask, and they fill a small card (tool call: book taxi, 5pm, to airport) — structured fields, not essays. Your job (the app) is only to validate the card and relay the answer back if needed.
How it works
- Declare tools: name, description, JSON-schema arguments.
- Send user message + tool list to the model.
- Model replies with a tool_call block (function + args) or plain text.
- Your code validates args against the schema, executes the function.
- Return the tool result to the model as a tool role message.
The function-call round trip.
In production
- Chat apps add search/DB/calculator tools the model can invoke.
- Automation flows trigger backend actions from chat intents.
- Eval harnesses assert correct tool choice and argument validity.
Best practices
- Keep tool descriptions crisp; they steer selection.
- Validate args strictly — never execute unvalidated.
- Design schemas the model can obey (flat, small, useful).
- Cap the number of round trips per request.
Common mistakes
- Executing arguments the schema didn't check.
- Too many overlapping tools confusing selection.
- Forgetting to feed the tool result back into the loop.
Common issues
Model never calls toolsDescriptions unclear or task doesn't need it
Be explicit about WHEN to call in descriptions/prompt.
Tool calls fail validation mid-loopSchema mismatch with real model output
Track actual args; widen schemas; add a retry with error feedback.
Debugging tips
- Right action, wrong tool → sharpen descriptions / reduce overlap.
- Missing tool_call in reply → the model judged no tool needed; check the prompt.
- Args fail schema → enum/schema too strict vs realistic output.
Interview checkpoint
Quick quiz
A tool_call contains…
Tool results must be returned to the model to continue the loop.