From ea8a94988fc5fa2050efffc395398a730c2eb050 Mon Sep 17 00:00:00 2001 From: LouisShark Date: Thu, 8 Jan 2026 03:24:46 +0800 Subject: [PATCH] fix(bedrock): ensure toolUse.input is always a dict when converting from OpenAI format (#18414) When some providers (like OpenRouter) return tool call arguments as '""' (a JSON-encoded empty string), json.loads returns an empty string instead of a dict. Since Bedrock requires toolUse.input to be a JSON object, this causes a BedrockException. This fix adds a type check after json.loads() to ensure the result is always a dictionary. Co-authored-by: Krish Dholakia --- litellm/litellm_core_utils/prompt_templates/factory.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index f359dbbb70..0c331e4303 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -3176,6 +3176,11 @@ def _convert_to_bedrock_tool_call_invoke( id = tool["id"] name = tool["function"].get("name", "") arguments = tool["function"].get("arguments", "") + arguments_dict = json.loads(arguments) if arguments else {} + # Ensure arguments_dict is always a dict (Bedrock requires toolUse.input to be an object) + # When some providers return arguments: '""' (JSON-encoded empty string), json.loads returns "" + if not isinstance(arguments_dict, dict): + arguments_dict = {} if not arguments or not arguments.strip(): arguments_dict = {} else: