Skip to content

no-unknown-pydantic-validator-field

Pydantic field decorators must target declared fields.

Why

A field validator or serializer naming a missing field prevents the model from being constructed.

Fix

Use the declared field name, or explicitly set check_fields=False for a validator intended for subclass fields.

Examples

Before — flagged Decorator targets a field the model does not declare
app/models.py
from pydantic import BaseModel, field_validator
class Model(BaseModel):
value: int
@field_validator("missing")
@classmethod
def check(cls, value: int) -> int:
return value
After — preferred Decorator names the declared field
app/models.py
from pydantic import BaseModel, field_validator
class Model(BaseModel):
value: int
@field_validator("value")
@classmethod
def check(cls, value: int) -> int:
return value