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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(invoke_handler.py): fix converse chunk parsing to only return empty dict on tool use
Krrish Dholakia92d85555fe48
diff --git a/litellm/llms/bedrock/chat/invoke_handler.py b/litellm/llms/bedrock/chat/invoke_handler.pyindex 27289164f7a..44e5b403801 100644--- a/litellm/llms/bedrock/chat/invoke_handler.py+++ b/litellm/llms/bedrock/chat/invoke_handler.py@@ -1231,7 +1231,9 @@ class AWSEventStreamDecoder:if len(self.content_blocks) == 0:return False- if "text" in self.content_blocks[0]:+ if (+ "toolUse" not in self.content_blocks[0]+ ): # be explicit - only do this if tool use block, as this is to prevent json decoding errorsreturn Falsefor block in self.content_blocks:diff --git a/tests/llm_translation/test_anthropic_completion.py b/tests/llm_translation/test_anthropic_completion.pyindex ce7f8f95b50..da47e745e71 100644--- a/tests/llm_translation/test_anthropic_completion.py+++ b/tests/llm_translation/test_anthropic_completion.py@@ -992,8 +992,8 @@ def test_anthropic_thinking_output(model):@pytest.mark.parametrize("model",[- "anthropic/claude-3-7-sonnet-20250219",- # "bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0",+ # "anthropic/claude-3-7-sonnet-20250219",+ "bedrock/us.anthropic.claude-3-7-sonnet-20250219-v1:0",# "bedrock/invoke/us.anthropic.claude-3-7-sonnet-20250219-v1:0",],)@@ -1011,8 +1011,11 @@ def test_anthropic_thinking_output_stream(model):reasoning_content_exists = Falsesignature_block_exists = False+ tool_call_exists = Falsefor chunk in resp:print(f"chunk 2: {chunk}")+ if chunk.choices[0].delta.tool_calls:+ tool_call_exists = Trueif (hasattr(chunk.choices[0].delta, "thinking_blocks")and chunk.choices[0].delta.thinking_blocks is not None@@ -1025,6 +1028,7 @@ def test_anthropic_thinking_output_stream(model):print(chunk.choices[0].delta.thinking_blocks[0])if chunk.choices[0].delta.thinking_blocks[0].get("signature"):signature_block_exists = True+ assert not tool_call_existsassert reasoning_content_existsassert signature_block_existsexcept litellm.Timeout: