// Foundations · ~2 min read
Tool Use / Function Calling
Reach for it when: the model must call structured tools instead of inventing facts.
After this lesson you can: Give a model typed tools, check each tool call against its schema, and refuse answers that skip the tool.
// 60-second mental model
How to hold it in your head
Give the model named tools with schemas. It picks a tool and fills arguments. You run the tool. It reads the result — it does not invent the payload.
Tool use (also called function calling) gives the model declared tools, each with a schema for its inputs. The model returns a structured call; your code checks the arguments (some SDKs can enforce the schema for you with a strict mode), runs the tool, and sends the result back.
// Mini architecture
Schema → select tool → validate args → execute → observe
A user request goes to the model, which reads tool schemas from a tool catalog and picks a tool with arguments. A validator checks the arguments and, if they are wrong, asks the model to fix them. Valid calls run the tool (or MCP tool); the observation goes back to the model, which answers.
No tool call means no invented “API result”. If the schema rejects the args, fix and retry — do not freehand JSON.
// Mini-project
Weather via typed MCP tool (stub)
Stub tool server (MCP or plain function calling)
Goal: Answer “What is the weather in X?” only through a typed `get_weather` tool — never from model memory.
- Declare `get_weather({ city: string, units: "c"|"f" })` with a JSON schema.
- Model must emit a tool call; reject free-text “answers” that skip the tool.
- Validator rejects missing city or bad units; model retries once.
- Stub tool returns canned `{ temp, conditions }`.
- Final answer cites the tool payload fields only.
- Log schema violations separately from tool failures.
Stub the tool. The lesson is schema discipline and “no tool, no fact” — not live weather APIs.
// Common failure
What goes wrong
Symptom
Hallucinated tool results — the model “remembers” an API response without calling anything.
Fix
Gate the final answer: if no successful tool observation exists for the claim, refuse, or send the model back to make the call. Enforce this in your own loop: some newer models reject API settings that force a tool call.
// Self-reflection
Sit with this
Where does your agent still narrate tool output instead of requiring a real call?
Sources
Session only. Nothing is saved.