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
Bedrock handle json mode check correctly
Mohse Morad369aa02c4b5b
diff --git a/litellm/llms/bedrock/chat/converse_transformation.py b/litellm/llms/bedrock/chat/converse_transformation.pyindex 1b8fcabcf29..239d7fe9c6f 100644--- a/litellm/llms/bedrock/chat/converse_transformation.py+++ b/litellm/llms/bedrock/chat/converse_transformation.py@@ -10,6 +10,7 @@ from typing import List, Literal, Optional, Tuple, Union, cast, overloadimport httpximport litellm+from litellm.constants import RESPONSE_FORMAT_TOOL_NAMEfrom litellm.litellm_core_utils.core_helpers import map_finish_reasonfrom litellm.litellm_core_utils.litellm_logging import Loggingfrom litellm.litellm_core_utils.llm_response_utils.convert_dict_to_response import (@@ -322,7 +323,6 @@ class AmazonConverseConfig(BaseConfig):def _create_json_tool_call_for_response_format(self,json_schema: Optional[dict] = None,- schema_name: str = "json_tool_call",description: Optional[str] = None,) -> ChatCompletionToolParam:"""@@ -347,7 +347,7 @@ class AmazonConverseConfig(BaseConfig):_input_schema = json_schematool_param_function_chunk = ChatCompletionToolParamFunctionChunk(- name=schema_name, parameters=_input_schema+ name=RESPONSE_FORMAT_TOOL_NAME, parameters=_input_schema)if description:tool_param_function_chunk["description"] = description@@ -391,14 +391,11 @@ class AmazonConverseConfig(BaseConfig):continuejson_schema: Optional[dict] = None- schema_name: str = ""description: Optional[str] = Noneif "response_schema" in value:json_schema = value["response_schema"]- schema_name = "json_tool_call"elif "json_schema" in value:json_schema = value["json_schema"]["schema"]- schema_name = value["json_schema"]["name"]description = value["json_schema"].get("description")if "type" in value and value["type"] == "text":@@ -414,7 +411,6 @@ class AmazonConverseConfig(BaseConfig):"""_tool = self._create_json_tool_call_for_response_format(json_schema=json_schema,- schema_name=schema_name if schema_name != "" else "json_tool_call",description=description,)optional_params = self._add_tools_to_optional_params(@@ -430,11 +426,10 @@ class AmazonConverseConfig(BaseConfig):optional_params["tool_choice"] = ToolChoiceValuesBlock(tool=SpecificToolChoiceBlock(- name=schema_name if schema_name != "" else "json_tool_call"+ name=RESPONSE_FORMAT_TOOL_NAME))optional_params["json_mode"] = True- optional_params["structured_output_tool_name"] = schema_name if schema_name != "" else "json_tool_call"if non_default_params.get("stream", False) is True:optional_params["fake_stream"] = Trueif param == "max_tokens" or param == "max_completion_tokens":@@ -1121,14 +1116,10 @@ class AmazonConverseConfig(BaseConfig):self._transform_thinking_blocks(reasoningContentBlocks))chat_completion_message["content"] = content_str- if json_mode is True and tools is not None and len(tools) == 1:- function_name = tools[0]["function"].get("name")- if function_name == structured_output_tool_name:- json_mode_content_str: Optional[str] = tools[0]["function"].get("arguments")- if json_mode_content_str is not None:- chat_completion_message["content"] = json_mode_content_str- else:- chat_completion_message["tool_calls"] = tools+ if json_mode is True and tools is not None and len(tools) == 1 and tools[0]["function"]["name"] == RESPONSE_FORMAT_TOOL_NAME:+ json_mode_content_str: Optional[str] = tools[0]["function"].get("arguments")+ if json_mode_content_str is not None:+ chat_completion_message["content"] = json_mode_content_strelse:chat_completion_message["tool_calls"] = tools