What does "tool_use ids were found without tool_result blocks immediately after" mean?
The message history you sent to the Claude API contains an assistant turn with a tool_use block and no matching tool_result in the user message right after it. The API requires that no message sits between the call and its result, and that the tool_result blocks come first in that user message, with any text after them.
The docs name two causes: code inserts a message between the call and its results, or puts text before the tool_result blocks. Also check your own code for an interrupted run that never stored the result, history trimming that drops the results message, or parallel tool calls whose results end up in separate user messages.
The request fails the same way on every retry, so a retry loop only repeats it. Fix the history. Return a result for every id, with is_error set to true for a tool that failed, and trim history in whole call-and-result pairs. For what to put in that error result, see how an agent should handle errors from an MCP server.
The error doesn’t say which step dropped the result. The trace of that turn does.
published