Function calling (tool use)
Function calling lets a language model emit a structured request to invoke a developer-defined tool, enabling reliable JSON output and agent workflows.
Function calling (sometimes called tool use) is the API feature where you give the model a JSON schema describing one or more tools, and the model responds with a tool name + arguments instead of free text. OpenAI, Anthropic, Google, and Mistral all support it. It is the foundation of every modern agent loop: the model decides which tool to call, your code runs it, the result is fed back, and the loop continues until the model emits a final answer. Done well, it replaces brittle string parsing and unlocks reliable structured output even when JSON-mode alone fails.
When to use function calling (tool use)
- Any agent or workflow where the model needs to take external action (search, fetch, write to DB).
- Reliable structured output (more robust than "return JSON" prompting).
- Multi-step planning with tool routing.
Common mistakes
- Defining too many tools — models above ~30 tools start mis-routing.
- Vague descriptions in the schema — the model uses them as docstrings.
- Not validating the tool arguments against the schema on the server side.
FAQ
What is function calling (tool use)?
Function calling lets a language model emit a structured request to invoke a developer-defined tool, enabling reliable JSON output and agent workflows.
When should I use function calling (tool use)?
Any agent or workflow where the model needs to take external action (search, fetch, write to DB). Reliable structured output (more robust than "return JSON" prompting). Multi-step planning with tool routing.
What are the most common mistakes with function calling (tool use)?
Defining too many tools — models above ~30 tools start mis-routing. Vague descriptions in the schema — the model uses them as docstrings. Not validating the tool arguments against the schema on the server side.
Related terms
- AI agent — An AI agent is a system where a language model autonomously plans and executes a sequence of tool calls to accomplish a goal.
- JSON mode (structured output) — JSON mode forces a language model to emit only syntactically valid JSON, usually conforming to a schema you supply.
- Structured output — Structured output is any production prompt pattern that forces a language model to return data in a deterministic, machine-parseable form (JSON, XML, custom).
- System prompt — A system prompt is the high-priority instruction block that defines a model's role, constraints, and default behaviors for an entire conversation.
Last updated: 2026-06-01. Raw markdown: https://promtable.com/glossary/function-calling.md.