From 0c442663b753de9955040768c38e01e54e05e281 Mon Sep 17 00:00:00 2001 From: Aryan Kochhar Date: Tue, 4 Aug 2026 10:37:26 +0530 Subject: [PATCH 1/2] fix: carry functionDeclaration parameters into google_genai tool translation Google GenAI function declarations carry their argument schema in `parameters` (a Schema, whose type enums are uppercase) as well as in the newer `parametersJsonSchema`. The adapter only read `parametersJsonSchema`, so any tool declared with `parameters` reached the model with no argument schema at all and could not be called correctly Reading `parameters` as a fallback also makes the existing `normalize_tool_schema` call reachable for its intended input; it lowercases the uppercase Schema type enums, which is what that normalizer was written for --- .../google_genai/adapters/transformation.py | 2 + .../test_google_genai_adapter_fixes.py | 92 +++++++++++++++++++ 2 files changed, 94 insertions(+) diff --git a/litellm/google_genai/adapters/transformation.py b/litellm/google_genai/adapters/transformation.py index 4f127f476c34..cc3b626f268f 100644 --- a/litellm/google_genai/adapters/transformation.py +++ b/litellm/google_genai/adapters/transformation.py @@ -320,6 +320,8 @@ def _transform_google_genai_tools_to_openai( function_chunk["description"] = func_decl["description"] if "parametersJsonSchema" in func_decl: function_chunk["parameters"] = func_decl["parametersJsonSchema"] + elif "parameters" in func_decl: + function_chunk["parameters"] = func_decl["parameters"] openai_tool = {"type": "function", "function": function_chunk} openai_tools.append(openai_tool) diff --git a/tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py b/tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py index da56b094d958..385e4af7980a 100644 --- a/tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py +++ b/tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py @@ -82,6 +82,98 @@ def test_parameters_json_schema_transformation(): assert "location" in tool["function"]["parameters"]["properties"] +def test_parameters_schema_transformation(): + """Test that a functionDeclaration's `parameters` Schema is carried over and normalized. + + Google GenAI function declarations carry their argument schema in `parameters` + (a Schema, whose type enums are uppercase) as well as in the newer + `parametersJsonSchema`. Only reading the latter silently dropped the whole + argument schema, leaving the model with a tool it could not call correctly. + """ + adapter = GoogleGenAIAdapter() + + tools = [ + { + "functionDeclarations": [ + { + "name": "get_weather", + "description": "Get current weather information", + "parameters": { + "type": "OBJECT", + "properties": { + "location": { + "type": "STRING", + "description": "The city name", + }, + "days": {"type": "INTEGER"}, + }, + "required": ["location"], + }, + } + ] + } + ] + + openai_tools = adapter._transform_google_genai_tools_to_openai(tools) + + assert len(openai_tools) == 1 + function = openai_tools[0]["function"] + assert function["name"] == "get_weather" + + parameters = function["parameters"] + assert parameters["type"] == "object" + assert parameters["properties"]["location"]["type"] == "string" + assert parameters["properties"]["location"]["description"] == "The city name" + assert parameters["properties"]["days"]["type"] == "integer" + assert parameters["required"] == ["location"] + + +def test_parameters_json_schema_takes_precedence_over_parameters(): + """Test that parametersJsonSchema still wins when both fields are present.""" + adapter = GoogleGenAIAdapter() + + tools = [ + { + "functionDeclarations": [ + { + "name": "get_weather", + "parametersJsonSchema": { + "type": "object", + "properties": {"city": {"type": "string"}}, + }, + "parameters": { + "type": "OBJECT", + "properties": {"location": {"type": "STRING"}}, + }, + } + ] + } + ] + + openai_tools = adapter._transform_google_genai_tools_to_openai(tools) + + parameters = openai_tools[0]["function"]["parameters"] + assert "city" in parameters["properties"] + assert "location" not in parameters["properties"] + + +def test_function_declaration_without_parameters(): + """Test that a functionDeclaration with no argument schema stays parameter-less.""" + adapter = GoogleGenAIAdapter() + + tools = [ + { + "functionDeclarations": [ + {"name": "get_time", "description": "Get the current time"} + ] + } + ] + + openai_tools = adapter._transform_google_genai_tools_to_openai(tools) + + assert "parameters" not in openai_tools[0]["function"] + + def test_streaming_tool_call_with_empty_args(): """Test that streaming tool calls with empty arguments are handled correctly""" from litellm.google_genai.adapters.transformation import ( From b06809a52673ed3b92dc5c245e0c31e0694ed730 Mon Sep 17 00:00:00 2001 From: Aryan Kochhar Date: Wed, 5 Aug 2026 12:30:57 +0530 Subject: [PATCH 2/2] test: shorten the parameters schema test docstring to one line Matches the single line docstrings the other tests in this file already use --- .../google_genai/test_google_genai_adapter_fixes.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py b/tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py index 385e4af7980a..bc07096e5642 100644 --- a/tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py +++ b/tests/test_litellm/google_genai/test_google_genai_adapter_fixes.py @@ -83,13 +83,7 @@ def test_parameters_json_schema_transformation(): def test_parameters_schema_transformation(): - """Test that a functionDeclaration's `parameters` Schema is carried over and normalized. - - Google GenAI function declarations carry their argument schema in `parameters` - (a Schema, whose type enums are uppercase) as well as in the newer - `parametersJsonSchema`. Only reading the latter silently dropped the whole - argument schema, leaving the model with a tool it could not call correctly. - """ + """Test that a functionDeclaration's `parameters` Schema is carried over and normalized""" adapter = GoogleGenAIAdapter() tools = [