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

This commit is contained in:
mateo-berri 2026-09-19 19:19:33 -07:00
parent 47ebfa10a0
commit 5eb967d925
2 changed files with 16 additions and 1 deletions

View file

@ -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

View file

@ -1544,6 +1544,20 @@ def test_null_parameters_json_schema_falls_back_to_parameters():
}
@pytest.mark.parametrize("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,