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: keep type field in Gemini schema when properties is empty (#18979)

Rayan Pald92a0168cc41
diff --git a/litellm/llms/vertex_ai/common_utils.py b/litellm/llms/vertex_ai/common_utils.py
index 5ccbb8cd088..704e45e301d 100644
--- a/litellm/llms/vertex_ai/common_utils.py
+++ b/litellm/llms/vertex_ai/common_utils.py
@@ -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():
diff --git a/tests/test_litellm/llms/vertex_ai/test_gemini_empty_properties.py b/tests/test_litellm/llms/vertex_ai/test_gemini_empty_properties.py
new file mode 100644
index 00000000000..1a4e4d35ca9
--- /dev/null
+++ b/tests/test_litellm/llms/vertex_ai/test_gemini_empty_properties.py
@@ -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
diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
index 12e35a47280..19d8f174930 100644
--- a/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
+++ b/tests/test_litellm/llms/vertex_ai/test_vertex_ai_common_utils.py
@@ -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"