Home / Glossary / Function Calling
Function Calling
Function calling is an AI model capability where the model generates structured JSON arguments to invoke external functions instead of producing plain text. This enables LLMs to interact with APIs, databases, file systems, and other tools in a reliable, programmatic way—turning a conversational model into one that can take real-world actions.
How function calling works
You provide the model with a list of function definitions—each with a name, description, and parameter schema. When the model determines a function call is needed, it returns a structured JSON object with the function name and arguments instead of (or alongside) text. Your application executes the function, passes the result back to the model, and the model continues reasoning with that new information. This creates a reliable interface between the model and external systems.
Function calling vs. free-form text parsing
Before function calling, developers had to prompt the model to output structured text and parse it—a fragile approach prone to formatting errors. Function calling solves this by making the model output machine-readable JSON that conforms to a predefined schema. This is why modern AI coding tools are so much more reliable than earlier approaches: every file read, edit, and command execution is a structured function call, not parsed text.
// Defining functions for the model (Anthropic API example)
const response = await anthropic.messages.create({
model: "claude-sonnet-4-20250514",
messages: [{ role: "user", content: "What's the weather in NYC?" }],
tools: [{
name: "get_weather",
description: "Get current weather for a location",
input_schema: {
type: "object",
properties: {
location: { type: "string", description: "City name" },
unit: { type: "string", enum: ["celsius", "fahrenheit"] }
},
required: ["location"]
}
}]
});
// Model returns: { name: "get_weather", input: { location: "New York", unit: "fahrenheit" } }Write clear, specific function descriptions. The model uses these descriptions to decide when and how to call each function. A vague description leads to incorrect tool selection; a precise one leads to reliable behavior.
What is the difference between function calling and tool use?+
Can function calling make mistakes?+
How does function calling relate to MCP?+
Related comparisons
Master Claude Code in days, not months
37 hands-on lessons from beginner to CI/CD automation. Module 1 is free.
START FREE →