{
  "id": "python/fastapi-dependency-injection-error",
  "signature": "fastapi.exceptions.FastAPIError: Invalid args for response field",
  "signature_zh": "FastAPI 错误：响应字段的参数无效",
  "regex": "fastapi\\.exceptions\\.FastAPIError:\\ Invalid\\ args\\ for\\ response\\ field",
  "domain": "python",
  "category": "runtime_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.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "将所有参数改为 Any 类型",
      "why_fails": "失去了类型安全，可能隐藏错误",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "检查并修正依赖函数的返回类型",
      "success_rate": 0.9,
      "how": "def get_db() -> Session:\n    return Session()\n@app.get('/items', response_model=List[Item])\ndef get_items(db: Session = Depends(get_db)):\n    ...",
      "condition": "",
      "sources": []
    },
    {
      "action": "使用正确的依赖注入语法",
      "success_rate": 0.95,
      "how": "from fastapi import Depends\n@app.get('/')\ndef root(db: Session = Depends(get_db)):\n    ...",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-10-20",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}