{
  "id": "python/pydantic-field-validator-signature-error",
  "signature": "pydantic.errors.PydanticUserError: @field_validator 'check_email' should be a classmethod or a staticmethod. Wrap the function with @classmethod or @staticmethod.",
  "signature_zh": "pydantic.errors.PydanticUserError: @field_validator 'check_email' 应为 classmethod 或 staticmethod。请用 @classmethod 或 @staticmethod 包装。",
  "regex": "pydantic\\.errors\\.PydanticUserError:\\ @field_validator\\ 'check_email'\\ should\\ be\\ a\\ classmethod\\ or\\ a\\ staticmethod\\.\\ Wrap\\ the\\ function\\ with\\ @classmethod\\ or\\ @staticmethod\\.",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "In Pydantic v2, @field_validator must decorate a classmethod (or staticmethod). Missing the @classmethod decorator causes a PydanticUserError at class definition time.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 Pydantic v2 中，@field_validator 必须装饰 classmethod（或 staticmethod）。缺少 @classmethod 装饰器会在类定义时引发 PydanticUserError。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Decorator order matters: @field_validator must be the outermost decorator, i.e., listed first.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "@validator is deprecated in v2 and raises PydanticDeprecatedSince20 warnings; it also still requires classmethod semantics.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.98,
      "how": "from pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    email: str\n\n    @field_validator('email')\n    @classmethod\n    def check_email(cls, v):\n        assert '@' in v\n        return v",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from pydantic import BaseModel, field_validator\n\nclass User(BaseModel):\n    email: str\n\n    @field_validator('email')\n    @staticmethod\n    def check_email(v):\n        return 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-03-15",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}