fix: keep type field in Gemini schema when properties is empty (#18979)

This commit is contained in:
Rayan Pal
2026-01-14 09:28:05 -08:00
committed by GitHub
parent 1391e41916
commit d92a0168cc
3 changed files with 20 additions and 4 deletions
+2 -2
View File
@@ -660,11 +660,11 @@ def add_object_type(schema):
if "required" in schema and schema["required"] is None:
schema.pop("required", None)
# Gemini doesn't accept empty properties for object types
# If properties is empty, remove it and the type field
# If properties is empty, remove it but keep type as object
if not properties:
schema.pop("properties", None)
schema.pop("type", None)
schema.pop("required", None)
schema["type"] = "object"
else:
schema["type"] = "object"
for name, value in properties.items():
@@ -0,0 +1,16 @@
"""Test for Gemini schema handling with empty properties."""
import os
import sys
sys.path.insert(0, os.path.abspath("../../../.."))
from litellm.llms.vertex_ai.common_utils import add_object_type
def test_add_object_type_empty_properties_keeps_type():
"""Gemini requires type: object even when properties is empty."""
schema = {"properties": {}, "type": "object"}
add_object_type(schema)
assert schema.get("type") == "object"
assert "properties" not in schema
@@ -1297,8 +1297,8 @@ def test_build_vertex_schema_empty_properties():
# Verify empty properties was removed
assert "properties" not in go_back_schema, "Empty properties should be removed"
# Verify type was also removed (since object without properties is invalid in Gemini)
assert "type" not in go_back_schema, "Type should be removed when properties is empty"
# Verify type is kept as object (Gemini requires type: object even without properties)
assert go_back_schema.get("type") == "object", "Type should be kept as object when properties is empty"
# Verify required was also removed
assert "required" not in go_back_schema, "Required should be removed when properties is empty"