FieldInfo.asdict() method returns annotation, metadata, and attributes
The FieldInfo.asdict() method returns a dictionary with three keys: 'annotation' (the field type), 'metadata' (a list of constraints and metadata like Gt() or WithJsonSchema()), and 'attributes' (remaining field-specific attributes like title).
Pydantic optional timezone dependency
The timezone optional dependency provides a fallback IANA time zone database via the tzdata package. Install with pip using: pip install 'pydantic[timezone]' or with uv using: uv add 'pydantic[timezone]'
Pydantic optional email dependency
The email optional dependency provides email validation via the email-validator package. Install with pip using: pip install 'pydantic[email]' or with uv using: uv add 'pydantic[email]'
PositiveInt type annotation
PositiveInt is shorthand for Annotated[int, annotated_types.Gt(0)], representing a positive integer.
Pydantic type coercion in lax mode
In lax mode (the default), Pydantic attempts to coerce data to the correct type where appropriate. For example, strings can be coerced to integers, bytes keys can be coerced to strings, and string values can be coerced to integers.
datetime field parsing from ISO 8601 and Unix timestamp
Pydantic datetime fields accept either ISO 8601 formatted strings or Unix timestamp integers, converting them to datetime objects.
BoolSchema core schema structure
The BoolSchema core schema has the following structure with fields: type (Required[Literal['bool']]), strict (bool), ref (str), metadata (Any), and serialization (SerSchema). When defining a Pydantic model with a boolean field and Field(strict=True), the core schema for that field is {"type": "bool", "strict": True}.
Pydantic supports Annotated with constraints
Pydantic allows using the Annotated type from typing along with the annotated-types package to apply constraints beyond standard Python types while maintaining typing support. For example, Annotated[float, Gt(0)] enforces that a float must be greater than 0.
Iterables of pairs no longer coerce to dict
In Pydantic V2, iterables of pairs (including empty iterables) no longer pass validation for fields of type `dict`.
Union type preserves input type when possible
In Pydantic V2, union types preserve the type of the input whenever possible, even if the correct type is not the first choice. For example, `Model(x='1')` with `x: int | str` preserves the string type. To revert to V1's left-to-right behavior, use `Field(union_mode='left_to_right')`.
Optional field behavior changes
In Pydantic V2, fields annotated as `Optional[T]` are required and can be `None`, but do not have a default value of `None` unless explicitly set. This matches dataclass behavior and differs from V1. A field is only not required if it has a default value.
Any type no longer has default value of None
In Pydantic V2, fields annotated as `Any` no longer have a default value of `None`. If you want a field to be not required and allow any type, use `Any = None` explicitly.
Regex uses Rust regex crate instead of Python
Pydantic V2 uses Rust's regex crate instead of Python's regex library. The Rust crate provides linear time searching but drops features like lookarounds and backreferences. Use the `regex_engine` config setting to use Python's regex library if needed.
Float to integer conversion only allows zero fractional part
In Pydantic V2, type conversion from floats to integers is only allowed if the decimal part is zero. For example, `Model(x=10.0)` is valid, but `Model(x=10.2)` raises a `ValidationError`.
__get_validators__ replaced with __get_pydantic_core_schema__
In Pydantic V2, custom types should use `__get_pydantic_core_schema__` instead of `__get_validators__` for custom validation logic.
__modify_schema__ replaced with __get_pydantic_json_schema__
In Pydantic V2, custom types should use `__get_pydantic_json_schema__` instead of `__modify_schema__` to customize JSON schema generation.
Decimal type exposed as string in JSON schema
In Pydantic V2, the `Decimal` type is exposed in JSON schema (and serialized) as a string.
Color and PaymentCardNumber types moved to pydantic-extra-types
In Pydantic V2, the `Color` types and payment card number types have been moved to the `pydantic-extra-types` package.
URL and DSN types no longer inherit from str
In Pydantic V2, `AnyUrl` and other `Url` and `Dsn` types no longer inherit from `str`. They are built using `Annotated`. To use them in APIs expecting `str`, convert with `str(url)`.
URL validation uses Rust url crate
Pydantic V2 uses Rust's url crate for URL validation. URL validation differs slightly from V1. The new types append slashes to the validated version if no path is included, even if no slash was in the original argument.
Constrained types replaced with Annotated and Field
In Pydantic V2, the `Constrained*` classes are removed. Replace them using `Annotated[<type>, Field(...)]`. For example, `Annotated[int, Field(ge=0)]` replaces `ConstrainedInt` with `ge = 0`. For `ConstrainedStr`, use `StringConstraints` instead.
Field no longer supports arbitrary kwargs for JSON schema
In Pydantic V2, `Field` no longer supports arbitrary keyword arguments to be added to the JSON schema. Instead, pass extra data as a dictionary to the `json_schema_extra` keyword argument.
Field alias property returns None when not set
In Pydantic V1, the `alias` property returned the field's name when no alias was set. In Pydantic V2, it returns `None` when no alias is set.
Field constraint properties removed or renamed
The following properties have been removed from or changed in `Field`: `const`, `min_items` (use `min_length` instead), `max_items` (use `max_length` instead), `unique_items`, `allow_mutation` (use `frozen` instead), `regex` (use `pattern` instead), `final` (use `typing.Final` type hint instead).
Field constraints not pushed to generic parameters
In Pydantic V2, field constraints are no longer automatically pushed down to the parameters of generics. For example, `my_list: list[str] = Field(pattern=".*")` no longer validates every element. Use `typing.Annotated` instead: `my_list: list[Annotated[str, Field(pattern=".*")]]`.
Type coercion changes in V2
Pydantic V2 includes changes to type coercion. Coercing `int`, `float`, and `Decimal` values to strings is now optional and disabled by default (see `coerce_numbers_to_str` config). Iterables of pairs are no longer coerced to a dict.
Input types not preserved for generic collections
In Pydantic V2, input types are not preserved for generic collections. For example, passing `collection.Counter()` to a field annotated as `Mapping[str, int]` results in a plain `dict`, not a `Counter`. Pydantic V2 only promises the output type matches the annotation. Use custom validators or `TypeAdapter` to preserve specific input types if needed.
Input types preserved for BaseModel and dataclass subclasses
In Pydantic V2, while input types are not preserved for generic collections, they are preserved for subclasses of `BaseModel` and for dataclasses used as fields.