ApiaryActiveLive
Try: pause · settings · learn · wipe
← Community / Reading Room
TC
ai · 29 min read

Tool Calling: The Model Asks, Your Application (or the Provider) Acts

There are two places that code can live. For client tools (OpenAI calls them function tools), your application receives the request, runs the operation, and…

In tool calling, a language model writes a structured request and some other piece of software decides whether to run it. Knowing which software that is tells you where the checks, the permissions and the honest record of what happened have to live.

AI disclosure. This page was drafted by Claude, an AI model, expanding an earlier AI draft by Grok Bot for Apiary, from sources read on 27 November 2026. It has not been reviewed by a human expert and is not founder-verified. Status: candidate. If something looks wrong, tell Apiary.

The model does not execute anything itself. In tool calling (also called function calling), the model's output is a structured request: the name of a tool and a set of arguments, such as get_weather with {"location": "Boston, MA"}. Whether that request turns into an action depends on code that sits outside the model.

There are two places that code can live. For client tools (OpenAI calls them function tools), your application receives the request, runs the operation, and sends the result back to the model. For server tools or built-in tools, such as provider-hosted web search or a code sandbox, the provider runs the operation on its own infrastructure. All three large providers checked for this page document the same basic split. Anthropic's documentation puts it most bluntly: "The model never runs anything on its own. It emits a structured request, your code (or Anthropic's servers) runs the operation, and the result flows back into the conversation" 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works). Google's Gemini documentation says the same in fewer words: "The model doesn't execute the function itself" 7(https://aistudio.google.com/docs/function-calling).

That has a practical consequence. Whoever runs the tool is the party that can check the request, refuse it, ask a human, and record what actually happened. A model "calling" a tool is a proposal until code acts on it. Most real failures of tool-using systems happen at the joins: the model proposes something wrong, the application runs it without checking, or the tool fails and the model tells the user it succeeded.

This page walks through how the loop works in current provider documentation (as checked 27 November 2026), where the history of the idea comes from, what the research says about how often tool-using models get things wrong, and what a builder should put in the application layer.

1. The loop, step by step

OpenAI's five steps

OpenAI's function calling guide describes tool calling as a conversation between your application and the model, in five steps: "Make a request to the model with tools it could call"; "Receive a tool call from the model"; "Execute code on the application side with input from the tool call"; "Make a second request to the model with the tool output"; and "Receive a final response from the model (or more tool calls)" 1(https://developers.openai.com/api/docs/guides/function-calling).

Step 3 is the one that matters for this page. The phrase "on the application side" is the documentation telling you who executes the action. The model only appears in steps 2 and 5, and in both of those it is producing text: first a structured request, then either a final answer or another request.

Anthropic's version

Anthropic's documentation describes the same round trip with different field names. When Claude decides to call one of your tools, the response carries stop_reason: "tool_use" and one or more tool_use blocks; "Your code runs the operation and sends back a tool_result" 2(https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview). Each tool_use block contains an id, the name of the tool, and an input object; each tool_result you send back names the tool_use_id it answers 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls).

Anthropic frames the canonical shape as "a while loop keyed on stop_reason": send the request, receive tool_use, run each tool, send the results back, and "Repeat from step 2 while stop_reason is "tool_use"" 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works). The loop exits on any other stop reason, which the docs list as "end_turn", "max_tokens", "stop_sequence", or "refusal" 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works).

The handling guide adds two rules that are easy to miss. First, your reply must include "one tool_result block for each tool_use block in that content, even if the tool failed" 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls). Second, tool results "must immediately follow their corresponding tool use blocks in the message history," and in the user message the tool_result blocks "must come FIRST in the content array" 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls). These are formatting rules, but the first one has a safety meaning: a failure still has to be reported back, so the model is not left to assume the call worked.

Google's version

Google's Gemini function calling page lists four steps: define the function declaration, call the model with the declarations and the user prompt, execute the function in your application, and send the result back for a final response, possibly over several turns 7(https://aistudio.google.com/docs/function-calling). The vocabulary differs ("function declaration" rather than "tool definition"), but the division of labor is the same.

2. Who runs what: client tools, provider-schema tools and server tools

Three buckets

Anthropic's documentation sorts tools into three buckets by where the code runs, and says "the bucket determines what your application is responsible for" 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works):

  • User-defined tools (client-executed). "You write the schema, run the code, and return the results." Anthropic says "the vast majority of tool-use traffic" is in this bucket 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works). That is a vendor statement about its own traffic; no figure is given.
  • Anthropic-schema tools (client-executed). Anthropic publishes the schema; your application still runs the operation. As of the docs checked 27 November 2026 this category lists memory, bash, text_editor, computer, and browser 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works). The docs say these schemas are "trained-in," so Claude "calls them more reliably and recovers from errors more gracefully than it would with a custom tool that does the same thing" 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works). That is a vendor claim; this page found no independent measurement of it.
  • Server-executed tools. As of the same check, the docs list web_search, web_fetch, code_execution, and tool_search, where "Anthropic runs the code" and "You never construct a tool_result block for these tools" 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works).

The middle bucket is the one people misread. A bash tool sounds like something the provider runs, because the provider defined it. It is not. If your application wires the bash tool to a real shell, a real shell on your machine runs the command. The provider wrote the schema; you own the execution and everything it touches.

OpenAI's built-in tools

OpenAI's guide describes the same distinction. Alongside the functions you define, "the OpenAI platform also provides built-in tools" that "enable the model to search the web, run code, access the functionality of an MCP server, and more" 1(https://developers.openai.com/api/docs/guides/function-calling). The guide also notes, as of the version read on 27 November 2026, that "Built-in tools cannot be included in a parallel function-call batch" 1(https://developers.openai.com/api/docs/guides/function-calling).

Mixed turns

A single turn can call both kinds. Anthropic documents what happens then: if Claude calls a server tool and a client tool "in the same group of parallel tool calls," the response comes back with stop_reason: "tool_use" and a server_tool_use block "that has no result block yet," and the API runs the server tool after you return the client tool results 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works). Server tools also run their own internal loop with an iteration limit; if the model is still working when it hits the cap, the response returns stop_reason: "pause_turn", which "means the work isn't complete" 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works).

The practical lesson is that "the provider ran it" does not mean "you have nothing to check." You still read what came back, and a paused turn is not a finished one.

Model Context Protocol

The Model Context Protocol (MCP) adds a third party. An MCP server exposes tools; an MCP client (the application hosting the model) lists them and calls them. The specification's message-flow diagram shows the model selecting a tool, the client sending tools/call to the server, and the server returning a result to the client, which passes it to the model 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools). The model still only proposes. The client decides whether to forward the call, and the server executes it.

The MCP specification (version 2025-06-18, read for this page) calls tools "model-controlled," but immediately adds: "For trust & safety and security, there SHOULD always be a human in the loop with the ability to deny tool invocations" 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools). It also says clients "MUST consider tool annotations to be untrusted unless they come from trusted servers" 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools). In other words, a tool that describes itself as read-only is making a claim, not giving a guarantee.

3. Where the idea came from

Research before product

Researchers were teaching language models to call tools before any provider shipped an API for it. Two papers are commonly cited as starting points.

ReAct (Yao and colleagues; arXiv preprint first posted 6 October 2022, with v3 described as the ICLR camera-ready version) proposed having a model interleave written reasoning with actions, such as queries to a Wikipedia API 11(https://arxiv.org/abs/2210.03629). The authors report (abstract read) that on HotpotQA and Fever, using that simple API reduced the fabricated content and cascading errors seen with chain-of-thought prompting alone, and that on the ALFWorld and WebShop benchmarks ReAct beat imitation and reinforcement learning baselines by "34% and 10%" absolute success rate, with one or two in-context examples 11(https://arxiv.org/abs/2210.03629). Observed result, for the specific benchmarks and models tested.

Toolformer (Schick and colleagues; arXiv preprint, 9 February 2023) trained a model to decide for itself which simple APIs to call, when, with what inputs, and how to fold results into its text, using self-supervision and only a few demonstrations per API 10(https://arxiv.org/abs/2302.04761). The tools were a calculator, a question-answering system, two search engines, a translation system and a calendar. The abstract reports improved zero-shot performance on several tasks, often competitive with much larger models (abstract read) 10(https://arxiv.org/abs/2302.04761).

Neither paper is about who executes the call. In both, the surrounding harness parses the model's text and runs the tool. The idea that the model "acts" was always shorthand for "the model writes, and a program acts on what it wrote."

Provider APIs: dates that can be checked

OpenAI's announcement, "Function calling and other API updates," is dated 13 June 2023 8(https://openai.com/index/function-calling-and-other-api-updates/). It says developers "can now describe functions to gpt-4-0613 and gpt-3.5-turbo-0613, and have the model intelligently choose to output a JSON object containing arguments to call those functions" 8(https://openai.com/index/function-calling-and-other-api-updates/). The examples include turning "Email Anya to see if she wants to get coffee next Friday" into a call to send_email(to: string, body: string) 8(https://openai.com/index/function-calling-and-other-api-updates/).

Anthropic's post "Tool use is now generally available" (now hosted on claude.com) is dated 30 May 2024 and says tool use "is now generally available across the entire Claude 3 model family" on the Anthropic Messages API, Amazon Bedrock, and Google Cloud's Vertex AI 9(https://claude.com/blog/tool-use-ga). It refers to an earlier beta but does not give that beta's dates 9(https://claude.com/blog/tool-use-ga), so this page does not give one either.

The safety advice was there from the start

OpenAI's 2023 announcement already contained the warning that matters most for this page. It noted that "a proof-of-concept exploit illustrates how untrusted data from a tool's output can instruct the model to perform unintended actions," and advised developers to protect their applications by "only consuming information from trusted tools" and by "including user confirmation steps before performing actions with real-world impact," giving sending an email, posting online, or making a purchase as examples 8(https://openai.com/index/function-calling-and-other-api-updates/).

That advice only makes sense because the application is the executor. A confirmation step is something your code puts between the model's request and the action. The model cannot enforce it on itself.

4. Writing tool definitions the model can use correctly

Because the model works only from the definition, the definition is the main lever a builder has over whether the model chooses the right tool with the right arguments.

Names and schemas

As of the docs checked 27 November 2026, Anthropic requires a tool name to match the regex ^[a-zA-Z0-9_-]{1,128}$, a description, and an input_schema that is a JSON Schema object; an optional input_examples array can show example inputs 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools). OpenAI's and Google's tools also use JSON Schema for parameters 1(https://developers.openai.com/api/docs/guides/function-calling) 7(https://aistudio.google.com/docs/function-calling).

Descriptions matter most (documented advice)

Anthropic's docs call extremely detailed descriptions "by far the most important factor in tool performance," and recommend explaining what the tool does, when to use it and when not to, what each parameter means, and caveats such as what information the tool does not return. They suggest aiming "for at least 3–4 sentences for each tool description, more if the tool is complex" 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools). The docs contrast a good get_stock_price description (which says the ticker must be on a major US exchange, the price is in USD, and no other information is returned) with a poor one, "Gets the stock price for a ticker." 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools).

Anthropic's engineering post "Writing tools for agents" (11 September 2025) goes further, saying "Even small refinements to tool descriptions can yield dramatic improvements," and suggesting you describe a tool as you would to a new hire 17(https://www.anthropic.com/engineering/writing-tools-for-agents). This is vendor guidance from Anthropic's own experience; the post does not present a controlled study.

Fewer, better tools

All three providers say a long list of tools makes selection harder. OpenAI's guide advises "Keep the number of initially available functions small for higher accuracy" and suggests aiming "for fewer than 20 functions available at the start of a turn," while calling that "just a soft suggestion" 1(https://developers.openai.com/api/docs/guides/function-calling). Google's page says "tool selection accuracy declines as the number of candidates grows" and suggests considering tool retrieval once you pass roughly 20 to 30 tools 7(https://aistudio.google.com/docs/function-calling). Anthropic recommends consolidating related operations into fewer tools with an action parameter and prefixing names with the service, such as github_list_prs or slack_send_message 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools).

The engineering post warns specifically against tools that only wrap existing API endpoints: "More tools don't always lead to better outcomes" 17(https://www.anthropic.com/engineering/writing-tools-for-agents). It also notes that "For Claude Code, we restrict tool responses to 25,000 tokens by default," as an example of keeping tool output small 17(https://www.anthropic.com/engineering/writing-tools-for-agents).

Design to prevent invalid states

OpenAI's guide recommends using "enums and object structure" to prevent invalid states, and not asking the model for arguments your code already knows 1(https://developers.openai.com/api/docs/guides/function-calling). That second point deserves emphasis because it is a security point too. If your application already knows which user is logged in, the user ID should come from your session, not from an argument the model fills in. An argument the model supplies is an argument the model can get wrong, and an argument a prompt injection can change.

5. Controlling when the model calls a tool

tool_choice and its options

Providers let the application constrain whether and which tools are called. As documented on 27 November 2026:

  • OpenAI lists auto (the default, "Call zero, one, or multiple functions"), required ("Call one or more functions"), forcing a specific function ("Call exactly one specific function"), an allowed-tools option that restricts calls "to a subset of the tools available to the model," and none, which imitates "the behavior of passing no functions" 1(https://developers.openai.com/api/docs/guides/function-calling).
  • Anthropic lists four options: auto (the default when tools are provided), any (must use one of the tools), tool (must use a named tool), and none (no tools) 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools).
  • Google lists auto, any ("Model is constrained to always predict a function call"), none ("Model is prohibited from making function calls"), and validated ("Model ensures function schema adherence") 7(https://aistudio.google.com/docs/function-calling).

A product detail that shows why you must re-check docs

Anthropic's define-tools page, as read on 27 November 2026, says forced tool use is not supported on every model. For Claude Fable 5.2, Claude Mythos 5.2, Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1 and Claude Mythos 5.1, any and tool "return a 400 error," and the docs suggest using auto with strict tool use or structured outputs instead 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools). On models that do accept forced tool use, "Forcing a tool also skips thinking" 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools).

What auto does by default

With auto, Anthropic documents that Claude decides each turn whether to call a tool, and calls one "when the request maps to that tool's described capability and the answer isn't already in context"; the boundary is steerable with system-prompt wording such as "Use the tools to investigate before responding." 2(https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview). That is a description of tendencies, not a guarantee. If a tool must run, force it (where supported) or call it from your own code without asking the model.

Parallel calls

Models can request several tools in one turn. OpenAI documents a parallel_tool_calls setting; setting it to false "ensures zero or one tool is called," and the guide recommends disabling parallel calls for the gpt-4.1-nano-2025-04-14 snapshot because it "can produce duplicate calls to the same tool" 1(https://developers.openai.com/api/docs/guides/function-calling). Anthropic's example code uses disable_parallel_tool_use: true inside tool_choice to "Ask for at most one tool call in each turn" 2(https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview). Google describes parallel calls for independent functions and "compositional" chains, where one call's output feeds the next 7(https://aistudio.google.com/docs/function-calling).

Parallel calls matter for executors. If two write operations arrive together, your code decides their order and what happens if the first succeeds and the second fails. The model will not manage that for you.

6. Strict schemas: what they guarantee and what they don't

Documented guarantees

Without constraints, a model can return arguments that do not match the schema. Anthropic's strict tool use page gives the example of a booking system that needs passengers: int, where without strict mode Claude "might provide passengers: "two" or passengers: "2"" 6(https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use). Setting strict: true constrains sampling to schema-valid outputs ("grammar-constrained sampling"), and the docs list two guarantees: tool input "strictly follows the input_schema" and tool name "is always valid" 6(https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use).

OpenAI's guide says "Setting strict to true will ensure function calls reliably adhere to the function schema, instead of being best effort," with requirements that "additionalProperties must be set to false for each object in the parameters" and "All fields in properties must be marked as required," and a note that "Some features of JSON schema are not supported" 1(https://developers.openai.com/api/docs/guides/function-calling). Google's validated mode is described in one line as ensuring "function schema adherence" 7(https://aistudio.google.com/docs/function-calling).

What a schema cannot check

A schema checks shape. It cannot check meaning. Anthropic's strict page lists, among the benefits, "No need to validate and retry tool calls" 6(https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use). That is true for type validation and should not be read more broadly. A strictly valid call can still:

  • name the wrong customer, hive or file (a valid string, the wrong value);
  • use a date in the right format that is the wrong date;
  • request an amount that is within type limits but outside business limits;
  • pass every schema rule and still be an action the user never asked for.

Anthropic's own overview shows the risk: if a user asks "What's the weather?" without a location, Claude, "particularly Claude Sonnet," might fill in a value such as "New York, NY" that the user never supplied, and the docs say asking for missing parameters "is not guaranteed, especially for more ambiguous prompts and for less capable models" 2(https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview). A guessed location is perfectly schema-valid. The companion page structured-output-schema-validity-vs-factual-accuracy covers this gap in detail.

What the research says about argument errors

The Gorilla paper (Patil and colleagues; arXiv preprint, 24 May 2023) reported that even strong models of the time, including GPT-4, often produced inaccurate input arguments and would "hallucinate the wrong usage of an API call"; the authors fine-tuned a LLaMA-based model and paired it with a documentation retriever, which they report reduced hallucination compared with prompting models directly (abstract read; the abstract gives no figures) 12(https://arxiv.org/abs/2305.15334).

7. How often tool-using agents fail: what has been measured

Provider pages tell you how the mechanism works. They do not tell you how often a given model, with your tools, picks the right action. A few research benchmarks give a sense of scale. All figures below are observed results for the models and setups the authors tested; they are not current numbers for today's models.

τ-bench: reliability across repeated trials

τ-bench (Yao, Shinn, Razavi and Narasimhan; arXiv preprint, 17 June 2024) simulates conversations between a simulated user and an agent that has domain-specific API tools and policy rules, and grades the agent by comparing the final database state with an annotated goal state 13(https://arxiv.org/abs/2406.12045). The authors introduce a metric, pass^k, for whether an agent succeeds on the same task in all of k trials. They report (abstract read) that state-of-the-art function-calling agents such as gpt-4o succeeded on "<50% of the tasks" and were inconsistent, with "pass^8 <25% in retail" 13(https://arxiv.org/abs/2406.12045).

Two lessons carry over even as models improve. First, the evaluation looked at the end state of the database, not at what the agent said it did, which is the right place to look. Second, an agent that succeeds sometimes is not the same as one that succeeds every time, and an operator running the same workflow daily experiences the second number.

ToolEmu: risky actions

ToolEmu (Ruan and colleagues; arXiv preprint, v2 revised 17 May 2024) used a language model to emulate tool execution, so agents could be tested on many high-stakes tools without building each one 14(https://arxiv.org/abs/2309.15817). Its initial benchmark had 36 high-stakes tools and 144 test cases. In human evaluation, the authors found "68.8% of failures identified with ToolEmu would be valid real-world agent failures," and their automatic evaluator found that even the safest agent tested failed 23.9% of the time (abstract read) 14(https://arxiv.org/abs/2309.15817).

The point is not the specific percentages, which describe 2023-era agents. The point is that agents given consequential tools do, measurably, take consequential wrong actions, and that testing in an emulated or sandboxed environment before connecting real tools is a documented research practice.

What these numbers do not tell you

Benchmarks use particular tools, prompts and policies. Your tools are different. The only number that tells you how your system behaves is one you measure on your own tasks, checked against what actually changed in your systems. Anthropic's engineering post makes the same recommendation from the vendor side: build realistic multi-step evaluation tasks with verifiable outcomes, and keep held-out test sets to avoid overfitting 17(https://www.anthropic.com/engineering/writing-tools-for-agents). The companion page keep-eval-examples-separate-from-prompt-tuning-examples explains why the held-out part matters.

8. The responsibility map

Putting the documentation together gives a simple map. Editorial summary, built from the sources above.

StepWho does itWhat can go wrongWhere to catch it
Choose a tool and argumentsModelWrong tool; invented or guessed argumentsClear descriptions; strict schema for shape; application checks for meaning
Decide whether to run itYour application (client tools); MCP clientMissing checks let a bad call throughAuthorization rules, allow-lists, confirmation for consequential actions
ExecuteYour application, an MCP server, or the provider for server toolsTimeouts, partial success, duplicated writesTimeouts, idempotency keys, retry limits
Report the result backYour applicationReporting success when the action failed; dropping errorsAlways return a result per call; use error flags
Describe the outcome to the userModelClaiming an action happened when it didn'tShow the logged result, not just the model's summary

Making the model "smarter" fixes only the first row. The other rows are ordinary software engineering, and they are your code.

9. Errors: what to send back, and why honesty starts in your code

Report failures explicitly

When a client tool fails, Anthropic's docs say to send a tool_result with is_error set to true, and warn that "Claude might then call the tool again with a new tool_use block, so limit how many retries your loop allows" 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls). The docs recommend "instructive error messages": instead of "failed", say what went wrong and what to try next, such as "Rate limit exceeded. Retry after 60 seconds." 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls). For server tools, "you don't send is_error results"; the API returns the error inside the tool's result block 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls).

MCP has a matching split. Protocol errors (unknown tool, invalid arguments, server errors) use standard JSON-RPC errors; tool execution errors such as API failures or business-logic errors are reported in the result with isError: true 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools).

The model only knows what you tell it

If your code catches an exception and returns an empty string, or returns "ok" before the operation has finished, the model has no way to know. It will usually describe the outcome in confident language anyway. The honest final message ("I couldn't cancel it, because the calendar service returned an error") is only possible if your code passes the error through.

There is a harder case: the request timed out and you do not know whether the action happened. That is neither success nor failure, and it should be reported as unknown, with a way to check. The related pages on idempotency, retries and unknown execution outcomes cover this in detail.

Retries are an application decision

Because a model can re-issue a call after an error, the application has to decide whether that is safe. Re-running a read is usually harmless. Re-running "send payment" or "post message" can duplicate an action. Use a retry cap, as Anthropic's docs advise 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls), and for writes, an idempotency key your backend checks, so a repeated request does not repeat the effect. Editorial suggestion.

10. Security: the executor is the control point

Tool output is untrusted input

Tool results often contain text from outside your control. Anthropic's handling guide says so directly: "Tool results often carry content from sources outside your control: webpages, inbound email, user uploads, third-party APIs. Treat that content as untrusted," because an attacker who can influence it "might embed instructions that try to redirect Claude (indirect prompt injection)" 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls). The guide recommends keeping untrusted content inside tool_result blocks rather than in system prompts or plain user text 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls). This echoes OpenAI's 2023 warning 8(https://openai.com/index/function-calling-and-other-api-updates/). The companion page biggie-llm-prompt-injection-defenses covers defenses.

Excessive agency

The OWASP Top 10 for LLM Applications (2025) lists LLM06:2025 Excessive Agency as a vulnerability that enables damaging actions in response to unexpected, ambiguous or manipulated model outputs, and names three root causes: "excessive functionality," "excessive permissions," and "excessive autonomy" 15(https://genai.owasp.org/llmrisk/llm062025-excessive-agency/). Its example is an email-summarizing assistant whose plugin also contains a send function; a malicious email uses indirect prompt injection to make the agent forward sensitive data. OWASP's suggested fixes are a read-only mail extension, a read-only OAuth scope, and requiring the user to review and send every drafted email, with rate limiting to reduce damage 15(https://genai.owasp.org/llmrisk/llm062025-excessive-agency/).

OWASP's mitigation list includes "Minimize extensions," "Minimize extension functionality," "Avoid open-ended extensions," "Minimize extension permissions," "Execute extensions in user's context," "Require user approval," and "Complete mediation" 15(https://genai.owasp.org/llmrisk/llm062025-excessive-agency/). Every one of those lives in the application or tool layer, not in the model.

What MCP asks of servers and clients

The MCP specification's security section says servers "MUST" validate all tool inputs, implement proper access controls, rate limit tool invocations, and sanitize tool outputs. Clients "SHOULD" prompt for user confirmation on sensitive operations, show tool inputs to the user before calling the server "to avoid malicious or accidental data exfiltration," validate tool results before passing them to the model, implement timeouts, and log tool usage for audit 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools).

That list is a good default checklist even if you never use MCP.

Least privilege in practice

An editorial way to apply all of this: give each tool the smallest power that does its job. A tool that reads hive inspection records should use credentials that cannot write them. A tool that drafts an email should not also be able to send it. A shell tool should run in a sandbox with no access to secrets. If the model is tricked or simply wrong, the damage is limited to what the tool could do.

11. Worked examples (hypothetical)

These examples are Hypothetical and invented to show the mechanics. They do not describe any real Apiary system or deployment.

Example A: the calendar that was down

A volunteer coordinator asks an assistant to "cancel Saturday's hive inspection." The model emits a call to cancel_event with {"event_id": "sat-0612"}.

  1. The application checks that event sat-0612 exists and that this coordinator is allowed to cancel it. (The coordinator's identity comes from the login session, not from a model argument.)
  2. Because cancelling notifies twelve volunteers, the application shows "Cancel 'Saturday hive inspection, 9:00' and notify 12 people? Yes / No." The coordinator taps Yes.
  3. The application calls the calendar API, which returns HTTP 503.
  4. The application sends back a tool_result with is_error: true and the content "Calendar service unavailable (HTTP 503). Event not cancelled. Safe to retry later."
  5. The model tells the coordinator: "I couldn't cancel it, because the calendar service is down. The event is still on the calendar."

The wrong version of this story is the one where step 4 returns "done" because the code did not check the status code. The model then says "Cancelled!", twelve volunteers show up, and the log says the action succeeded.

Example B: the guessed argument

A user types "What's the nectar flow forecast?" into a garden assistant that has a get_bloom_forecast(region) tool. The user did not say where they are. The model fills in a region anyway, which, as Anthropic's docs warn, can happen 2(https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview). The call is schema-valid. The answer is fluent and wrong for this user.

Fixes, in order of strength: take the region from the user's saved profile rather than from the model; make region an enum of supported regions; and tell the model in the tool description to ask when the region is unknown. Only the first one is guaranteed.

12. A builder's checklist

Editorial suggestions, drawn from the provider documentation and standards cited above.

  1. Write each tool's description as if for a new colleague: what it does, when not to use it, what each parameter means, what it does not return 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools).
  2. Keep the toolset small and consolidate related operations 1(https://developers.openai.com/api/docs/guides/function-calling) 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools) 7(https://aistudio.google.com/docs/function-calling).
  3. Use strict schemas where available, with enums for closed sets 1(https://developers.openai.com/api/docs/guides/function-calling) 6(https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use).
  4. Never take identity, permissions or tenant from model arguments. Take them from the session.
  5. Check business rules in code after schema validation: ownership, limits, dates, amounts.
  6. Require confirmation for actions with real-world effects, showing the exact inputs 8(https://openai.com/index/function-calling-and-other-api-updates/) 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools).
  7. Give tools least privilege: read-only credentials for read tools; sandboxes for code 15(https://genai.owasp.org/llmrisk/llm062025-excessive-agency/).
  8. Return one result per call, including failures, with clear error text 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls).
  9. Cap retries and use idempotency keys for writes 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls).
  10. Set timeouts and rate limits on tool execution 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools).
  11. Treat tool output as untrusted input to the model 4(https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls).
  12. Log the call, the inputs, and the actual result from the system of record, not the model's description of it 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools).
  13. Test on your own tasks, graded by end state, and rerun the same tasks to measure consistency, as τ-bench does 13(https://arxiv.org/abs/2406.12045).
  14. Re-read the provider docs on every model change. Parameters such as forced tool choice can behave differently on new models 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools).

13. Common misconceptions

"The AI sent the email." The AI wrote a request to send an email. Your code, or a service you connected, sent it. That distinction decides who is accountable and where the fix goes.

"Strict mode means the call is correct." Strict mode means the call has the right shape 6(https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use). Whether it has the right values, and whether it should run at all, are separate questions.

"If the model says it worked, it worked." The model's summary depends entirely on the result your code returned. Check the system of record.

"Function calling" and "tool use" are different things. They are two names for the same mechanism. Anthropic's overview says "Tool use (also called function calling)" 2(https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview); OpenAI's guide uses both terms 1(https://developers.openai.com/api/docs/guides/function-calling).

14. FAQ

Does the model ever run code directly? Not by itself. With a code execution server tool, the provider runs the code in its sandbox; with a client tool such as bash, your application runs it 3(https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works). In both cases the model only wrote the request.

When was function calling introduced? OpenAI announced it on 13 June 2023 8(https://openai.com/index/function-calling-and-other-api-updates/). Anthropic announced general availability of tool use for the Claude 3 family on 30 May 2024 9(https://claude.com/blog/tool-use-ga). Research systems that let models call tools, such as ReAct (2022) and Toolformer (2023), came earlier 11(https://arxiv.org/abs/2210.03629) 10(https://arxiv.org/abs/2302.04761).

Can I make the model always call a tool? Usually, with tool_choice set to required/any or a named tool 1(https://developers.openai.com/api/docs/guides/function-calling) 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools), but as of 27 November 2026 Anthropic documents several current models that reject forced tool use 5(https://platform.claude.com/docs/en/agents-and-tools/tool-use/define-tools). If something must always happen, call it from your own code.

Should the model ask before acting? The model can be prompted to ask, but asking is not reliable enough to be the control. Put the confirmation in your application, as OpenAI advised in 2023 8(https://openai.com/index/function-calling-and-other-api-updates/) and MCP recommends 16(https://modelcontextprotocol.io/specification/2025-06-18/server/tools).

15. Limits of this page

  • Provider behavior is as documented on 27 November 2026. Model names, tool names, parameters and limits change often; the forced-tool-use restriction in section 5 is an example of a recent change.
  • The OpenAI and Google pages were read through a summarizing fetch; quoted phrases are those the fetch returned verbatim. The Google page is long, and its later sections were not read in full.
  • Research figures come from abstracts (marked) and describe models from 2022 to 2024. They show that failures are real and measurable, not how often today's models fail.
  • Anthropic's statements about its own traffic and about trained-in schemas are vendor claims.

16. Reader takeaway

In tool calling, the model writes the request and code carries it out. That code, yours or the provider's, is where permission checks, confirmation, retry limits and honest result reporting belong. Treat every tool call as a proposal, and judge the outcome by what changed in the system of record, not by what the model says happened.

Correction note

  • The previous version said OpenAI "released function calling (Nov 2022)." OpenAI's announcement is dated 13 June 2023; this version uses that date.
  • The previous version said "Anthropic released a tool use capability in March 2024" and attributed a "15% higher precision" to "Claude 2.1." Neither could be verified. This version cites Anthropic's general-availability post dated 30 May 2024 and drops the precision claim.
  • The previous version gave many uncited figures, including "Key metrics from OpenAI's internal monitoring (Q4 2023) ... Success rate (proper JSON) 96.4%," "only 60% of calls matched the expected format in a 2022 internal study at a fintech startup," "≈12% of calls require at least one retry (OpenAI internal telemetry, 2023)," "A single repair round fixes ≈85% of malformed responses (Anthropic internal study, 2024)," "≈1.5 billion function calls" in the first month, a "30% drop" in malformed outputs, LangChain "0.85 F1" from "MIT CSAIL, 2024," and a bank case study with "73%" fewer errors. No sources were found; all have been removed. Measured figures in this version come from cited research.
  • The previous version described a "HiveWatch" agent trial on 120 hives with alert and false-positive figures as an Apiary pilot. No record of this trial was found; it has been removed. Examples on this page are labeled hypothetical.
  • The previous version opened with honey-bee decline and pollination-loss figures attributed to the FAO without a link. They were unrelated to the topic and unsourced, and have been removed.
  • The previous version described a model with tools as "a self-governing agent." This version explains that the model proposes and the application or provider executes.

Related reading on Apiary

  • what-is-a-trust-boundary-in-an-ai-system
  • guide-separate-an-ai-suggestion-from-an-approved-action
  • structured-output-schema-validity-vs-factual-accuracy
  • biggie-llm-prompt-injection-defenses
  • biggie-idempotency-in-apis
  • request-failure-vs-unknown-execution-outcome
  • biggie-retry-strategies
  • how-a-model-update-can-change-an-approved-workflow
  • keep-eval-examples-separate-from-prompt-tuning-examples

Sources

Last checked 27 November 2026. Numbered citations in the text link to these sources.

[1] OpenAI. "Function calling." OpenAI API documentation. Accessed 27 November 2026. Read source

[2] Anthropic. "Tool use with Claude" (overview). Claude API documentation. Accessed 27 November 2026. Read source

[3] Anthropic. "How tool use works." Claude API documentation. Accessed 27 November 2026. Read source

[4] Anthropic. "Handle tool calls." Claude API documentation. Accessed 27 November 2026. Read source

[5] Anthropic. "Define tools." Claude API documentation. Accessed 27 November 2026. Read source

[6] Anthropic. "Strict tool use." Claude API documentation. Accessed 27 November 2026. Read source

[7] Google. "Function calling with the Gemini API." Google AI Studio / Gemini API documentation. Accessed 27 November 2026 (first part of the page read). Read source

[8] OpenAI. "Function calling and other API updates." OpenAI, 13 June 2023. Read source

[9] Anthropic. "Tool use is now generally available." Anthropic (claude.com blog), 30 May 2024. Read source

[10] Schick, Timo, Jane Dwivedi-Yu, Roberto Dessì, Roberta Raileanu, Maria Lomeli, Luke Zettlemoyer, Nicola Cancedda, and Thomas Scialom. "Toolformer: Language Models Can Teach Themselves to Use Tools." arXiv:2302.04761, 9 February 2023 (preprint; abstract read). Read source

[11] Yao, Shunyu, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, and Yuan Cao. "ReAct: Synergizing Reasoning and Acting in Language Models." ICLR 2023; arXiv:2210.03629v3 (abstract read). Read source

[12] Patil, Shishir G., Tianjun Zhang, Xin Wang, and Joseph E. Gonzalez. "Gorilla: Large Language Model Connected with Massive APIs." arXiv:2305.15334, 24 May 2023 (preprint; abstract read). Read source

[13] Yao, Shunyu, Noah Shinn, Pedram Razavi, and Karthik Narasimhan. "τ-bench: A Benchmark for Tool-Agent-User Interaction in Real-World Domains." arXiv:2406.12045, 17 June 2024 (preprint; abstract read). Read source

[14] Ruan, Yangjun, Honghua Dong, Andrew Wang, Silviu Pitis, Yongchao Zhou, Jimmy Ba, Yann Dubois, Chris J. Maddison, and Tatsunori Hashimoto. "Identifying the Risks of LM Agents with an LM-Emulated Sandbox." arXiv:2309.15817v2, 17 May 2024 (preprint; abstract read). Read source

[15] OWASP GenAI Security Project. "LLM06:2025 Excessive Agency." OWASP Top 10 for LLM Applications 2025. Accessed 27 November 2026. Read source

[16] Model Context Protocol. "Tools." MCP Specification, version 2025-06-18. Accessed 27 November 2026. Read source

[17] Aizawa, Ken (Anthropic). "Writing effective tools for AI agents." Anthropic Engineering, 11 September 2025 (vendor engineering post). Read source

This page was researched and drafted by an AI assistant (Claude) for Apiary from Grok Bot's earlier draft. Sources were opened and read on 27 November 2026. It has not been reviewed by a human expert and is not founder-verified. Status: candidate.

Frequently asked
What is Tool Calling: The Model Asks, Your Application (or the Provider) Acts about?
There are two places that code can live. For client tools (OpenAI calls them function tools), your application receives the request, runs the operation, and…
What should you know about openAI's five steps?
OpenAI's function calling guide describes tool calling as a conversation between your application and the model, in five steps: "Make a request to the model with tools it could call"; "Receive a tool call from the model"; "Execute code on the application side with input from the tool call"; "Make a second request to…
What should you know about anthropic's version?
Anthropic's documentation describes the same round trip with different field names. When Claude decides to call one of your tools, the response carries stop_reason: "tool_use" and one or more tool_use blocks; "Your code runs the operation and sends back a tool_result " 2…
What should you know about google's version?
Google's Gemini function calling page lists four steps: define the function declaration, call the model with the declarations and the user prompt, execute the function in your application, and send the result back for a final response, possibly over several turns 7 (https://aistudio.google.com/docs/function-calling).…
What should you know about three buckets?
Anthropic's documentation sorts tools into three buckets by where the code runs, and says "the bucket determines what your application is responsible for" 3 (https://platform.claude.com/docs/en/agents-and-tools/tool-use/how-tool-use-works):
References & sources
  1. Apiary Reading Room — Open, cited knowledge base — funded to keep bee & practical research free.
From the Apiary Reading Room. Opinion & editorial — not financial advice. We don't overclaim.
More from the Reading Room