Tool Implementation
Official scope (Exam Guide v1.0): function calling, tool descriptions, error handling, agentic harness dispatch, client-side vs server-side tools, approval patterns, tool-set construction.
Anatomy of a tool
name, description, input_schema (JSON Schema), optional input examples and strict: true. The description is by far the most important factor: what it does, when to use it and when not, what each parameter means, what it returns, its limits. Several sentences, not a phrase. Tool definitions are assembled into the model's instructions, so a vague description is a vague prompt.
Client vs server tools
| Type | Examples | Who executes | What you see |
|---|---|---|---|
| Client: your own | get_weather, lookup_order | Your code | stop_reason: tool_use, tool_use blocks; you return tool_result |
| Client: Anthropic-schema | bash, text_editor, memory, computer use, browser use | Your code (Anthropic publishes the schema and trains on it) | Same as above |
| Server | web_search, web_fetch, code_execution, tool_search, MCP connector | Anthropic's infrastructure | server_tool_use and results in the same response; pause_turn if the server loop hits its limit |
Server tools can add usage charges (for example per web search). Tool definitions and a tool-use system prompt (a few hundred tokens) count as input.
Harness dispatch (verified flow, design guidance on structure)
Read each tool_use block → look up the handler by name (a registry) → validate input → run → return a tool_result with the matching tool_use_id. Claude may request several tools in parallel: run independent ones concurrently and return all results in one user message, with no text after them. The SDK tool runner can do this loop for you.
Errors are results
Return a tool_result with is_error: true and an actionable message so the model can correct and retry; do not crash the loop.
tool_choice
auto (default with tools), any, tool (named), none. Forced choices suppress text before the call and are rejected (400) on Opus 5.5, Sonnet 5.5 and Fable 5.1; there, use auto with strict tools, or structured outputs.
Approval patterns (design guidance, verified mechanisms)
Read-only by default; allowlists; human approval before destructive or irreversible actions; hooks or permission rules that deny or ask; validate inputs and the caller's rights server-side; never trust model-supplied arguments blindly; least privilege per tool.
Tool-set construction (design guidance, verified mechanics)
Fewer, more capable tools over many near-duplicates; namespaced names (orders_lookup); return only high-signal fields with stable ids; make misuse hard through parameter design. For large libraries, defer loading and use tool search so only needed definitions enter context.
Exam traps
- One-line descriptions for similar tools, causing misrouting.
- "Claude executes my function." Your code does (except server tools).
- Throwing an exception instead of an error
tool_result. - Forced
tool_choiceon a model that rejects it. - Returning results one by one for parallel calls, or adding text after them.
References
- Tool use overview — checked Oct 16, 2026
- Define tools — checked Oct 16, 2026
- Handling stop reasons — checked Oct 16, 2026
- Errors (forced tool use) — checked Oct 16, 2026
- Tool search tool — checked Oct 16, 2026
Check your understanding
Claude keeps picking the wrong one of two similar tools. First fix?Show answerHide answer
Answer
Sharpen both descriptions (when to use, when not); consider merging or renaming.Web search: who runs it?Show answerHide answer
Answer
Anthropic (server tool).A delete tool takes an id from the model. Safeguards?Show answerHide answer
Answer
Server-side validation of id and caller rights, confirmation or human approval, least privilege.Two
tool_useblocks in one response. How do you reply?Show answerHide answerAnswer
One user message with bothtool_resultblocks.