Follow Discord
Sweep 20 Nov 2026 · 19:55Z Build v2.1.330 547 read Stable v2.1.323 Latest v2.1.330 Next v2.1.330 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

handle-tool-calls changedagents-and-tools/tool-use/handle-tool-calls

Nearest release: v2.1.328, published 7 hours after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+24added
Lines−32removed
From line 4 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits9to this page, all time

The whole hunk

from line 4, old and new numbered
/
lines
from line 4
44description: Parse tool_use blocks, format tool_result responses, and handle errors with is_error.
55---
66 
7This page covers the tool-call lifecycle: reading `tool_use` blocks from Claude’s response, formatting `tool_result` blocks in your reply, and signaling errors. For the SDK abstraction that handles this automatically, see [Tool Runner](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner).
7When Claude’s response contains `tool_use` blocks, your code runs each tool and sends back `tool_result` blocks, including any errors. Write this code yourself when you need custom control over tool execution. Otherwise, use the SDK’s [tool runner](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner), which runs the tools and sends the results for you.
88 
9<Note>
10 **Simpler with Tool Runner:** The manual tool handling described on this page is automatically managed by [Tool Runner](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner). Use this page when you need custom control over tool execution.
11</Note>
12 
139Claude’s response differs based on whether it uses a [client or server tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview#how-tool-use-works).
1410 
1511## Handling results from client tools
from line 41
4541 ```
4642</Accordion>
4743 
48When you receive a tool use response for a client tool, you should:
44When you receive a tool use response for a client tool, follow these steps:
4945 
501. Extract the `name`, `id`, and `input` from the `tool_use` block.
461. For each `tool_use` block, run the tool that the block names, passing in its `input`.
472. In a new request, keep the earlier messages and add the response’s `content` unchanged as an `assistant` message.
483. Add a `user` message with one `tool_result` block for each `tool_use` block in that content, even if the tool failed.
494. Send the request with the same `tools` as the first request. Claude uses the tool results to continue its response.
505. If the next response’s `stop_reason` is also `tool_use`, repeat these steps. For other values, see the [stop reason quick reference](https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons#quick-reference).
5151 
522. Run the actual tool in your code base corresponding to that tool name, passing in the tool `input`.
52For these steps as complete programs, see [Tutorial: Build a tool-using agent](https://platform.claude.com/docs/en/agents-and-tools/tool-use/build-a-tool-using-agent).
5353 
543. Continue the conversation by sending a new message with the `role` of `user`, and a `content` block containing the `tool_result` type and the following information:
54Each `tool_result` block has `type` set to `tool_result`, plus these fields:
5555 
56 * `tool_use_id`: The `id` of the tool use request this is a result for.
57 * `content` (optional): The result of the tool, as a string (for example, `"content": "15 degrees"`), a list of nested content blocks (for example, `"content": [{"type": "text", "text": "15 degrees"}]`), or a list of document blocks (for example, `"content": [{"type": "document", "source": {"type": "text", "media_type": "text/plain", "data": "15 degrees"}}]`). These content blocks can use the `text`, `image`, `document`, or [`search_result`](https://platform.claude.com/docs/en/build-with-claude/search-results) types.
58 * `is_error` (optional): Set to `true` if the tool execution resulted in an error.
56* `tool_use_id`: The `id` of the `tool_use` block that this result answers.
57* `content` (optional): The result of the tool as a string or a list of content blocks. These content blocks can use the `text`, `image`, `document`, or [`search_result`](https://platform.claude.com/docs/en/build-with-claude/search-results) types.
58* `is_error` (optional): Set to `true` if the tool failed or the call was invalid.
5959 
6060For example, a successful tool result looks like this:
6161 
from line 180
180180 </Accordion>
181181</AccordionGroup>
182182 
183After receiving the tool result, Claude will use that information to continue generating a response to the original user prompt.
184 
185183## Handling results from server tools
186184 
187185Claude runs the tool internally and incorporates the results directly into its response without requiring additional user interaction.
from line 198
200198 
201199## Handling errors with is\_error
202200 
203There are a few different types of errors that can occur when using tools with Claude:
201When a client tool fails or a call is invalid, send a `tool_result` block with `is_error` set to `true`. Claude might then call the tool again with a new `tool_use` block, so limit how many retries your loop allows.
204202 
205203<AccordionGroup>
206204 <Accordion title="Tool execution error">
from line 218
220218 }
221219 ```
222220 
223 Claude will then incorporate this error into its response to the user. For example: “I’m sorry, I was unable to retrieve the current weather because the weather service API is not available. Please try again later.”
221 Claude can then call the tool again or tell the user what happened. For example, Claude might say “I’m sorry, I was unable to retrieve the current weather because the weather service API is not available. Please try again later.”
224222 
225223 <Tip>
226224 Write instructive error messages. Instead of generic errors such as `"failed"`, include what went wrong and what Claude should try next (for example, `"Rate limit exceeded. Retry after 60 seconds."`). This gives Claude the context it needs to recover or adapt without guessing.
from line 225
227225 </Tip>
228226 </Accordion>
229227 
230 <Accordion title="Invalid tool name">
228 <Accordion title="Invalid tool call">
231229 If Claude’s attempted use of a tool is invalid (for example, missing required parameters), it usually means that there wasn’t enough information for Claude to use the tool correctly. The best approach during development is to try the request again with more-detailed `description` values in your tool definitions.
232230 
233 However, you can also continue the conversation forward with a `tool_result` that indicates the error, and Claude will attempt to use the tool again with the missing information filled in:
231 However, you can also continue the conversation with a `tool_result` that indicates the error:
234232 
235233 ```json JSON
236234 {
from line 244
246244 }
247245 ```
248246 
249 If a tool request is invalid or missing parameters, Claude will retry 2–3 times with corrections before apologizing to the user.
247 Claude can then call the tool again with the missing information filled in.
250248 
251249 <Tip>
252250 To eliminate invalid tool calls entirely, use [strict tool use](https://platform.claude.com/docs/en/agents-and-tools/tool-use/strict-tool-use) with `strict: true` on your tool definitions. This guarantees that tool inputs always match your schema exactly, preventing missing parameters and type mismatches.
from line 252
254252 </Accordion>
255253 
256254 <Accordion title="Server tool errors">
257 When server tools encounter errors (for example, network issues with web search), Claude will transparently handle these errors and attempt to provide an alternative response or explanation to the user. Unlike client tools, you do not need to handle `is_error` results for server tools.
255 Unlike with client tools, you don’t send `is_error` results for server tools. When a server tool hits an error, such as a network issue during web search, the API returns the error inside the tool’s result block. In most cases, Claude then continues with another approach or an explanation for the user.
258256 
259 For web search specifically, possible error codes include:
260 
261 * `too_many_requests`: Rate limit exceeded
262 * `invalid_input`: Invalid search query parameter
263 * `max_uses_exceeded`: Maximum web search tool uses exceeded
264 * `query_too_long`: Query exceeds maximum length
265 * `unavailable`: An internal error occurred
257 For web search error codes, see [Web search tool errors](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool#errors).
266258 </Accordion>
267259</AccordionGroup>
268260 
Feedback