{
  "id": "python/pydantic-v2-string-type-coercion-strict",
  "signature": "pydantic_core._pydantic_core.ValidationError: 1 validation error for Product\nprice\n  Input should be a valid string [type=string_type, input_value=19.99, input_type=float]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError: 1 validation error for Product\nprice\n  输入应为有效的字符串 [type=string_type, input_value=19.99, input_type=float]",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ Product\\\nprice\\\n\\ \\ Input\\ should\\ be\\ a\\ valid\\ string\\ \\[type=string_type,\\ input_value=19\\.99,\\ input_type=float\\]",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "The model was configured with strict=True (or the field uses StrictStr), so Pydantic v2 refuses to coerce a float into a string even though lax mode would accept it.",
  "root_cause_type": "generic",
  "root_cause_zh": "模型配置了 strict=True（或字段使用了 StrictStr），因此 Pydantic v2 拒绝将 float 强制转换为字符串，即使宽松模式会接受。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Pushes type-handling logic to every call site; easy to miss one and re-trigger the error",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disables strictness everywhere, silently accepting bad data for unrelated fields",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "Add a field_validator with mode='before' to coerce: `@field_validator('price', mode='before') @classmethod def coerce(cls, v): return str(v)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Relax strictness per-field: `price: str = Field(strict=False)` while keeping the model strict.",
      "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.86,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}