Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(google_genai): drop non-object tool parameters instead of forwarding them

mateo-berri5eb967d9256e
diff --git a/litellm/google_genai/adapters/transformation.py b/litellm/google_genai/adapters/transformation.py
index a256be45780..10340eb7acf 100644
--- a/litellm/google_genai/adapters/transformation.py
+++ b/litellm/google_genai/adapters/transformation.py
@@ -103,6 +103,7 @@ class _GenAISystemInstruction(TypedDict, total=False):
_EMPTY_STR_MAPPING: Final[Mapping[str, str]] = MappingProxyType({})
_RESPONSE_MIME_TYPE_KEYS: Final = ("responseMimeType", "response_mime_type")
_RESPONSE_SCHEMA_KEYS: Final = ("responseJsonSchema", "response_json_schema", "responseSchema", "response_schema")
+_TOOL_PARAMETERS_KEYS: Final = ("parametersJsonSchema", "parameters")
_JSON_MIME_TYPE: Final = "application/json"
_GEMINI_ONLY_SCHEMA_KEYS: Final = frozenset({"propertyOrdering", "property_ordering"})
_CONFIG_FIELDS: Final = TypeAdapter(Mapping[str, object])
@@ -442,7 +443,7 @@ class GoogleGenAIAdapter:
if "description" in func_decl:
function_chunk["description"] = func_decl["description"]
- parameters = _first_present(func_decl, ("parametersJsonSchema", "parameters"))
+ parameters = _validated(_JSON_OBJECT_SCHEMA, _first_present(func_decl, _TOOL_PARAMETERS_KEYS))
if parameters is not None:
function_chunk["parameters"] = parameters
diff --git a/tests/test_litellm/google_genai/test_google_genai_adapter.py b/tests/test_litellm/google_genai/test_google_genai_adapter.py
index fb3bcb17c13..761ab7bac89 100644
--- a/tests/test_litellm/google_genai/test_google_genai_adapter.py
+++ b/tests/test_litellm/google_genai/test_google_genai_adapter.py
@@ -1544,6 +1544,20 @@ def test_null_parameters_json_schema_falls_back_to_parameters():
}
[email protected]("parameters", [5, "", "x", [1], True])
+def test_non_object_tool_parameters_are_dropped_instead_of_forwarded(parameters):
+ from litellm.google_genai.adapters.transformation import GoogleGenAIAdapter
+
+ adapter = GoogleGenAIAdapter()
+ tools = [{"functionDeclarations": [{"name": "lookup", "description": "Look it up", "parameters": parameters}]}]
+
+ completion_request = adapter.translate_generate_content_to_completion(
+ model="gpt-4.1", contents={"role": "user", "parts": [{"text": "hi"}]}, tools=tools
+ )
+
+ assert completion_request["tools"][0]["function"] == {"name": "lookup", "description": "Look it up"}
+
+
def test_streaming_chunk_has_no_top_level_text():
from litellm.google_genai.adapters.transformation import (
GoogleGenAIAdapter,