Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

chore(bedrock): fix stale test comment; modernize types and narrow tool_calls for lint

Kentedb7ec230ee6
diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.py
index 79d5ac51fa8..5781b97ce00 100644
--- a/litellm/llms/bedrock/chat/converse_transformation.py
+++ b/litellm/llms/bedrock/chat/converse_transformation.py
@@ -191,7 +191,7 @@ class AmazonConverseConfig(BaseConfig):
return messages_copy
@staticmethod
- def _has_orphaned_tool_blocks(messages: List[AllMessageValues]) -> bool:
+ def _has_orphaned_tool_blocks(messages: list[AllMessageValues]) -> bool:
return any(
(m.get("role") == "assistant" and m.get("tool_calls"))
or m.get("role") in ("tool", "function")
@@ -200,8 +200,8 @@ class AmazonConverseConfig(BaseConfig):
@staticmethod
def _neutralize_orphaned_tool_blocks(
- messages: List[AllMessageValues], optional_params: dict
- ) -> List[AllMessageValues]:
+ messages: list[AllMessageValues], optional_params: dict
+ ) -> list[AllMessageValues]:
if optional_params.get(
"tools"
) or not AmazonConverseConfig._has_orphaned_tool_blocks(messages):
@@ -223,9 +223,10 @@ class AmazonConverseConfig(BaseConfig):
def _rewrite(message: AllMessageValues) -> AllMessageValues:
role = message.get("role")
- if role == "assistant" and message.get("tool_calls"):
+ tool_calls = message.get("tool_calls")
+ if role == "assistant" and tool_calls:
base_text = convert_content_list_to_str(message)
- call_texts = [_tool_call_text(call) for call in message["tool_calls"]]
+ call_texts = [_tool_call_text(call) for call in tool_calls]
text = "\n".join(filter(None, [base_text, *call_texts]))
return ChatCompletionAssistantMessage(role="assistant", content=text)
if role in ("tool", "function"):
diff --git a/tests/local_testing/test_function_calling.py b/tests/local_testing/test_function_calling.py
index b51da95c4f0..e0984cd4311 100644
--- a/tests/local_testing/test_function_calling.py
+++ b/tests/local_testing/test_function_calling.py
@@ -348,7 +348,8 @@ def test_parallel_function_call_anthropic_error_msg(
Reference Issue: https://github.com/BerriAI/litellm/issues/24158, https://github.com/BerriAI/litellm/issues/27138
"""
- # Ensure modify_params is False so Bedrock Converse path still raises.
+ # Force modify_params off as a clean baseline: it exercises the Anthropic
+ # dummy-tool path, which injects regardless of modify_params
# (other tests in this file set it to True and don't reset it)
original_modify_params = litellm.modify_params
litellm.modify_params = False