{
  "id": "python/pydantic-validator-not-classmethod",
  "signature": "PydanticUserError: @field_validator on 'email' requires a classmethod, but the decorator was applied to a regular method. Add @classmethod below @field_validator.",
  "signature_zh": "PydanticUserError: 'email' 上的 @field_validator 需要 classmethod，但装饰器被应用于普通方法。请在 @field_validator 下方添加 @classmethod。",
  "regex": "PydanticUserError:\\ @field_validator\\ on\\ 'email'\\ requires\\ a\\ classmethod,\\ but\\ the\\ decorator\\ was\\ applied\\ to\\ a\\ regular\\ method\\.\\ Add\\ @classmethod\\ below\\ @field_validator\\.",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "In Pydantic v2, field_validator must decorate a classmethod; omitting @classmethod causes a PydanticUserError at class definition time.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 Pydantic v2 中，field_validator 必须装饰 classmethod；省略 @classmethod 会在类定义时引发 PydanticUserError。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "field_validator explicitly checks for classmethod; staticmethod is rejected.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Validators must be defined inside the model class to be registered.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.99,
      "how": "from pydantic import field_validator\nclass User(BaseModel):\n    email: str\n    @field_validator('email')\n    @classmethod\n    def check_email(cls, v):\n        return v.lower()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.94,
      "how": "from typing import Annotated\nfrom pydantic import AfterValidator\nEmail = Annotated[str, AfterValidator(lambda v: v.lower())]",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-01-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}