python config_error ai_generated true

pydantic.errors.ConfigError: Invalid validator signature

ID: python/pydantic-validator-wrong-signature

Also available as: JSON · Markdown · 中文
80%Fix Rate
88%Confidence
0Evidence
2024-02-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 95% success
    Define correctly: @field_validator('field') def validate(cls, v): return v
  2. 90% success
    For model validator: @model_validator(mode='after') def validate(self): return self

Dead Ends

Common approaches that don't work:

  1. 90% fail

    Pydantic expects at least two arguments: cls and value.

  2. 80% fail

    Validators are class methods, not instance methods.