pypi / pydantic
pydantic
What changed in pydantic 1 to 2, from its official release notes, upgrade guides and advisories. Sources checked 2026-12-04.
103 breaking2 security16 deprecations17 new APIs and options5 performance6 behavior and defaults3 tooling48 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initpydantic 2191 changes
Breaking changes 100
Validation now disallows extra keys that are not strings.
GraalPy 3.11 wheels are no longer published because they were not working due to a PyO3 version bump.
Attribute docstrings are no longer extracted from nested classes and functions.
With extra=allow, extra data matching a field name is ignored for dataclasses.
JSON validation now handles field lookup and extra data like Python validation; keys matching only an unused alias or field name are treated as extra data instead of being silently dropped.
Mapping max_length constraints are now checked during validation.
With extra=allow, extra data matching a field name is ignored for TypedDict values.
Rejects out-of-range int inputs for timedelta.
Enum constructors are called in both validation modes.
Fraction validation rejects large exponents.
JSON Schema defaults are encoded with a consistent configuration.
multiple_of constraints must be positive.
NameEmail validation rejects newlines.
Python 3.9 is no longer supported.
Serialization inference no longer applies ser_json_timedelta to all datetime types.
The config setting has been renamed to populate_by_name.
The allow_reuse keyword argument is no longer necessary because repeated-function detection now errors only for redefinition within a single class.
Fields annotated as Any no longer have an implicit default value of None.
The config setting has been renamed to str_to_lower.
The config setting has been renamed to str_strip_whitespace.
The config setting has been renamed to str_to_upper.
Url and Dsn types no longer inherit from str, so convert them with str(url) when using APIs that expect a string.
Coercion of int, float, and Decimal values to strings is optional and disabled by default.
Constrained* classes were removed; replace constrained types with Annotated and Field(...).
Constrained* classes were removed; StringConstraints is an alternative for constrained strings.
The copy_on_model_validation config setting has been removed.
Vanilla dataclasses no longer inherit the parent type's config; configure them with the config parameter on the @dataclass decorator.
Dataclasses used as fields no longer accept tuples as validation input; use dictionaries instead.
Fields typed as dict no longer accept iterables of pairs, including empty iterables.
Support for email-validator versions below 2.0.0 was dropped; update the package.
Models compare equal only to BaseModel instances with matching type, field values, extra values, and private attribute values; they are no longer equal to data dictionaries.
The error_msg_templates config setting has been removed.
Pydantic dataclasses no longer support extra='allow' for storing unexpected initializer fields as extra attributes.
Field no longer accepts arbitrary keyword arguments for JSON schema extras; pass extra data in the json_schema_extra dictionary argument.
field_validator replaces validator and does not accept each_item; annotate generic container item types to validate them.
The validator argument config was removed; use info.config to access configuration.
The validator argument field was removed; access field information through info.field_name and cls.model_fields.
Field.alias returns None when no alias is set, instead of returning the field's name.
Field.allow_mutation has been removed; use frozen instead.
The const property has been removed from Field.
Field.final has been removed; use the typing.Final type hint instead.
Field.max_items has been removed; use max_length instead.
Field.min_items has been removed; use min_length instead.
Field.regex has been removed; use pattern instead.
The unique_items property has been removed from Field.
The fields config setting has been removed; use Annotated on fields to modify them.
Float values convert to integers only when their decimal part is zero, preventing loss of fractional data.
Field constraints are no longer pushed down automatically to generic parameters; annotate the contained type with typing.Annotated instead.
GenericModel has been removed; define generic BaseModel subclasses by adding Generic as a parent class.
Custom types should replace __get_validators__ with __get_pydantic_core_schema__ to define validation using pydantic-core schemas.
Custom types should replace __modify_schema__ with __get_pydantic_json_schema__ to customize JSON schema generation.
The getter_dict config setting has been removed along with orm_mode.
GetterDict has been removed along with orm_mode; it was an implementation detail of orm_mode.
Pydantic no longer promises to preserve input types for generic collections; output types match annotations, while BaseModel subclasses and dataclasses retain their input types.
Use the intent query parameter instead of goal when fetching pydantic.dev pages; describe what you're trying to achieve.
The json_dumps config setting has been removed.
The json_loads config setting has been removed.
Generated schemas now indicate null for Optional fields, expose Decimal as a string, omit namedtuple preservation, and target draft 2020-12 by default.
The config setting has been renamed to ignored_types.
The config setting has been renamed to str_max_length.
The config setting has been renamed to str_min_length.
JSON serialization of non-string dictionary keys generally uses str(key), and model_dump_json output is compacted and may differ from json.dumps output.
Use model_fields in place of the V1 __fields__ attribute.
Use model_rebuild in place of update_forward_refs.
model_validate_json provides the JSON-loading behavior previously available through parse_raw.
model_validator replaces root_validator; in some cases, including assignment validation, it receives a model instance rather than a values dictionary.
An Optional field without a default is required but allows None; Optional no longer implies a default of None.
The config setting has been renamed to from_attributes.
The parse_env_var classmethod was removed; customize settings sources to provide a parsing function.
Pydantic dataclass __post_init__ now runs after validation rather than before.
The post_init_call config setting has been removed.
__post_init_post_parse__ has been removed because it became redundant after __post_init__ moved after validation.
Pydantic dataclasses no longer expose __pydantic_model__ or rely on an underlying BaseModel; use TypeAdapter for related functionality.
Use __pydantic_private__ in place of the V1 __private_attributes__ attribute.
Use __pydantic_validator__ in place of the V1 __validators__ attribute.
Color functionality moved to pydantic_extra_types.color.
parse_file_as is removed from the public API.
parse_raw_as is removed from the public API.
PyObject was replaced by pydantic.ImportString.
PaymentCardBrand moved to pydantic_extra_types.
PaymentCardNumber moved to pydantic_extra_types.
The alias generator moved to pydantic.alias_generators.to_pascal.
The alias generator moved to pydantic.alias_generators.to_camel.
version_info moved to pydantic.version.version_info.
validate_model is removed from the public API.
The deprecated root_validator can no longer run with skip_on_failure=False; set it explicitly to True.
RootModel replaces the __root__ field for custom root models; RootModel types do not support arbitrary_types_allowed.
The config setting has been renamed to json_schema_extra.
The smart_union config setting has been removed; the default union_mode in V2 is 'smart'.
Use the stack query parameter instead of organization to identify the language/framework context you are working in.
Nested model serialization includes only fields defined on the field's annotated type, rather than all fields on a subclass instance, helping prevent accidental security bugs.
A TypeError raised in a validator is no longer converted into a ValidationError, across all validation decorators.
The underscore_attrs_are_private setting has been removed because V2 behaves as if it were always True in V1.
Union validation preserves the input type when it matches a choice, rather than coercing it to an earlier choice; left-to-right behavior remains available with union_mode.
Set union_mode to left_to_right to restore the non-short-circuiting left-to-right union behavior of V1.
Validated URLs without a path now have a trailing slash, even when the input URL omitted one.
The config setting has been renamed to validate_default.
The decorator was renamed to validate_call; its former raw_function and validate attributes are not preserved.
The validate_arguments decorator was renamed to validate_call; the old decorator's raw_function and validate attributes are not preserved.
Validator function signatures can no longer include field or config arguments, even when using the deprecated validator decorator.
Deprecations 16
Invalid after model validator function signatures now raise a deprecation warning instead of an error.
Defining a Config class in a BaseModel subclass is deprecated in favor of the model_config class attribute.
from_orm is deprecated; use model_validate with from_attributes=True in the model config.
The .json() method is deprecated; use model_dump_json instead, since arguments such as indent or ensure_ascii may produce confusing errors.
Support for json_encoders in model config is deprecated; serialization decorators are preferred for common customization scenarios.
The model construction method is now named model_construct; construct is retained as deprecated where possible.
The model copy method is now named model_copy; copy is retained as deprecated where possible.
The JSON schema method is now named model_json_schema; json_schema is retained as deprecated where possible.
Using parameterized generics in isinstance checks is strongly discouraged; subclass the parameterized generic if such checks are needed.
parse_file is deprecated; load the data and pass it to model_validate.
parse_obj_as is deprecated; TypeAdapter is its complete replacement.
parse_raw is deprecated; use model_validate_json for JSON input, or load the data and pass it to model_validate.
Several V1 APIs, including parsing tools, encoders, and validators, are available under pydantic.deprecated paths.
The root_validator decorator is deprecated; replace it with model_validator, whose allowed signatures differ.
schema_of is deprecated; TypeAdapter is its complete replacement.
The validator decorator is deprecated; replace it with field_validator.
New APIs and options 17
Supports
closedandextra_itemsvia inheritance in TypedDict.A counter core schema is added.
create_model() accepts a __namespace__ parameter.
The multiple_of constraint is supported in fraction and timedelta core schemas.
An ordered-dict core schema is added.
Adds a method to FieldInfo for returning its data as a dictionary.
The field_serializer decorator adds support for customizing serialization.
Add the harness query parameter to identify the agent harness and model you are running.
Configure models with a model_config class attribute containing the desired key/value pairs; the nested Config class approach is deprecated.
The model dictionary serialization method is now named model_dump; dict is retained as deprecated where possible.
Use model_dump_json in place of json for model JSON serialization.
Use model_validate to validate objects, replacing parse_obj and, with from_attributes enabled, from_orm.
ValidationError is available as pydantic.ValidationError.
Pydantic V2 includes a mypy plugin that can be enabled in mypy configuration.
The V2 package continues to expose the Pydantic V1 API through the pydantic.v1 namespace, allowing gradual migration.
JSON schema generation methods accept schema_generator so callers can supply a custom GenerateJsonSchema subclass.
The Field validate_default argument can reproduce the V1 always=True behavior while offering more flexibility and control.
Performance 5
Serialization with per-index include or exclude on sequences no longer has quadratic time.
Skips decorator field checks when no field decorators exist.
Avoids heap allocation for small JSON model field buffers.
Avoids Python tuple allocation during model fields validation.
Avoids an unnecessary extra dict allocation in model validation.
Behavior and default changes 5
Explicit by_alias now overrides validate_by_alias in validation JSON schemas.
Sequence serialization now supports named tuples.
Supports named tuples in Sequence validation.
Default factories for private attributes can now take validated model data.
Constructor arguments may be copied during validation and coercion, which is notable when passing mutable objects.
Tooling 3
Wheels are now published for PyPy 8.0 using the pp80 ABI.
A beta code transformation tool is available to help migrate projects from Pydantic V1 to V2.
When using V1 features, this plugin might also need to be enabled alongside the V2 mypy plugin.
Fixes and other changes 45
Deeply nested data is no longer incorrectly reported as a cyclic reference.
Copying or unpickling models with
defer_buildno longer raisesRecursionError.Serialization JSON Schema now includes null for
unless-nonefield serializers.Wheels are now published for GraalPy 3.13 alongside 3.12, expanding the available platform builds.
Fixes unpickling of generic classes defined in a separate module.
Fixes a plugin crash on deferred empty models.
Calls repr of values lazily during nested union serialization.
Fixes forward annotation evaluation and type variable substitution when rebuilding parametrized generic models.
Fixes pickling of PydanticCustomError and ValidationError instances containing custom errors.
Prevents infinite recursion when validating an invalid default.
Fixes Self resolution in parametrized generics.
Fixes deep copying of self-referential models.
URL types equality now takes preserve_empty_path into account.
Adds a recursion guard to validate_strings().
Fixes the arguments-v3 schema when variadic keywords are present.
The Python Decimal validator now enforces the max_digits whole-digits limit.
Fixes a TypeError involving ForwardRef on Python 3.10.0.
OverflowError is caught during ByteSize validation.
Exceptions are handled during Decimal validation.
init and kw_only=False are propagated from Field() to stdlib dataclass fields.
Config propagation for stdlib dataclasses and TypedDicts in JSON Schema is fixed.
Propagated extra config is respected in the JSON Schema of stdlib dataclasses.
The model_config attribute is no longer mutated.
URL prefixes are no longer validated multiple times in multi host URLs.
Python 3.15 is now supported.
Incomplete types are rebuilt during serialization inference.
OS errors are handled during ZoneInfo validation.
Validated model fields are counted once in smart unions.
Validators can now be reused when plugins are set.
Preserves RootModel core metadata.
Handles AttributeError subclasses when using from_attributes.
Fixes
ValidationInfo.field_namebeing missing when usingmodel_validate_json().ValidationInfo.data is no longer missing when using model_validate_json().
Model equality is fixed when using runtime extra configuration.
Serialization warns when fixed length tuples have too few items.
The synthesized BaseSettings.__init__() signature uses a changed type for Any in _build_sources.
The namespace is updated to version 1.10.26, which includes support for Python 3.14.
Fixed a pickle error when using model_construct on a model with MISSING as a default value.
Reverts URL credential percent-encoding in the build() method of AnyUrl and Dsn types.
Validation no longer gets default values from defaultdict, fixing a subtle regression in its validation behavior.
Fields with exclude_if are no longer included among JSON Schema required fields.
Fixes field serializers on nested typed dictionaries.
Adds type inference for IP address types, fixing their JSON serialization when serialize_as_any is used.
Fixes forward references in parent TypedDict classes on Python 3.14 and greater.
Mutations on FieldInfo classes reused as Annotated metadata are supported again, though this remains an unsupported pattern.
pydantic 19 changes
Breaking changes 3
Only accepts
.as the decimal separator, addressing a security advisory.V1 support, including the pydantic.v1 namespace in Pydantic V2, fully ends after this release.
With ag-ui-protocol 1.0 or later, binary input parts are converted to image, audio, video, or document content; parts without a MIME type or payload still raise.
Security 2
Dataclasses ignore internal __pydantic attributes when setting extra values, addressing a security advisory.
Checks unique_items in linear time for builtin scalar types, addressing a security advisory.
Behavior and default changes 1
Unsupported message roles, input content types, or media source types introduced by a newer protocol version are skipped with a warning instead of failing the whole request.
Fixes and other changes 3
Fixes compatibility with Cython 3.3.
Fixed a syntax error that occurred under Python 3.7.
Adds minimal support for Python 3.14.