Study FAQ
How do I return client tool results and errors to the Claude Messages API?
Also asked as 2
- How do tool_use and tool_result blocks match when Claude requests multiple client tools?
- What message ordering does the Claude API expect after a client tool call fails?
Answer
For developer-defined client tools, retain the complete assistant turn containing the tool_use blocks. Then send the next user message with one tool_result for each client call. Set each tool_use_id to that call's ID and put all result blocks first in the array. Return is_error: true and a safe explanation when the call is invalid or the tool fails. Handle tool calls
If multiple client calls arrive in one turn, collect the results together. If the same turn also has a server tool without a result yet, send only the client result blocks in that user message. Specialized Anthropic-defined toolsets may have extra result fields. Server tools themselves execute on Anthropic infrastructure and use their documented server-result flow. Handle tool calls How tool use works
Return status, identifiers, and only the data needed for the next decision. Preserve untrusted third-party result text inside tool_result. Keep secrets and stack traces outside the conversation. When the API reports missing tool results, inspect the stored assistant turn, matching IDs, immediately following user turn, and block ordering. Handle tool calls Troubleshoot tool use
Full explanation
Implementing Claude Tools with Safe Execution and Approval Patterns
Study guide · CCDV-F
Read the full explanation