mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-20 16:19:55 +00:00
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 <krrishdholakia@gmail.com>
This commit is contained in:
co-authored by
Krish Dholakia
parent
f126f75995
commit
ea8a94988f
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user