# Function calling and tool calling in LLMs: how it works and how providers differ

> Function calling lets an LLM return a structured request for your code to run. The model never executes the function. How OpenAI, Claude and Gemini differ.

Source: https://www.honeyhive.ai/learn/function-calling-llm (updated 2026-11-12)

Function calling (also called tool calling or tool use) is a model feature where you describe functions to the LLM and it replies with a structured request to call one, instead of plain text. The model never runs anything for functions you define. Your code runs the call and sends the result back, and the model writes the answer.

## The loop

OpenAI's guide [describes five steps](https://developers.openai.com/api/docs/guides/function-calling): send a request with the tools the model could call, receive a tool call, run the function in your application, send a second request with the output, and receive a final response or further tool calls. Because the last step can be another tool call, this is the loop that most [AI agents](/learn/what-are-ai-agents) are built on, as in the [ReAct pattern](/learn/react-agent).

```text
your app                          model
   | -- prompt + tool definitions --> |
   | <-- tool call (name, args) ----- |
   | run the function                 |
   | -- tool result (same call id) -> |
   | <-- answer or another call ----- |
```

The pieces are the same across providers. A tool definition has a name, a description and a JSON Schema for the arguments. OpenAI's [function definition](https://developers.openai.com/api/docs/guides/function-calling) uses `name`, `description`, `parameters` and `strict`, and Claude's [tool definition](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools) uses `name`, `description` and `input_schema`. Each call carries an id, and the result must quote it: OpenAI uses a [`call_id`](https://developers.openai.com/api/docs/guides/function-calling), Claude a [`tool_use_id`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview) and Gemini a [`call_id` on a `function_result` step](https://aistudio.google.com/docs/function-calling).

## Where the function runs

The main difference between tools is who executes them. Claude's docs separate [client tools, which run in your application, from server tools](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview) such as `web_search`, `web_fetch` and `code_execution`, which run on Anthropic's infrastructure so you see only the results. For client tools Claude returns `stop_reason: "tool_use"`, your code runs the operation and sends back a `tool_result`.

Gemini's docs say the model [doesn't execute the function itself](https://aistudio.google.com/docs/function-calling). A function call is a request your code can refuse. Anything you run on the model's say-so needs the same checks as any other untrusted input; see [prompt injection](/learn/prompt-injection) and [human-in-the-loop approval](/learn/human-in-the-loop-ai).

## Controlling when a tool is called

All three providers let you choose between letting the model decide, forcing a call and forbidding calls.

| Setting | OpenAI | Claude | Gemini |
|---|---|---|---|
| Model decides (default) | [`auto`](https://developers.openai.com/api/docs/guides/function-calling): zero, one or several functions | [`auto`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools) | [`auto`](https://aistudio.google.com/docs/function-calling) |
| Must call some tool | [`required`](https://developers.openai.com/api/docs/guides/function-calling) | [`any`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools) | [`any`](https://aistudio.google.com/docs/function-calling) |
| Must call one named tool | [Forced function](https://developers.openai.com/api/docs/guides/function-calling) | [`tool`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools) | [`allowed_tools`](https://aistudio.google.com/docs/function-calling) with `mode: any` and one tool |
| No calls | [`none`](https://developers.openai.com/api/docs/guides/function-calling) | [`none`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools) | [`none`](https://aistudio.google.com/docs/function-calling) |
| Limit to a subset | [`allowed_tools`](https://developers.openai.com/api/docs/guides/function-calling) | Not listed | [`allowed_tools`](https://aistudio.google.com/docs/function-calling) |
| Schema-validated calls | [`strict`](https://developers.openai.com/api/docs/guides/function-calling) | [`strict: true`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview) | [`validated`](https://aistudio.google.com/docs/function-calling) |

Three details matter in practice.

- **Forcing is not available everywhere.** Claude's docs say `any` and `tool` [fail on some models and settings](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools), including manual extended thinking and several newer models as of November 2026. The suggested replacement is `auto` with strict tool use.
- **Forcing removes the preamble.** With `any` or `tool`, Claude's API [prefills the assistant message](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools), so the model will not write an explanation before the call.
- **Prompting still steers `auto`.** Claude's docs say the tool boundary [is steerable through the system prompt](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview): a line such as "Use the tools to investigate before responding" increases tool use.

## Parallel and chained calls

A model can ask for several independent calls in one turn. OpenAI's guide says it [may call multiple functions](https://developers.openai.com/api/docs/guides/function-calling) per turn and that `parallel_tool_calls: false` limits it to zero or one. Claude has [`disable_parallel_tool_use`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview) on `tool_choice`. Gemini's docs describe [parallel calling for independent functions and compositional calling](https://aistudio.google.com/docs/function-calling), where later calls depend on earlier results, such as looking up a location before fetching its weather.

Each result goes back with its own call id, so run independent calls together and return every result in the next request.

## Writing tool definitions

The description is the part the model reads to decide. Claude's docs call detailed descriptions [by far the most important factor in tool performance](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools) and ask for at least three or four sentences covering what the tool does, when to use it and when not to, what each parameter means and any limits. The same page makes four more recommendations:

- Consolidate related operations into fewer tools, for example one tool with an `action` parameter rather than `create_pr`, `review_pr` and `merge_pr`.
- Prefix names with the service, such as `github_list_prs`.
- Return only high-signal fields from the tool, with stable identifiers.
- Add `input_examples` for tools with nested or format-sensitive inputs.

Cost matters too. OpenAI says definitions [count against the context limit and are billed as input tokens](https://developers.openai.com/api/docs/guides/function-calling), and Claude counts the `tools` parameter, `tool_use` and `tool_result` blocks [as tokens](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview) and adds a tool-use system prompt automatically. A long tool list also eats into the [context window](/learn/context-window).

## What still goes wrong

- **Wrong tool or invented arguments.** Claude's docs say that when a required parameter is missing, Sonnet [might infer a reasonable value](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview) instead of asking, and that this is not guaranteed either way. Strict mode fixes the shape of the arguments, not whether the value is the one the user meant. The same distinction applies to [structured output](/learn/structured-output-llm).
- **Too many tools.** OpenAI's soft limit is [under 20 functions at the start of a turn](https://developers.openai.com/api/docs/guides/function-calling). Every definition also adds input tokens, which is what a [tool search tool](/learn/tool-search-tool) is meant to reduce. When a task chains many calls, [programmatic tool calling](/learn/programmatic-tool-calling) keeps the intermediate results out of the context.
- **Unmatched ids.** Each result must quote the id of the call it answers, which is how the provider pairs them. Keep the original model steps in the history you resend, as Gemini's docs say [stateless mode requires](https://aistudio.google.com/docs/function-calling).
- **Text around the call.** Claude often writes text before a call. The docs say to [treat it like any other assistant text](https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools) and not parse it.
- **Unsafe execution.** The call is the model's output, so validate and authorize it before running it.

## Function calling vs MCP

They sit at different layers. Function calling is how a model asks for a call; the [Model Context Protocol](/learn/model-context-protocol) standardizes how tools are described, discovered and run by a server. A host app usually fetches MCP tool definitions and passes them to the model through function calling. See [MCP vs API](/learn/mcp-vs-api) for the comparison.

## Where this comes from

Schick and colleagues [introduced Toolformer](https://arxiv.org/abs/2302.04761) in February 2023, a model trained to decide which APIs to call, when, with what arguments and how to use the results. Provider function calling APIs now make this a standard interface instead of a training method, and the Berkeley [Function Calling Leaderboard](https://gorilla.cs.berkeley.edu/leaderboard.html) measures it, moving from single-turn AST checks to multi-turn interactions in its third version and agentic evaluation in its fourth.

## Tracing tool calls with HoneyHive

Tool failures show up in the trajectory, not only in the final answer. HoneyHive's [tracing](https://docs.honeyhive.ai/v2/tracing/introduction.md) captures LLM requests, tool calls and agent handoffs using OpenTelemetry, and the [tree view](https://docs.honeyhive.ai/v2/tracing/tree-view.md) nests model and tool events by parent and child, so you can click a tool span to see the inputs and outputs it actually had. For scoring, see [agent evaluation metrics](/learn/agent-evaluation-metrics) and [agent tracing](/learn/agent-tracing).

## FAQ

### Are function calling and tool calling the same thing?

In practice, yes. Anthropic's docs say [tool use is also called function calling](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview). The one distinction worth keeping is where the code runs: your application, or the provider (server tools such as web search).

### Does the model run the function?

For functions you define, no. Google's docs say the model [doesn't execute the function itself](https://aistudio.google.com/docs/function-calling); your code extracts the name and arguments and runs it. Claude's server tools are the exception, because Anthropic runs them.

### Does strict mode make tool calls correct?

It makes them match the schema, not be right. OpenAI [recommends always enabling strict mode](https://developers.openai.com/api/docs/guides/function-calling), which guarantees the shape of the arguments. The model can still pick the wrong tool or a wrong value.

### How many tools can I give a model?

OpenAI suggests [fewer than 20 functions](https://developers.openai.com/api/docs/guides/function-calling) at the start of a turn, and calls that a soft suggestion. Every definition also costs input tokens, so consolidate related operations into fewer tools.

### How do I test function calling?

Check the right tool was called with valid arguments, then check the final answer. The Berkeley [Function Calling Leaderboard](https://gorilla.cs.berkeley.edu/leaderboard.html) shows how such tests grew from single-turn checks to multi-turn and agentic evaluation.
