{
  "id": "python/fastapi-response-model-serialization-error",
  "signature": "pydantic.error_wrappers.ValidationError: 1 validation error for Item\nresponse -> name\n  str type expected (type=type_error.str)",
  "signature_zh": "Pydantic 验证错误：响应字段 'name' 期望字符串类型",
  "regex": "pydantic\\.error_wrappers\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ Item\\\nresponse\\ \\->\\ name\\\n\\ \\ str\\ type\\ expected\\ \\(type=type_error\\.str\\)",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "FastAPI 路径操作返回的数据类型与响应模型不匹配",
  "root_cause_type": "generic",
  "root_cause_zh": "FastAPI 路径操作返回的数据类型与响应模型不匹配",
  "versions": [
    {
      "version": "3.9",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "3.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "禁用响应模型验证",
      "why_fails": "失去了类型安全性",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "返回原始字典而不使用模型",
      "why_fails": "文档生成可能出错",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "确保返回数据与模型一致",
      "success_rate": 0.95,
      "how": "class Item(BaseModel):\n    name: str\n@app.get('/item', response_model=Item)\ndef get():\n    return Item(name='test')",
      "condition": "",
      "sources": []
    },
    {
      "action": "使用 response_model_exclude_unset",
      "success_rate": 0.9,
      "how": "@app.get('/item', response_model=Item, response_model_exclude_unset=True)\ndef get():\n    return {'name': 'test'}",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2025-07-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}