Files
litellm/tests/litellm_core_utils
Simon Lynch 07bffddbfa fix(bedrock): deduplicate toolResult and toolUse blocks in Converse message transformation (#20049)
Bedrock rejects requests when toolResult or toolUse blocks within a
single message contain duplicate IDs. The Converse message transformer
merges consecutive tool/assistant messages without checking for
duplicate toolUseId values, causing BedrockException errors.

Add _deduplicate_bedrock_content_blocks() — a generalized helper that
removes duplicate blocks by ID, logs a warning for each dropped
duplicate via verbose_logger, and preserves non-tool blocks (e.g.
cachePoint). Apply it at all four merge sites (sync/async × toolResult/
toolUse).

The Anthropic /messages path was fixed in PR #19324; this applies the
equivalent fix to the Bedrock Converse path.

Fixes #20048

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 18:23:43 +05:30
..