diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index f42c912ee14..e95718469a6 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -5361,9 +5361,7 @@ def make_valid_bedrock_tool_name(input_tool_name: str) -> str: return valid_string -def make_valid_bedrock_tool_use_id( - input_tool_use_id: Optional[str], -) -> Optional[str]: +def make_valid_bedrock_tool_use_id(input_tool_use_id: str) -> str: """ Replaces any invalid characters in the input tool_use_id with underscores so it matches Bedrock Converse's required pattern ``^[a-zA-Z0-9_.:-]+$``. diff --git a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py index eeb59a3e0c1..2796ed5ee9b 100644 --- a/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py +++ b/tests/test_litellm/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py @@ -2818,7 +2818,12 @@ def test_make_valid_bedrock_tool_use_id_empty_passthrough(): ) assert make_valid_bedrock_tool_use_id("") == "" - assert make_valid_bedrock_tool_use_id(None) is None + # The signature is ``str -> str`` to match downstream TypedDict callers + # (``BedrockToolUseBlock.toolUseId``); the helper still defensively returns + # the input unchanged when None slips in. Suppress the resulting mypy + # error here — annotating the helper as ``Optional[str]`` would force a + # cascade of ``cast(str, ...)`` calls at the use sites. + assert make_valid_bedrock_tool_use_id(None) is None # type: ignore[arg-type] def test_bedrock_tool_call_invoke_sanitizes_drifted_name_and_id():