# pydantic.error_wrappers.ValidationError：User 有 1 个验证错误

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

## 根因

传递给 Pydantic 模型的数据与其模式不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 2.x | active | — | — |
| 2.5.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   User(name='John', age=30)  # age must be int
   ```
2. **** (90% 成功率)
   ```
   @field_validator('age')
def parse_age(cls, v):
    return int(v)
   ```

## 无效尝试

- **** — Only ignores extra fields, not type errors. (70% 失败率)
- **** — Same validation applies. (90% 失败率)
