# HTTP 422 无法处理的实体：请求体字段类型验证失败。

- **ID:** `python/fastapi-422-unprocessable-entity`
- **领域:** python
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

客户端发送的值与 Pydantic 字段类型不匹配（例如给 int 传字符串，给非可选字段传 null）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.100.x | active | — | — |
| 0.110.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Use `age: int = Field(..., ge=0)` and document; client should send `{"age": 30}` not `{"age": "30"}` unless using `model_config = ConfigDict(coerce_numbers_to_str=False)` with custom validator.
   ```
2. **** (90% 成功率)
   ```
   Add a custom validator: `@field_validator('age', mode='before') def coerce(cls, v): return int(v)`
   ```

## 无效尝试

- **** — Validation runs before the handler; decorator status does not apply. (90% 失败率)
- **** — Hides the real cause; clients still send wrong types. (70% 失败率)
