Function Calling
Function Calling is a feature supported by major LLM APIs whereby the model, instead of producing a text response, emits a structured request to invoke one of a set of tools the developer has declared; Developers supply a list of tool schemas, each describing a function name, description, and parameter types in JSON Schema format; Function calling is the primary mechanism for giving LLMs the ability to interact with external systems: querying databases, calling APIs, reading files, or sending messages
Function Calling is a feature supported by major LLM APIs whereby the model, instead of producing a text response, emits a structured request to invoke one of a set of tools the developer has declared. The model does not execute the function itself; it signals intent and the calling application handles execution, then feeds results back into the conversation.
How it works
Developers supply a list of tool schemas, each describing a function name, description, and parameter types in JSON Schema format. At inference time, the model decides whether to answer directly or to call a tool. If it opts to call a tool, it returns a tool-use message containing the function name and argument values; the application executes the function, then sends a tool-result message back so the model can continue.
Key facts
- Parallel calls: Models like GPT-4o and Claude 3.5 support calling multiple tools in a single response turn.
- Strict mode: Some APIs offer strict schema adherence, preventing hallucinated parameter names or types.
- MCP: The Model Context Protocol standardizes function calling schemas and tool discovery across different models and applications.
- Security: Tool inputs from models should be validated and sanitized before execution, as a compromised or jailbroken model could supply malicious arguments.
For builders
Function calling is the primary mechanism for giving LLMs the ability to interact with external systems: querying databases, calling APIs, reading files, or sending messages. It shifts the integration pattern from parsing free-text responses to handling structured JSON, which is dramatically more reliable. Builders should define tight schemas with clear descriptions, since the model uses the description to decide when and how to call each tool.
Sources
- Yao, S., et al. (2022). ReAct: Synergizing Reasoning and Acting in Language Models. arXiv:2210.03629. arxiv.org
- Madaan, A., et al. (2023). Self-Refine: Iterative Refinement with Self-Feedback. arXiv:2303.17651. arxiv.org
- Anthropic. Model Context Protocol specification. modelcontextprotocol.io
- Anthropic. Tool use with Claude. docs.anthropic.com
- OpenAI. Function calling guide. platform.openai.com