Describe the JSON shape of a Claude Opus 4.7 assistant message that calls a tool
Walk through what an assistant message looks like at the JSON level when Claude Opus 4.7 calls a tool during a turn, and what the next user turn must contain. Be specific about field names and the block-typed content array.
Assistant content is a typed-block array mixing text and tool_use blocks; the next user turn replies with tool_result blocks linked by tool_use_id. No separate tool role.
Picture a conversation where each speaker can hand over more than one slip of paper per turn. The assistant might pass a slip with words on it and another slip that says please run this calculation, with a unique sticker number on the calculation slip. On the next turn, the user hands back a slip with the calculation result and the same sticker number, so it is obvious which request the result answers. Nothing is glued together as one long sentence. Each kind of slip has its own format, and the sticker number is what keeps the call and the result linked across turns. That is exactly how the message shape works under the hood.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: the typed-block content array, the tool_use block fields, the tool_result reply, the id linkage, parallel-call support, and the fine-tuning data implications.
from anthropic import Anthropic
client = Anthropic()
resp = client.messages.create(
model="claude-opus-4-7-20260101",
max_tokens=1024,
tools=[{
"name": "get_weather",
"description": "Lookup current weather for a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}],
messages=[
{"role": "user", "content": "Weather in Tokyo?"},
],
)
# resp.content is the block-typed array.
# For a tool call, you will see something like:
# [TextBlock(text="Let me check..."),
# ToolUseBlock(id="toolu_01...", name="get_weather",
# input={"city": "Tokyo"})]
for block in resp.content:
if block.type == "tool_use":
result = run_tool(block.name, block.input)
# Reply with a tool_result block under role 'user'
followup = client.messages.create(
model="claude-opus-4-7-20260101",
max_tokens=1024,
messages=[
{"role": "user", "content": "Weather in Tokyo?"},
{"role": "assistant", "content": resp.content},
{"role": "user", "content": [
{"type": "tool_result",
"tool_use_id": block.id,
"content": result},
]},
],
)| Aspect | Anthropic messages API | OpenAI chat completions |
|---|---|---|
| Assistant content | Typed-block array (text, tool_use) | String plus tool_calls field |
| Tool-call location | Inline tool_use block in content | Separate tool_calls field on message |
| Result role | 'user' with tool_result block | 'tool' role with content string |
| Call-to-result linkage | tool_use_id matches tool_use.id | tool_call_id matches tool_calls[].id |
| Parallel calls | Multiple tool_use blocks in one turn | Multiple entries in tool_calls array |
Real products, models, and research that use this idea.
- Claude Opus 4.7 production deployments at Anthropic customers use this exact block-typed shape for tool-augmented agents calling search, calculator, and code-execution tools.
- Anthropic's official SDKs (TypeScript, Python) construct typed-block content automatically when you pass tools to the messages.create call.
- Open-source fine-tuning datasets like glaive-toolcall-anthropic emit the block-typed shape directly so SFT preserves tool-call grounding.
- Tool-use agent frameworks like Smolagents and PydanticAI generate this exact JSON shape when targeting Claude Opus 4.7 or Claude Sonnet 4.6 backends.
- Multi-tool parallel calls in Anthropic's computer-use beta rely on the id linkage to dispatch tool_result blocks back to the right tool_use call in one user message.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does the message shape support parallel tool calls in one assistant turn?
QWhat goes wrong when fine-tuning data flattens the typed-block content into strings?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Treating assistant content as a single string and putting a tool call into JSON inside that string. The API expects a list of typed blocks; flat strings drop the structured schema and break the model's tool-call grounding.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.