# fastapi.exceptions.ResponseValidationError：ResponseModel 有 1 个验证错误

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

## 根因

端点返回的数据与声明的 response_model 模式不匹配。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   @app.get('/item', response_model=Item)
def get_item():
    return {"name": "foo", "price": 10.0}
   ```
2. **** (85% 成功率)
   ```
   from typing import Union
@app.get('/item', response_model=Union[Item, Error])
   ```

## 无效尝试

- **** — Loses automatic documentation and validation, not a fix. (70% 失败率)
- **** — Only excludes unset fields, doesn't fix type mismatches. (80% 失败率)
