BerriAI/litellm · error · ValueError

Max depth of {DEFAULT_MAX_RECURSE_DEPTH} exceeded while proc

Error message

Max depth of {DEFAULT_MAX_RECURSE_DEPTH} exceeded while processing schema. Please check the schema for excessive nesting.

What it means

Guard in the recursive schema processor: flattening/simplifying a JSON schema (e.g. anyOf handling) exceeded DEFAULT_MAX_RECURSE_DEPTH, protecting against pathological or cyclic schemas that would hang or blow the stack. The input at fault is the tool/response schema passed to Vertex AI.

Source

Thrown at litellm/llms/vertex_ai/common_utils.py:681

    """
    title: Final = schema_dict.get("title", None)
    description: Final = schema_dict.get("description", None)

    if isinstance(schema_dict, dict) and schema_dict.get("anyOf"):
        any_of: Final = schema_dict["anyOf"]
        if (title or description) and isinstance(any_of, list) and all(isinstance(item, dict) for item in any_of):
            for item in any_of:
                if title:
                    item["title"] = title
                if description:
                    item["description"] = description
        return {"anyOf": any_of}
    return schema_dict


def process_items(schema, depth=0):
    if depth > DEFAULT_MAX_RECURSE_DEPTH:
        raise ValueError(
            f"Max depth of {DEFAULT_MAX_RECURSE_DEPTH} exceeded while processing schema. Please check the schema for excessive nesting."
        )
    if isinstance(schema, dict):
        # Vertex requires `items` whenever `type == "array"` (even inside anyOf).
        # Normalize: empty `items: {}` and missing-items both become {"type": "object"}.
        type_val: Final = schema.get("type")
        if (
            (
                isinstance(type_val, str)
                and type_val.lower() == "array"
                and ("items" not in schema or schema.get("items") == {})
            )
            or schema.get("type") == "array"
            and "items" not in schema
        ):
            schema["items"] = {"type": "object"}
        for key, value in schema.items():
            if isinstance(value, dict):

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Reduce excessive nesting in the schema.
  2. Simplify the response_format / tool schema being sent.

Example fix

# flatten nested object definitions in the schema.
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when schema processing exceeds DEFAULT_MAX_RECURSE_DEPTH; check the schema for excessive nesting.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/b5334d9697d1746f. Report an issue: GitHub.