Skip to main content

field_validator

Decorate methods on the class indicating that they should be used to validate fields.

def field_validator(
field: str,
*fields: str,
mode: FieldValidatorModes = 'after',
check_fields: bool | None = None,
json_schema_input_type: Any = PydanticUndefined
) - > Callable[[Any], Any]

Decorate methods on the class indicating that they should be used to validate fields.

Parameters

NameTypeDescription
fieldstrThe first field name the validator should apply to; must be a string.
*fieldsstrAdditional field names the validator should apply to.
modeFieldValidatorModes = 'after'Specifies whether to validate the fields before or after standard validation, or to use 'plain' or 'wrap' logic.
check_fields`boolNone` = None
json_schema_input_typeAny = PydanticUndefinedThe input type used to generate the appropriate JSON Schema; only valid when mode is 'before', 'plain', or 'wrap'.

Returns

TypeDescription
Callable[[Any], Any]A decorator function that wraps the target method and registers it as a Pydantic field validator.