{
  "id": "python/pydantic-strict-str-from-int",
  "signature": "pydantic_core._pydantic_core.ValidationError: 1 validation error for Payload\nname\n  Input should be a valid string [type=string_type, input_value=123, input_type=int]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError：1 个验证错误（Payload）\nname\n  输入应为有效的字符串 [type=string_type, input_value=123, input_type=int]",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ Payload\\\nname\\\n\\ \\ Input\\ should\\ be\\ a\\ valid\\ string\\ \\[type=string_type,\\ input_value=123,\\ input_type=int\\]",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "model_config strict=True (or StrictStr) prevents coercion of int to str, even though v1 allowed it.",
  "root_cause_type": "generic",
  "root_cause_zh": "model_config 的 strict=True（或 StrictStr）阻止将 int 强制转换为 str，尽管 v1 允许这样做。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Changes semantics only for that field; other numeric-to-string coercions still fail.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Every caller must remember; easy to miss in one code path.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Disables strictness everywhere, re-introducing silent coercions you wanted to avoid.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from pydantic import BaseModel, field_validator\nclass Payload(BaseModel):\n    model_config = {'strict': True}\n    name: str\n    @field_validator('name', mode='before')\n    @classmethod\n    def to_str(cls, v):\n        return str(v)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "class Payload(BaseModel):\n    name: int | str\n    @field_validator('name')\n    @classmethod\n    def norm(cls, v): return str(v)",
      "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-06-02",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}