BerriAI/litellm · error · ValueError
Invalid input: AnyOf schema with only null type is not suppo
Error message
Invalid input: AnyOf schema with only null type is not supported. Please provide a non-null type.
What it means
anyOf schema converter guard: every branch of the schema's anyOf was the null type, so after stripping nulls there is no concrete type left to mark nullable — the schema is unusable for Gemini and rejected.
Source
Thrown at litellm/llms/vertex_ai/common_utils.py:793
raise ValueError(
f"Max depth of {DEFAULT_MAX_RECURSE_DEPTH} exceeded while processing schema. Please check the schema for excessive nesting."
)
""" Converts null objects within anyOf by removing them and adding nullable to all remaining objects """
anyof: Final = schema.get("anyOf", None)
if anyof is not None:
contains_null = False
for atype in anyof:
if isinstance(atype, dict) and atype.get("type") == "null":
# remove null type
anyof.remove(atype)
contains_null = True
elif "type" not in atype and len(atype) == 0:
# Handle empty object case
atype["type"] = "object"
if len(anyof) == 0:
# Edge case: response schema with only null type present is invalid in Vertex AI
raise ValueError(
"Invalid input: AnyOf schema with only null type is not supported. Please provide a non-null type."
)
if contains_null:
# set all types to nullable following guidance found here: https://cloud.google.com/vertex-ai/generative-ai/docs/samples/generativeaionvertexai-gemini-controlled-generation-response-schema-3#generativeaionvertexai_gemini_controlled_generation_response_schema_3-python
# Empty `items: {}` on array branches is left in place; downstream
# process_items() converts it to {"type": "object"}, which Vertex
# requires whenever type == "array" (even inside anyOf).
for atype in anyof:
atype["nullable"] = True
properties: Final = schema.get("properties", None)
if properties is not None:
for name, value in properties.items():
convert_anyof_null_to_nullable(value, depth=depth + 1)
items: Final = schema.get("items", None)
if items is not None:View on GitHub (pinned to 77b7c6c40c)
Solutions
- Provide a non-null type in the AnyOf schema.
- Remove anyOf entries that only allow null.
Example fix
# replace {"anyOf": [{"type": "null"}]} with a concrete type. Defensive patterns
Strategy: validation
When it happens
Trigger: Triggered when an AnyOf schema contains only a null type; a non-null type is required.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/2cfee1be475af578.
Report an issue: GitHub.