diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index 7b12d1e939f..f1c540ae043 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -1141,9 +1141,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 26124ac24de..09c9b67bef7 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 @@ -607,9 +607,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