{
  "id": "python/pydantic-v2-extra-input-forbidden",
  "signature": "pydantic_core._pydantic_core.ValidationError: 1 validation error for User\n  Extra inputs are not permitted [type=extra_forbidden, input_value='admin', input_type=str]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError: 不允许额外的输入字段",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ User\\\n\\ \\ Extra\\ inputs\\ are\\ not\\ permitted\\ \\[type=extra_forbidden,\\ input_value='admin',\\ input_type=str\\]",
  "domain": "python",
  "category": "data_error",
  "subcategory": null,
  "root_cause": "In Pydantic v2, the default model_config no longer allows extra fields. Any key in the input dict that is not declared as a field triggers extra_forbidden.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 Pydantic v2 中，默认 model_config 不再允许额外字段。输入字典中任何未声明的键都会触发 extra_forbidden 错误。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The extra data is silently discarded, so downstream code that relies on it raises KeyError or AttributeError later.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Fields become untyped Any attributes; validation is skipped and IDE/type-checker support is lost, causing subtle runtime bugs.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Loses v2 performance, Rust core, and breaks other dependencies that require v2.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Declare the field explicitly on the model:\n\nclass User(BaseModel):\n    name: str\n    role: str = 'user'",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "If you intentionally want to accept unknown keys:\n\nclass User(BaseModel):\n    model_config = ConfigDict(extra='ignore')\n    name: str",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "For dynamic keys, use a dict field:\n\nclass User(BaseModel):\n    name: str\n    metadata: dict[str, Any] = {}",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-12",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}