{
  "id": "python/pydantic-field-validator-info-arg",
  "signature": "pydantic.errors.PydanticUserError: If you use `@field_validator` with `mode='after'`, the function must be a classmethod. If you want to use an instance method, use `@model_validator(mode='after')` instead.",
  "signature_zh": "pydantic.errors.PydanticUserError：如果使用 `@field_validator` 且 `mode='after'`，函数必须为 classmethod。若想使用实例方法，请改用 `@model_validator(mode='after')`。",
  "regex": "pydantic\\.errors\\.PydanticUserError:\\ If\\ you\\ use\\ `@field_validator`\\ with\\ `mode='after'`,\\ the\\ function\\ must\\ be\\ a\\ classmethod\\.\\ If\\ you\\ want\\ to\\ use\\ an\\ instance\\ method,\\ use\\ `@model_validator\\(mode='after'\\)`\\ instead\\.",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "An instance method was decorated with @field_validator without @classmethod, which v2 disallows for after-mode.",
  "root_cause_type": "generic",
  "root_cause_zh": "实例方法被 @field_validator 装饰但未加 @classmethod，v2 对 after 模式不允许这样做。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Changes validation order; before-mode runs on raw input and may not see coerced types.",
      "fail_rate": 0.45,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Pydantic requires classmethod for field validators; staticmethod raises a different error.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Bypasses validation pipeline and breaks model_validate paths.",
      "fail_rate": 0.55,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "from pydantic import BaseModel, field_validator\nclass M(BaseModel):\n    x: int\n    @field_validator('x', mode='after')\n    @classmethod\n    def check(cls, v):\n        assert v > 0\n        return v",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from pydantic import model_validator\nclass M(BaseModel):\n    x: int\n    @model_validator(mode='after')\n    def check(self):\n        assert self.x > 0\n        return self",
      "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-05",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}