# pydantic_core._pydantic_core.ValidationError: 1 validation error for Node
child
  Recursion error - maximum recursion depth exceeded [type=recursion_loop, input_value={...}, input_type=dict]

- **ID:** `python/pydantic-recursion-depth`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A self-referential model (e.g., Node.child: Node) received a cyclic input dict, so validation loops forever.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   def has_cycle(d, seen=None):
    seen = seen or set()
    if id(d) in seen: return True
    seen.add(id(d))
    return any(has_cycle(v, seen) for v in d.values() if isinstance(v, dict))
assert not has_cycle(payload)
   ```
2. **** (80% success)
   ```
   from pydantic import BaseModel, model_validator
class Node(BaseModel):
    child: 'Node | None' = None
    @model_validator(mode='before')
    @classmethod
    def depth_guard(cls, v, info):
        d = info.context.get('depth', 0) if info.context else 0
        if d > 50: raise ValueError('too deep')
        return v
   ```

## Dead Ends

- **** — Turns the loop into a segfault instead of a clean ValidationError. (75% fail)
- **** — Disables nested validation entirely; malformed children pass silently. (55% fail)
- **** — The error is raised as ValidationError; the except clause never fires. (50% fail)
