{"record":{"id":"1cb61cfbe416eb26","repo":"BerriAI/litellm","slug":"max-depth-of-default-max-recurse-depth-exceeded-1cb61c","errorCode":null,"errorMessage":"Max depth of {DEFAULT_MAX_RECURSE_DEPTH} exceeded while processing model fields. Please check the model structure for excessive nesting.","messagePattern":"Max depth of (.+?) exceeded while processing model fields\\. Please check the model structure for excessive nesting\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"litellm/proxy/guardrails/guardrail_endpoints.py","lineNumber":1811,"sourceCode":"    if field_default is not None and field_default is not ...:\n        field_dict[\"default_value\"] = field_default\n\n    # Copy min, max, step from json_schema_extra for number/percentage inputs\n    if field_json_schema_extra:\n        for key in (\"min\", \"max\", \"step\", \"default_value\"):\n            if key in field_json_schema_extra:\n                field_dict[key] = field_json_schema_extra[key]\n\n    return field_dict\n\n\ndef _extract_fields_recursive(\n    model: type[BaseModel],\n    depth: int = 0,\n) -> dict[str, object]:\n    # Check if we've exceeded the maximum recursion depth\n    if depth > DEFAULT_MAX_RECURSE_DEPTH:\n        raise HTTPException(\n            status_code=400,\n            detail=f\"Max depth of {DEFAULT_MAX_RECURSE_DEPTH} exceeded while processing model fields. Please check the model structure for excessive nesting.\",\n        )\n\n    fields: Final = {}\n\n    for field_name, field in model.model_fields.items():\n        field_annotation = field.annotation\n\n        # Skip optional_params if it's not meaningfully overridden\n        if _should_skip_optional_params(field_name=field_name, field_annotation=field_annotation):\n            continue\n\n        # Handle Optional types and get the actual type\n        if field_annotation is None:\n            continue\n\n        field_annotation = _unwrap_optional_type(field_annotation=field_annotation)","sourceCodeStart":1793,"sourceCodeEnd":1829,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/proxy/guardrails/guardrail_endpoints.py#L1793-L1829","documentation":"_extract_fields_recursive guards against pathological model nesting (self-referential or deeply recursive schemas) when building guardrail UI field forms; exceeding DEFAULT_MAX_RECURSE_DEPTH aborts extraction.","triggerScenarios":"Thrown at litellm/proxy/guardrails/guardrail_endpoints.py:1811 when the library encounters an invalid state.","commonSituations":"Model fields are nested deeper than the maximum recursion depth.","solutions":["Reduce nesting depth in the model/request structure.","Check for recursive or self-referential structures in the payload."],"exampleFix":"Flatten overly nested message/metadata fields before sending the request.","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}