From 10511dfd131e6d5f5f58b5fe8cdf7150381a363b Mon Sep 17 00:00:00 2001 From: apex-mochen <2756823972@qq.com> Date: Sun, 27 Sep 2026 02:06:43 +0800 Subject: [PATCH] fix: map empty Gemini tool-call arguments to {} instead of {"type":"object"} Rebase onto latest upstream main. Fold the missing-key / non-empty regression cases into the mapped test file (per AGENTS.md) and drop the standalone test_gemini_empty_arguments.py. See #43156 Signed-off-by: ding <2756823972@qq.com> --- .../prompt_templates/factory.py | 4 +-- ...llm_core_utils_prompt_templates_factory.py | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index 5d6c1ac0e4b..efdb77943af 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -1209,9 +1209,7 @@ def _gemini_tool_call_invoke_helper( if ( isinstance(arguments, str) and len(arguments) == 0 ): # pass empty dict, if arguments is empty string - prevents call from failing - arguments_dict = { - "type": "object", - } + arguments_dict = {} else: arguments_dict = json.loads(arguments) function_call: Final = VertexFunctionCall( diff --git a/tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py b/tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py index 9576f4742c6..3460c3d45f0 100644 --- a/tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py +++ b/tests/unit/litellm_core_utils/prompt_templates/test_litellm_core_utils_prompt_templates_factory.py @@ -822,9 +822,33 @@ def test_vertex_ai_transform_empty_function_call_arguments(): } result: VertexFunctionCall = _gemini_tool_call_invoke_helper(function_call) print(result) - assert result["args"] == { - "type": "object", - } + assert result["args"] == {} + + +def test_gemini_missing_arguments_maps_to_empty_object(): + """When `arguments` key is absent, the helper should yield an empty object (see #43156).""" + from litellm.litellm_core_utils.prompt_templates.factory import ( + VertexFunctionCall, + _gemini_tool_call_invoke_helper, + ) + + result: VertexFunctionCall = _gemini_tool_call_invoke_helper( + {"name": "no_args"} + ) + assert result["args"] == {} + + +def test_gemini_nonempty_arguments_is_parsed(): + """Non-empty arguments string should still be JSON-decoded as before.""" + from litellm.litellm_core_utils.prompt_templates.factory import ( + VertexFunctionCall, + _gemini_tool_call_invoke_helper, + ) + + result: VertexFunctionCall = _gemini_tool_call_invoke_helper( + {"name": "get", "arguments": '{"x": 1}'} + ) + assert result["args"] == {"x": 1} @pytest.mark.asyncio