Field
Usage of Field to create a FieldInfo object, providing additional information about a field for validation and serialization.
def Field(
default_factory: Callable[[], Any] | Callable[[dict[str, Any]], Any],
alias: str | None,
alias_priority: int | None,
validation_alias: str | AliasPath | AliasChoices | None,
serialization_alias: str | None,
title: str | None,
field_title_generator: Callable[[str, FieldInfo], str] | None,
description: str | None,
examples: list[Any] | None,
exclude: bool | None,
exclude_if: Callable[[Any], bool] | None,
discriminator: str | types.Discriminator | None,
deprecated: Deprecated | str | bool | None,
json_schema_extra: JsonDict | Callable[[JsonDict], None] | None,
frozen: bool | None,
validate_default: Literal[True],
repr: bool,
init: bool | None,
init_var: bool | None,
kw_only: bool | None,
pattern: str | re.Pattern[str] | None,
strict: bool | None,
coerce_numbers_to_str: bool | None,
gt: annotated_types.SupportsGt | None,
ge: annotated_types.SupportsGe | None,
lt: annotated_types.SupportsLt | None,
le: annotated_types.SupportsLe | None,
multiple_of: float | None,
allow_inf_nan: bool | None,
max_digits: int | None,
decimal_places: int | None,
min_length: int | None,
max_length: int | None,
union_mode: Literal['smart', 'left_to_right'],
fail_fast: bool | None
) - > Any
Configures metadata and validation constraints for a Pydantic model field. Use this to define default values, aliases, schema information, and numeric or string constraints.
Parameters
| Name | Type | Description |
|---|---|---|
| default_factory | `Callable[[], Any] | Callable[[dict[str, Any]], Any]` |
| alias | `str | None` |
| alias_priority | `int | None` |
| validation_alias | `str | AliasPath |
| serialization_alias | `str | None` |
| title | `str | None` |
| field_title_generator | `Callable[[str, FieldInfo], str] | None` |
| description | `str | None` |
| examples | `list[Any] | None` |
| exclude | `bool | None` |
| exclude_if | `Callable[[Any], bool] | None` |
| discriminator | `str | types.Discriminator |
| deprecated | `Deprecated | str |
| json_schema_extra | `JsonDict | Callable[[JsonDict], None] |
| frozen | `bool | None` |
| validate_default | Literal[True] | Forces Pydantic to run validation logic on the default value or default_factory result. |
| repr | bool | Determines if the field should be included in the string representation of the model. |
| init | `bool | None` |
| init_var | `bool | None` |
| kw_only | `bool | None` |
| pattern | `str | re.Pattern[str] |
| strict | `bool | None` |
| coerce_numbers_to_str | `bool | None` |
| gt | `annotated_types.SupportsGt | None` |
| ge | `annotated_types.SupportsGe | None` |
| lt | `annotated_types.SupportsLt | None` |
| le | `annotated_types.SupportsLe | None` |
| multiple_of | `float | None` |
| allow_inf_nan | `bool | None` |
| max_digits | `int | None` |
| decimal_places | `int | None` |
| min_length | `int | None` |
| max_length | `int | None` |
| union_mode | Literal['smart', 'left_to_right'] | Controls how Pydantic attempts to match data against types in a Union. |
| fail_fast | `bool | None` |
Returns
| Type | Description |
|---|---|
Any | A FieldInfo instance that Pydantic uses to define the field's behavior and schema. |