python
config_error
ai_generated
true
pydantic.errors.ConfigError: Invalid validator signature
ID: python/pydantic-validator-wrong-signature
80%Fix Rate
88%Confidence
0Evidence
2024-02-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 2.x | active | — | — | — |
Root Cause
A @field_validator or @model_validator function has an incorrect number or names of arguments (e.g., missing cls or value).
generic中文
@field_validator 或 @model_validator 函数的参数数量或名称不正确(例如缺少 cls 或 value)。
Workarounds
-
95% success
Define correctly: @field_validator('field') def validate(cls, v): return v -
90% success
For model validator: @model_validator(mode='after') def validate(self): return self
Dead Ends
Common approaches that don't work:
-
90% fail
Pydantic expects at least two arguments: cls and value.
-
80% fail
Validators are class methods, not instance methods.