# fastapi.exceptions.HTTPException: 422: Unprocessable Entity

- **ID:** `python/fastapi-httpexception-422-unprocessable-entity`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Request body is well-formed but contains semantic errors, like invalid data types.

## Version Compatibility

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

## Workarounds

1. **Use Pydantic's conint or constr for validation** (90% success)
   ```
   from pydantic import BaseModel, conint
class Item(BaseModel):
    age: conint(gt=0, lt=150)  # valid integer
   ```
2. **Add custom validators** (85% success)
   ```
   from pydantic import validator
class Item(BaseModel):
    name: str
    @validator('name')
    def name_must_be_alpha(cls, v):
        if not v.isalpha():
            raise ValueError('must be alphabetic')
        return v
   ```

## Dead Ends

- **Sending numbers as strings without conversion** — Pydantic may not auto-convert if strict mode is on. (70% fail)
- **Missing required fields in nested models** — Validation fails at nested level. (80% fail)
