Skip to content

Home / Glossary / Function Calling

Definition

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.

typescript
// 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?+
They are the same concept with different names. OpenAI calls it "function calling," Anthropic calls it "tool use," and Google calls it "function declarations." All refer to the model's ability to generate structured calls to external functions.
Can function calling make mistakes?+
Yes. The model can call the wrong function, provide incorrect arguments, or call a function when none is needed. The quality depends on the model's training, the clarity of function descriptions, and the complexity of the task. Always validate function call arguments before executing them.
How does function calling relate to MCP?+
MCP (Model Context Protocol) standardizes how functions (tools) are defined and exposed to AI models. Instead of each application defining its own tool format, MCP provides a universal protocol. Function calling is the model capability; MCP is the interoperability standard built on top of it.

Related terms

Model Context Protocol (MCP)KodningsagentLarge Language Model (LLM)Tool Use

Related comparisons

Claude Code vs Gemini CLIClaude Code vs Codex CLI

Master Claude Code in days, not months

37 hands-on lessons from beginner to CI/CD automation. Module 1 is free.

START FREE →
← ALL TERMS