An architect is implementing tool use with the Claude API and receives the following in the assistant response: a content block with type 'tool_use' containing an id, name, and input object. The next step requires constructing the tool_result message correctly. Which structure is correct for returning tool results to Claude?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Here's the deal — b is correct: the Anthropic API requires tool results to be submitted as a user-turn message where content is an array containing a tool_result content block. The tool_result block must include tool_use_id (matching the id from the tool_use block), content (the result string or content array), and optionally is_error.
Full explanation below image
Full Explanation
B is correct: the Anthropic API requires tool results to be submitted as a user-turn message where content is an array containing a tool_result content block. The tool_result block must include tool_use_id (matching the id from the tool_use block), content (the result string or content array), and optionally is_error. The role of this message must be 'user'. A is wrong because 'tool' is not a valid role in the Anthropic messages API — only 'user' and 'assistant' are valid roles. C is wrong because tool results must come from the user role, not the assistant role, and must use the structured tool_result content block type rather than a plain string. D is wrong because messages are immutable after creation — you cannot append to an existing message; you must create a new user message with the tool result.