fix: truncate AWS Bedrock toolUseId to 64 characters #10902
Merged
+222
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
AWS Bedrock has a 64-character limit on
toolUseIdfields, but the Bedrock Converse format converter doesn't truncate these IDs. This causes validation errors when using LiteLLM as a proxy to Bedrock, especially when switching modes with long conversation histories.Error example:
The issue manifests when:
Solution
Applied the same ID sanitization approach used in OpenAI providers to the Bedrock Converse format converter:
sanitizeOpenAiCallIdfromsrc/utils/tool-id.tstoolUseIdfields in:tool_useblockstool_resultblocksThis ensures IDs are truncated to 64 characters with hash suffixes to maintain uniqueness.
Changes
src/api/transform/bedrock-converse-format.tssrc/api/transform/__tests__/bedrock-converse-format.spec.tsRelated
Fixes EXT-556
Related to issue #10766 which addresses MCP tool name length, but this is a separate issue about tool call ID length.
Important
Truncates
toolUseIdto 64 characters inconvertToBedrockConverseMessages()to comply with AWS Bedrock limits, adding tests for verification.toolUseIdto 64 characters inconvertToBedrockConverseMessages()inbedrock-converse-format.tsusingsanitizeOpenAiCallId.tool_useandtool_resultblocks, ensuring IDs are unique with hash suffixes.bedrock-converse-format.spec.tsto verify ID truncation and uniqueness.tool_useandtool_resultIDs.sanitizeOpenAiCallIdfromtool-id.tsfor ID sanitization.This description was created by
for 544cb90. You can customize this summary. It will automatically update as commits are pushed.