Repository navigation
fix(bedrock): scope tool name mappings to request context and honor TTL (#54172) - #54310
Open
MilindChatrabhuji wants to merge 3 commits into
Open
MilindChatrabhuji wants to merge 3 commits into
MilindChatrabhuji wants to merge 3 commits into
Conversation
Contributor
MilindChatrabhuji
force-pushed
the
fix/bedrock-converse-tool-name-cache-54172
branch
from
November 27, 2026 11:55
11f13dc to
4e86cb1
Compare
Author
|
@kimnamu Thank you for catching that! You were right: _transform_request and _async_transform_request previously only initialized �edrock_tool_name_mappings_context when None and never reset or scoped it across BedrockConverseLLM calls, so sequential calls on the same thread or asyncio task reused the prior request's dict. Updated PR #54310 ($sha):
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
Fixes #54172
On the Bedrock Converse route, tool names in model responses were being rewritten using a process-global cache (
litellm.bedrock_tool_name_mappings) that is shared across all requests and API keys on the proxy.make_valid_bedrock_tool_namereplaces invalid characters (such as:) with_and storessanitized -> originalinlitellm.bedrock_tool_name_mappings.get_bedrock_tool_name(llms/bedrock/common_utils.py) checkedif response_tool_name in litellm.bedrock_tool_name_mappings.cache_dict:, readingcache_dictdirectly and completely bypassing TTL checks on read.Xwhose sanitized form equaled a valid tool nameYused by another client, every subsequent Converse response that calledYwas returned to all clients asX(causing client validation failures such as Claude Code'sNo such tool available).Solution
bedrock_tool_name_mappings_context: ContextVar[dict[str, str] | None] = ContextVar("bedrock_tool_name_mappings_context", default=None)inlitellm/llms/bedrock/common_utils.py.bedrock_tool_name_mappings_contextin_lazy_imports_registry.pyandlitellm/__init__.py.make_valid_bedrock_tool_name: When a tool name is sanitized (input_tool_name != valid_string), storesvalid_string -> input_tool_namein the active request contextbedrock_tool_name_mappings_context.get(). Also retains global cache entry for backwards compatibility.get_bedrock_tool_name(response_tool_name: str) -> str:bedrock_tool_name_mappings_context.get()), preventing cross-tenant and cross-request tool corruption.litellm.bedrock_tool_name_mappings.get_cache(key=response_tool_name)to strictly honor TTL and purge expired entries, rather than reading.cache_dictdirectly.response_tool_nameunchanged if not mapped or if the entry has expired.Testing
Added unit tests covering:
test_get_bedrock_tool_name_honors_ttl: Confirms expired cache entries are never returned.test_get_bedrock_tool_name_context_isolation: Confirms request contexts isolate tool mappings across concurrent contexts without leaking.test_get_bedrock_tool_name_global_cache_fallback: Confirms valid global cache fallback and context override precedence.test_make_valid_bedrock_tool_name_request_context_and_cache: Confirmsmake_valid_bedrock_tool_namewrites to both request context and global cache.