mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-12 15:05:01 +00:00
fix: keep type field in Gemini schema when properties is empty (#18979)
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user