الانتقال إلى المحتوى
Claude وأدوات الـ AI للبرمجةClaude API و Tool Use· 7 دقائق للقراءة

Parallel Tool Calls and Tool Errors: Getting the tool_result Shape Right

Every result for one assistant turn goes back in one user message, and a failing tool is reported with is_error, not thrown.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
  • Claude API
محتويات المقال

An ops assistant gets asked, "Are checkout, search and payments healthy?" Claude answers with three tool_use blocks in one response. The loop runs the first check, sends its result and calls the API again, which answers with a 400: tool_use ids were found without tool_result blocks immediately after. After that is fixed, a second bug appears. On days when the payments check times out, the exception escapes the loop and the user gets "Something went wrong", even though two of the three answers were ready.

The common misconception

"Each tool result can go back in its own message, and a failing tool should abort the request instead of being reported to Claude." Both halves come from good habits:

  • Some other APIs carry results in special tool or function messages, so one message per result feels natural.
  • Early prototypes trigger one tool at a time, and one result per message works fine there.
  • In backend code, an unexpected exception should fail fast instead of being swallowed.
  • Showing the model an error message feels risky, as if it might invent an answer around it.

The half-truth: results are matched to calls by ID, and real bugs in your own code should still fail loudly. But the Claude API groups results by turn, and a tool that fails is information Claude needs, not a reason to throw away the turn.

What actually happens

One assistant turn, one user turn

With , a response with stop_reason: "tool_use" "can contain several tool_use blocks in a single assistant turn." The docs set three rules for the reply. Return one tool_result for each tool_use block, "all together in the next user message." Match each result with tool_use_id. And put every tool_result block before any text, because nothing may come between the assistant's tool use message and your results. Claude's docs point out the contrast with other APIs: there's no tool role here, and results are content blocks inside an ordinary user message.

JSON next user message
{  "role": "user",  "content": [    {"type": "tool_result", "tool_use_id": "toolu_01", "content": "healthy"},    {"type": "tool_result", "tool_use_id": "toolu_02", "content": "healthy"},    {      "type": "tool_result",      "tool_use_id": "toolu_03",      "is_error": true,      "content": "Timed out after 5 s. Report payments as unknown."    },    {"type": "text", "text": "Keep it to one line per service."}  ]}

Break the rules and you get the 400 from the opening: the troubleshooting page lists it with two causes, a missing result for some tool_use ID or a result that isn't the first block in the message. There's a quieter failure too. Sending a separate user message for each result is, according to the parallel tool use page, the most common reason Claude stops making parallel calls: the history "teaches" it to avoid them.

How you run the calls is your choice

"The API doesn't prescribe an execution order." Run independent, read-only calls concurrently for lower latency, with asyncio.gather or a thread pool. Run tools with side effects, shared state or ordering requirements one after another. If you stop early, say because an earlier write failed, every skipped call still gets a tool_result with is_error: true and a short explanation, such as "Not executed: the preceding write_file call failed."

A failing tool is a result, not a crash

For errors during execution, the docs' instruction is simple: return the error message in content with "is_error": true, and Claude "will then incorporate this error into its response to the user." Make it instructive: what went wrong and what to do next, not just "failed." If Claude's call was invalid, for example missing a required parameter, an error result lets it try again, and the docs say Claude "will retry 2–3 times with corrections before apologizing to the user."

The SDK's own tool runner works the same way: "When a tool throws an exception, the tool runner catches it and returns the error to Claude as a tool result with is_error: true", carrying the exception's message rather than the stack trace. And MCP draws the identical line between protocol errors and tool execution errors, which go back in the result with isError: true so the model can self-correct.

The health check loop, fixed

The first version answers one call per request and lets a timeout escape. The second runs the independent checks in parallel, turns a timeout into an error result and sends one user turn:

Python health.py
def handle_tools(reply):    for call in [b for b in reply.content if b.type == "tool_use"]:        out = check_health(call.input["service"])  # TimeoutError escapes        messages.append({"role": "user", "content": [  # one message each            {"type": "tool_result", "tool_use_id": call.id, "content": out},        ]})        reply = client.messages.create(  # 400: other tool_use ids unanswered            model="claude-opus-5-5", max_tokens=4096,            tools=TOOLS, messages=messages,        )    return reply

Now Claude can tell the user that checkout and search are healthy and that the payments check timed out, instead of the user seeing a generic failure. The try sits around the tool, not around the loop, so a bug in your own request-building code still raises.

MythReality
Each result can go in its own user messageAll results for one assistant turn go in one user message
Results and text can go in any ordertool_result blocks come first, right after the tool_use turn
The API runs parallel calls for youYour code chooses: concurrent, sequential or a mix
A failing tool should abort the requestReturn is_error: true with a message Claude can act on
A skipped call can be left outIt still needs a tool_result, marked as an error

How to apply it in your project

  1. Group results by assistant turnCollect every tool_use block from the response, build all the results, and send them in one user message, results first and text last.
  2. Pick an execution strategy per toolRun read-only calls in parallel. Run calls with side effects in order, stop at the first failure, and mark the skipped ones with is_error: true.
  3. Catch failures at the tool boundaryConvert timeouts, failed API calls and validation errors into error results that say what happened and what to do next.
  4. Make invalid calls rarerWrite precise tool descriptions and add strict: true, so inputs always match your schema.
  5. Check the transcriptsCount tool_use blocks per response to confirm Claude calls in parallel, and treat the "without tool_result blocks" 400 as a formatting bug in your loop.

Key takeaways

  • One assistant turn with several tool_use blocks gets one user message holding every tool_result.
  • Match results with tool_use_id and put them before any text in that message.
  • Execution order is yours: parallel for independent reads, sequential for side effects.
  • A failed or skipped tool still returns a tool_result, with is_error: true and an instructive message.
  • One message per result can cause 400s and teaches Claude to stop calling tools in parallel.

📚 المصادر

  1. Parallel tool use — Claude API Docs
  2. Handle tool calls — Claude API Docs
  3. Troubleshooting tool use — Claude API Docs
  4. Tool runner (SDK) — Claude API Docs
  5. Tools — MCP Specification 2026-07-28

التعليقات (0)