Function Calling: Structured Tool Use for Large Language Models › Function Calling
Language AI HandbookAll chapters Function Calling: Structured Tool Use for Large Language Models › Function CallingOne section · Sections in this chapter1 / 12 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Large language models excel at reasoning and writing as well as analysis, yet they remain confined to the text they were trained on. They cannot check the weather, calculate precise mathematical expressions, query databases, or interact with external APIs. Function calling bridges this gap by letting models to express intent to use external tools in a structured, machine-readable format. Rather than simply describing what a calculator might do, the model outputs a precise JSON object specifying which function to invoke and with what arguments. This structured output turns the model from a passive text generator into an active agent that can retrieve information, perform computations, and affect external systems.
The shift from natural language tool descriptions to structured function calling represents an important architectural decision. Early approaches to tool use relied on in-context learning, where you provided examples of tool usage within the prompt yourself. While effective for simple cases, this approach consumed valuable context window space and suffered from inconsistency as the complexity of available tools increased. Native function calling capabilities, by contrast, bake the understanding of tool schemas directly into the model's weights through specialized fine-tuning. This creates a more reliable, scalable interface, where the model learns to treat tool schemas as first-class citizens in its output space, much like it learns grammar or factual associations.
As we discussed in Tool Use Motivation, the shift from in-context tool demonstrations to native function calling capabilities represents a significant evolution in how language models interface with the world. In this chapter, we examine the mechanics of function calling: how you define tool schemas, how models generate structured calls, how execution results feed back into the generation process, and how to fine-tune models for reliable tool-use capabilities.
The terms "function calling" and "tool use" are often used interchangeably, but they carry slightly different connotations. Function calling emphasizes the mechanism: the model emits structured calls with named parameters. Tool use is the broader concept: the model employs external capabilities to answer queries. Every function call is a form of tool use, but tool use includes other patterns like web search, code execution, and memory retrieval that may not follow a strict function-call schema.
Understanding why function calling works requires thinking about the information-theoretic problem it solves. A language model generating free text must simultaneously decide what information to communicate and how to format it for the recipient. When the recipient is a human, natural language is ideal. When the recipient is a software system, natural language is ambiguous and brittle. Function calling resolves this by separating the decision of what to do (natural language understanding) from the specification of how to do it (structured output generation). The model uses its linguistic training to understand intent and its fine-tuned schema knowledge to express that intent unambiguously.