mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +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:
parent
f126f75995
commit
ea8a94988f
1 changed files with 5 additions and 0 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue