mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(responses): default serialize_tool_call_arguments to \"{}\" instead of empty string
An empty string is not valid JSON. Strict OpenAI-compatible gateways reject
tool-call arguments of \"\" with \"must be valid JSON\", while OpenAI itself
silently tolerates it — masking the defect in the most common test environment.
Root: serialize_tool_call_arguments defaulted to \"\" (custom_tools.py:58).
Line 1025 in transformation.py already passed \"{}\" explicitly, proving that
\"{}\" is the intended sentinel; three other call sites omitted the argument
and inherited the wrong default (lines 1554, 1604, 2582).
Two-part fix:
1. Flip the function default from \"\" to \"{}\" — all three unguarded call
sites now produce valid JSON for empty/None arguments.
2. Fix the custom-tool empty-input branch (transformation.py:1595): an
omitted input previously resolved to \"\"; now it becomes \"{\\\"content\\\": \\\"\\\"}\",
which matches the declared schema (required: [\"content\"]) and round-trips
cleanly through unwrap_custom_tool_arguments.
Sites in streaming_iterator.py and the upstream responses transformation that
accumulate fn_args via \"fn_args or accumulated\" patterns are intentionally
left unchanged — a truthy \"{}\" default would shadow the real accumulated
arguments and corrupt every streamed tool call.
Fixes #40369.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
328a5f5d60
commit
d04af4c837
2 changed files with 2 additions and 2 deletions
|
|
@ -55,7 +55,7 @@ def is_custom_tool_call(tool_name: str, custom_tool_names: set[str]) -> bool:
|
|||
return tool_name in custom_tool_names
|
||||
|
||||
|
||||
def serialize_tool_call_arguments(raw_arguments: object, default: str = "") -> str:
|
||||
def serialize_tool_call_arguments(raw_arguments: object, default: str = "{}") -> str:
|
||||
"""Render tool call arguments as the JSON string tool-call schemas require.
|
||||
|
||||
Arguments normally arrive already JSON-encoded, but clients and providers
|
||||
|
|
|
|||
|
|
@ -1592,7 +1592,7 @@ class LiteLLMCompletionResponsesConfig:
|
|||
raw_arguments = REDACTED_TOOL_CALL_ARGUMENTS_PLACEHOLDER
|
||||
if not raw_arguments and function_call.get("type") == "custom_tool_call":
|
||||
raw_input: Final = function_call.get("input") or ""
|
||||
raw_arguments = json.dumps({"content": raw_input}) if raw_input else ""
|
||||
raw_arguments = json.dumps({"content": raw_input}) if raw_input else json.dumps({"content": ""})
|
||||
raw_name: Final = function_call.get("name") or ""
|
||||
namespace: Final = function_call.get("namespace") or ""
|
||||
qualify: Final = bool(namespace) and function_call.get("type") != "custom_tool_call"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue