Study FAQ
How do I format custom client tool results in the Claude Messages API?
Also asked as 2
- How should I return all custom client tool_result blocks if one Claude tool call fails?
- What goes in the next Claude API message after parallel custom client tool calls?
Answer
For custom client tools, append Claude's assistant message, then send the results together in the immediately following user message. Return one tool_result for every client tool_use, even on failure, and set each tool_use_id to the ID it answers. Put every result block before any user text. Match parallel results by ID. Execute independent calls in parallel when useful and serialize calls with dependencies or shared effects.
On failure, set is_error: true and provide a brief, actionable explanation. For example, a denied lookup can report that the caller lacks access without disclosing another tenant's records. On success, return a small status, identifier or summary that answers the next step. Keep sensitive fields and stack traces outside the model context. Log the correlation ID with the executor's policy decision and observed outcome.
If the assistant turn has a server tool call with no result block yet, the user message must contain only client tool_result blocks and the next request must preserve the same tools array. Also return a container ID if Claude returned one, and keep the same mcp_servers if the pending block is mcp_tool_use. Adding text can end the turn early and cause a 400 response for an unresolved directly called server tool. If a request fails with a missing-result error, inspect the adjacent message pair, the complete set of IDs, and block placement before rerunning any tool. Built-in toolset member calls, such as computer or browser use, can impose additional sequencing and result fields.
Handle tool calls · Parallel tool use · Claude API tool-use continuation
Full explanation
Designing Claude Tool Interfaces and Execution Contracts
Study guide · CCAR-F
Read the full explanation