# FastAPI错误：响应字段的参数无效

- **ID:** `python/fastapi-response-model-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

response_model参数设置为无效类型或包含无法序列化的字段。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   Define a Pydantic model for the response: class ItemResponse(BaseModel):\n    name: str\n    price: float\nThen use response_model=ItemResponse.
   ```
2. **** (85% 成功率)
   ```
   Use response_model_exclude_unset=True to only include fields that were set.
   ```

## 无效尝试

- **** — Setting response_model to a dict without specifying keys can cause unexpected output. (60% 失败率)
- **** — Removing response_model entirely returns all fields, potentially leaking sensitive data. (80% 失败率)
