Skip to content

LLM request rejected: unexpected tool_use_id in tool_result blocks #11029

@dwebster123

Description

@dwebster123

Bug Description

Getting a repeated error when using Roo-Code with the Anthropic API:

LLM request rejected: messages.98.content.1: unexpected tool_use_id found in tool_result blocks: toolu_0114eUeLnM3d16LHL9X69Y92. Each tool_result block must have a corresponding tool_use block in the previous message.

The error persists across retries with the same tool_use_id, suggesting the conversation history is replayed with the same corrupted state.

Expected Behavior

The conversation should continue without API validation errors.

Likely Cause

A tool_result block in the conversation history references a tool_use_id that no longer has a matching tool_use block in the preceding assistant message. This can happen when conversation history is truncated or summarized — if the assistant message containing the tool_use is removed but the following user message with the tool_result is kept, the pairing breaks.

Suggested Fix

  • Treat tool_use/tool_result pairs as atomic units when trimming conversation context — never remove one without the other.
  • Validate the message array before sending to the API to ensure every tool_result.tool_use_id has a corresponding tool_use block in the immediately preceding assistant message.

Environment

  • API: Anthropic (Claude)
  • The error occurs at message index 98, suggesting it happens in longer conversations after context management kicks in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions