How to Fix Bedrock ToolResult Ordering Errors Caused by Async Execution
Amazon Bedrock rejects messages when toolResult IDs do not match the order of the preceding toolUse sequence, an issue logged as INC-004. The problem commonly arises when tools run in parallel, since async completion order differs from protocol order, and checkpoint restores or middleware can further shuffle result blocks. The recommended fix involves deriving result order from the assistant's toolUseId sequence, filling any missing results with explicit error blocks, and validating the assembled message before dispatch. Developers are advised not to rely on dictionary insertion order or the sequence in which async futures resolve, as the provider contract governs final ordering. Testing should cover at least three scenarios: results arriving in reverse order, a missing result, and shuffled results restored from a checkpoint.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in