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
| Name | Type | Description |
|---|---|---|
| field | str | The first field name the validator should apply to; must be a string. |
| *fields | str | Additional field names the validator should apply to. |
| mode | FieldValidatorModes = 'after' | Specifies whether to validate the fields before or after standard validation, or to use 'plain' or 'wrap' logic. |
| check_fields | `bool | None` = None |
| json_schema_input_type | Any = PydanticUndefined | The input type used to generate the appropriate JSON Schema; only valid when mode is 'before', 'plain', or 'wrap'. |
Returns
| Type | Description |
|---|---|
Callable[[Any], Any] | A decorator function that wraps the target method and registers it as a Pydantic field validator. |