{
  "id": "python/fastapi-query-param-type-error",
  "signature": "fastapi.exceptions.FastAPIError: Invalid type for query parameter 'age': <class 'str'> is not a valid type for a query parameter.",
  "signature_zh": "FastAPI 错误：查询参数 'age' 的类型无效：<class 'str'> 不是有效的查询参数类型。",
  "regex": "fastapi\\.exceptions\\.FastAPIError:\\ Invalid\\ type\\ for\\ query\\ parameter\\ 'age':\\ <class\\ 'str'>\\ is\\ not\\ a\\ valid\\ type\\ for\\ a\\ query\\ parameter\\.",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "FastAPI query parameters must have a type that can be parsed from strings; using unsupported types like str for a parameter that expects int causes this error.",
  "root_cause_type": "generic",
  "root_cause_zh": "FastAPI 查询参数必须具有可从字符串解析的类型；使用不支持的类型（如应为 int 却用了 str）会导致此错误。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using a custom class without type conversion",
      "why_fails": "FastAPI cannot automatically convert custom types.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting default value as string but type hint as int",
      "why_fails": "Mismatch between default and type hint causes validation issues.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use proper type hints like int, float, or str",
      "success_rate": 0.95,
      "how": "from fastapi import FastAPI, Query\napp = FastAPI()\n@app.get('/items')\ndef read_items(age: int = Query(...)):\n    return {'age': age}",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use Pydantic models for complex types",
      "success_rate": 0.9,
      "how": "from pydantic import BaseModel\nclass Item(BaseModel):\n    age: int\n\n@app.get('/items')\ndef read_items(item: Item = Query(...)):\n    return item",
      "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": "2024-07-14",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}