fix(vertex_ai): default missing items on array schemas
Some checks failed
Unit Tests: Proxy DB Operations / proxy-db (auth-checks, tests/proxy_unit_tests/test_auth_checks.py tests/proxy_unit_tests/test_user_api_key_auth.py, 20, 8) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (key-generation, tests/proxy_unit_tests/test_key_generate_prisma.py, 30, 0) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (proxy-utils, tests/proxy_unit_tests/test_proxy_utils.py, 20, 8) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (remaining, tests/proxy_unit_tests --ignore=tests/proxy_unit_tests/test_key_generate_prisma.py --ignore=tests/proxy_unit_tests/test_auth_checks.py --ignore=tests/proxy_unit_tests/test_user_api_key_auth.py --ignore=tests/proxy_unit_tests/test_p… (push) Has been cancelled
Unit Tests: Security / security (push) Has been cancelled

Vertex rejects array schemas without an items field
(GenerateContentRequest.tools[*].function_declarations[*].parameters...items: missing field).
This happened for tool params containing anyOf branches like {"type": "array"}
with no items, including the case where convert_anyof_null_to_nullable
strips an empty items entry. Default missing items to {"type": "object"}
in process_items so the same default applies to bare arrays and
arrays nested inside anyOf.
This commit is contained in:
mateo-berri 2026-04-30 19:14:02 +00:00 committed by Cursor Agent
parent c3338384c9
commit 860843953d
No known key found for this signature in database
2 changed files with 24 additions and 1 deletions

View file

@ -599,6 +599,8 @@ def process_items(schema, depth=0):
if isinstance(schema, dict):
if "items" in schema and schema["items"] == {}:
schema["items"] = {"type": "object"}
elif schema.get("type") == "array" and "items" not in schema:
schema["items"] = {"type": "object"}
for key, value in schema.items():
if isinstance(value, dict):
process_items(value, depth + 1)

View file

@ -225,7 +225,11 @@ def test_build_vertex_schema():
"metadata": {"type": "object"},
"callbacks": {
"anyOf": [
{"type": "array", "nullable": True},
{
"type": "array",
"items": {"type": "object"},
"nullable": True,
},
{"type": "object", "nullable": True},
]
},
@ -288,6 +292,23 @@ def test_process_items_basic():
process_items(schema)
assert schema["properties"]["nested"]["items"] == {"type": "object"}
# Test array with no items field at all - Vertex requires items to be present
schema = {"type": "array"}
process_items(schema)
assert schema["items"] == {"type": "object"}
# Test array missing items inside anyOf branch
schema = {
"type": "object",
"properties": {
"callbacks": {
"anyOf": [{"type": "array"}, {"type": "object"}],
}
},
}
process_items(schema)
assert schema["properties"]["callbacks"]["anyOf"][0]["items"] == {"type": "object"}
def test_vertex_ai_complex_response_schema():
import json