From d04af4c8371a40249f4bb68d362d0dc47b3b5691 Mon Sep 17 00:00:00 2001 From: okxint Date: Wed, 9 Sep 2026 11:59:14 +0530 Subject: [PATCH] fix(responses): default serialize_tool_call_arguments to \"{}\" instead of empty string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../responses/litellm_completion_transformation/custom_tools.py | 2 +- .../litellm_completion_transformation/transformation.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/responses/litellm_completion_transformation/custom_tools.py b/litellm/responses/litellm_completion_transformation/custom_tools.py index 4aa489d9e50..43376cf6cc0 100644 --- a/litellm/responses/litellm_completion_transformation/custom_tools.py +++ b/litellm/responses/litellm_completion_transformation/custom_tools.py @@ -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 diff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.py index b2d1a69e0d8..f80db02c398 100644 --- a/litellm/responses/litellm_completion_transformation/transformation.py +++ b/litellm/responses/litellm_completion_transformation/transformation.py @@ -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"