DEV Community

Cover image for Fixing Bedrock ToolResult Ordering Errors
Interro
Interro

Posted on

Fixing Bedrock ToolResult Ordering Errors

A tool executed successfully, but Bedrock rejected the next message because toolResult IDs did not match the preceding toolUse order.

INC-004 is easy to create when tools run in parallel. Async completion order is not protocol order, and checkpoint restore or middleware can shuffle result blocks.

The fix is to derive result order from the assistant's toolUseId sequence, fill missing results with explicit error blocks, and validate the assembled message before sending it to the provider.

Test at least three cases:

  • Results complete in reverse order.
  • One result is missing.
  • A checkpoint restores shuffled results.

Do not rely on dictionary insertion order or the order in which futures complete. The provider contract owns the final ordering rule.

Run a source review with:

prevention-scanner scan . --format json
Enter fullscreen mode Exit fullscreen mode

Read the full INC-004 incident.

AI #AWS #Bedrock #LangGraph

Top comments (0)