{
  "id": "python/pydantic-union-tag-discriminator-error",
  "signature": "pydantic_core._pydantic_core.ValidationError: 3 validation errors for TaggedUnion\ncat.kind\n  Input should be 'cat' [type=literal_error, input_value='dog', input_type=str]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError: 标签联合类型校验失败，kind 字段应为 'cat'，实际为 'dog'",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 3\\ validation\\ errors\\ for\\ TaggedUnion\\\ncat\\.kind\\\n\\ \\ Input\\ should\\ be\\ 'cat'\\ \\[type=literal_error,\\ input_value='dog',\\ input_type=str\\]",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "A discriminated union with a Literal discriminator received a tag value that does not match any union member, so every branch fails validation.",
  "root_cause_type": "generic",
  "root_cause_zh": "使用 Literal 判别器的可辨识联合收到一个不匹配任何联合成员的标签值，导致每个分支都校验失败。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Falls back to slow smart-union matching and produces confusing errors when multiple members overlap.",
      "fail_rate": 0.65,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Discriminator requires all Literal values to be unique; a str member makes the union ambiguous and Pydantic raises at build time.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "kind = data.get('kind')\nmapping = {'cat': Cat, 'dog': Dog}\nif kind not in mapping:\n    raise ValueError(f'unknown kind: {kind}')\nobj = mapping[kind].model_validate(data)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "from typing import Annotated\nfrom pydantic import BeforeValidator\n\nNormalize = Annotated[str, BeforeValidator(lambda v: v.lower())]\n\nclass Cat(BaseModel):\n    kind: Literal['cat']\n    name: Normalize",
      "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.84,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}