unstale

pypi / pydantic-core

pydantic-core

What changed in pydantic-core 2, from its official release notes, upgrade guides and advisories. Sources checked 2026-12-05.

90 breaking10 deprecations18 new APIs and options3 performance7 behavior and defaults2 tooling26 fixes and other

See which of these apply to your code, ranked, in your agent:

npx @unstale/cli init

@unstale/cli 0.3.1 on npm

pydantic-core 2156 changes

Breaking changes 90

  • Attribute docstrings are no longer extracted from nested classes and functions.

    2.14.2release notes

  • For TypedDict and dataclasses with extra=allow, extra data matching a field name is ignored.

    2.14.2release notes

  • 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.

    2.14.2release notes

  • The mapping max_length constraint is now checked during validation.

    2.14.2release notes

  • The config setting has been removed; use frozen equivalently with the inverse of its current use.

    2.0.0upgrade guide

  • With a validator using always=True, standard validators for the annotated type are also applied to defaults.

    2.0.0upgrade guide

  • Fields annotated as Any no longer default to None and are required unless an explicit default is provided.

    2.0.0upgrade guide

  • Url and Dsn types no longer inherit from str; convert them with str(url) when using APIs that expect a string.

    2.0.0upgrade guideupgrade guide

  • Coercing int, float, and Decimal values to strings is optional and disabled by default.

    2.0.0upgrade guideupgrade guide

  • Color Types have moved to the separately installable Pydantic Extra Types package.

    2.0.0upgrade guide

  • Arguments passed to model constructors may be copied during validation and coercion, which matters when passing mutable objects.

    2.0.0upgrade guide

  • This config setting has been removed.

    2.0.0upgrade guideupgrade guide

  • A parent type's config is no longer applied to vanilla dataclass fields; use the config parameter on the @dataclass decorator to override config.

    2.0.0upgrade guideupgrade guide

  • Pydantic dataclasses no longer support extra='allow'; extra='ignore' remains supported but does not store extra fields.

    2.0.0upgrade guideupgrade guide

  • Dataclasses used as fields no longer accept tuples as validation inputs; use dictionaries instead.

    2.0.0upgrade guideupgrade guide

  • Decimal is represented as a string in generated JSON schema and serialization.

    2.0.0upgrade guideupgrade guide

  • This config setting has been removed.

    2.0.0upgrade guideupgrade guide

  • Arbitrary keyword arguments are no longer added to JSON schema; pass extra schema data through json_schema_extra instead.

    2.0.0upgrade guideupgrade guide

  • Use frozen instead of allow_mutation.

    2.0.0upgrade guideupgrade guide

  • The const property has been removed.

    2.0.0upgrade guideupgrade guide

  • Constraints are no longer automatically pushed down to generic parameters; use typing.Annotated to annotate the parameter type.

    2.0.0upgrade guideupgrade guide

  • Use the typing.Final type hint instead.

    2.0.0upgrade guide

  • Use the typing.Final type hint instead of the final property.

    2.0.0upgrade guide

  • Use max_length instead of max_items.

    2.0.0upgrade guideupgrade guide

  • Use min_length instead of min_items.

    2.0.0upgrade guideupgrade guide

  • Use pattern instead of regex.

    2.0.0upgrade guideupgrade guide

  • The unique_items property has been removed.

    2.0.0upgrade guide

  • Introduced as the replacement for validator, with new features; annotate generic container item types to validate their contents.

    2.0.0upgrade guide

  • Validator functions no longer receive the config argument; access configuration through info.config instead.

    2.0.0upgrade guideupgrade guide

  • The new decorator does not accept the each_item keyword argument; annotate the container's type argument to validate its items.

    2.0.0upgrade guide

  • Validator functions no longer receive the field argument; use info.field_name to look up the field in cls.model_fields.

    2.0.0upgrade guideupgrade guide

  • Returns None when no alias is set, rather than returning the field name.

    2.0.0upgrade guideupgrade guide

  • This config setting has been removed; use Annotated on fields to modify them.

    2.0.0upgrade guideupgrade guide

  • Float values convert to integers only when their decimal part is zero, avoiding loss of fractional data.

    2.0.0upgrade guideupgrade guide

  • Renamed from orm_mode.

    2.0.0upgrade guideupgrade guide

  • Generic BaseModel subclasses can be created directly by adding Generic as a parent class.

    2.0.0upgrade guide

  • Removed; generic BaseModel subclasses can now inherit from Generic directly.

    2.0.0upgrade guideupgrade guide

  • Custom types should use __get_pydantic_core_schema__ in place of __get_validators__.

    2.0.0upgrade guideupgrade guide

  • Custom JSON schema hooks use __get_pydantic_json_schema__ in place of __modify_schema__.

    2.0.0upgrade guideupgrade guide

  • Removed because orm_mode and its implementation detail are no longer supported.

    2.0.0upgrade guideupgrade guide

  • Removed along with orm_mode; it was an implementation detail of that feature.

    2.0.0upgrade guide

  • Renamed from keep_untouched.

    2.0.0upgrade guideupgrade guide

  • Validated generic collections are no longer guaranteed to preserve their input subtype; output types match the annotations, while BaseModel subclasses and dataclasses retain their types.

    2.0.0upgrade guideupgrade guide

  • Iterables of pairs, including empty iterables, are no longer coerced to dictionaries during validation.

    2.0.0upgrade guideupgrade guide

  • This config setting has been removed.

    2.0.0upgrade guideupgrade guide

  • Non-string JSON key values are generally serialized using str(key), changing outputs such as the serialization of a None key.

    2.0.0upgrade guideupgrade guide

  • This config setting has been removed.

    2.0.0upgrade guideupgrade guide

  • Generated JSON schema now targets draft 2020-12 by default, with some OpenAPI extensions.

    2.0.0upgrade guide

  • Renamed from schema_extra; also used to pass extra JSON schema data to Field.

    2.0.0upgrade guideupgrade guide

  • Replaces construct() as the model construction method.

    2.0.0upgrade guideupgrade guide

  • Replaces copy() as the model copying method.

    2.0.0upgrade guideupgrade guide

  • Replaces dict() as the method for dumping model data.

    2.0.0upgrade guideupgrade guide

  • Replaces json() for JSON serialization; output is compacted and may not exactly match json.dumps() output.

    2.0.0upgrade guideupgrade guide

  • Models are equal only to BaseModel instances with matching type, field values, extra values, and private attribute values; they are no longer equal to dictionaries containing their data.

    2.0.0upgrade guideupgrade guide

  • Replaces the Pydantic V1 __fields__ attribute.

    2.0.0upgrade guideupgrade guide

  • Replaces json_schema() as the model JSON schema method.

    2.0.0upgrade guideupgrade guide

  • Replaces update_forward_refs() as the model rebuilding method.

    2.0.0upgrade guideupgrade guide

  • Provides the JSON-loading behavior that previously came from parse_raw.

    2.0.0upgrade guideupgrade guide

  • Replaces parse_obj() for validating data.

    2.0.0upgrade guide

  • Replaces root_validator; under some circumstances it receives a model instance rather than a dictionary of values.

    2.0.0upgrade guide

  • Generated JSON schema no longer preserves namedtuples as namedtuples.

    2.0.0upgrade guide

  • An Optional-annotated field without a default is required but accepts None; Optional no longer implies a default of None.

    2.0.0upgrade guide

  • Optional annotations without a default are required but accept None; Any annotations no longer default to None.

    2.0.0upgrade guide

  • The parse_env_var classmethod has been removed; customize settings sources to provide a parsing function.

    2.0.0upgrade guideupgrade guide

  • Payment Card Numbers have moved to the separately installable Pydantic Extra Types package.

    2.0.0upgrade guide

  • Renamed from allow_population_by_field_name.

    2.0.0upgrade guideupgrade guide

  • Pydantic dataclass __post_init__ is now called after validation rather than before.

    2.0.0upgrade guideupgrade guide

  • This config setting has been removed.

    2.0.0upgrade guideupgrade guide

  • The method has been removed because it became redundant when __post_init__ moved after validation.

    2.0.0upgrade guideupgrade guide

  • Pydantic dataclasses no longer expose this attribute or use an underlying BaseModel; use TypeAdapter for related functionality.

    2.0.0upgrade guideupgrade guide

  • Replaces the Pydantic V1 __private_attributes__ attribute.

    2.0.0upgrade guideupgrade guide

  • Replaces the Pydantic V1 __validators__ attribute.

    2.0.0upgrade guideupgrade guide

  • String patterns use Rust's regex crate by default, which provides linear-time searching but does not support look arounds or backreferences; Python's regex library can be selected with regex_engine.

    2.0.0upgrade guide

  • Deprecated in favor of model_validator; even when retained, skip_on_failure=False is no longer supported.

    2.0.0upgrade guideupgrade guide

  • Replaces the __root__ field for defining a custom root model; RootModel types do not support arbitrary_types_allowed.

    2.0.0upgrade guide

  • Removed; the default union_mode in Pydantic V2 is 'smart'.

    2.0.0upgrade guideupgrade guide

  • Renamed from max_anystr_length.

    2.0.0upgrade guideupgrade guide

  • Renamed from min_anystr_length.

    2.0.0upgrade guideupgrade guide

  • Renamed from anystr_strip_whitespace.

    2.0.0upgrade guideupgrade guide

  • Renamed from anystr_lower.

    2.0.0upgrade guideupgrade guide

  • Renamed from anystr_upper.

    2.0.0upgrade guideupgrade guide

  • Nested model serialization includes only fields defined on the annotated field type, rather than all fields from a subclass instance.

    2.0.0upgrade guideupgrade guide

  • Wrap dataclasses with TypeAdapter to validate, generate JSON Schema, or access functionality previously provided through __pydantic_model__.

    2.0.0upgrade guide

  • A TypeError raised in a validator is no longer converted into a ValidationError, preventing programming errors from being reported as validation failures.

    2.0.0upgrade guideupgrade guide

  • Removed because Pydantic V2 behaves as though this setting were always True.

    2.0.0upgrade guideupgrade guide

  • Set union_mode='left_to_right' on Field to restore the non-short-circuiting left-to-right union behavior.

    2.0.0upgrade guideupgrade guide

  • URL validation appends a slash when a URL has no path, even if the input omitted the slash.

    2.0.0upgrade guideupgrade guide

  • The decorator formerly named @validate_arguments is now @validate_call; attributes such as raw_function and validate are not preserved.

    2.0.0upgrade guideupgrade guide

  • Renamed from validate_all and can be used to validate defaults, including as an alternative to validator always=True behavior.

    2.0.0upgrade guideupgrade guide

  • Deprecated in favor of field_validator; validator function signatures can no longer include field or config arguments.

    2.0.0upgrade guide

Deprecations 10

  • Invalid *after* model validator function signatures now emit a deprecation warning instead of raising an error.

    2.12.3release notes

  • The V1 pattern of defining a Config class in a BaseModel subclass is deprecated; use model_config instead.

    2.0.0upgrade guideupgrade guide

  • Replaces the deprecated validator decorator; validators for generic container items should annotate the type argument rather than use each_item.

    2.0.0upgrade guide

  • Deprecated; model_validate can provide similar behavior when from_attributes=True is set in the model config.

    2.0.0upgrade guideupgrade guide

  • Support for specifying json_encoders in model config is deprecated; serialization decorators are recommended for common custom serialization scenarios.

    2.0.0upgrade guideupgrade guide

  • The notes advise against isinstance checks against parametrized generics; subclass the parametrized generic if such checks are needed.

    2.0.0upgrade guideupgrade guide

  • Deprecated; load the data and pass it to model_validate.

    2.0.0upgrade guideupgrade guide

  • Deprecated; use model_validate_json for JSON input or load the data before passing it to model_validate.

    2.0.0upgrade guideupgrade guide

  • Calling result.usage() continues to work with a deprecation warning until V3; result.usage is a property.

    2.0.0upgrade guide

  • Deprecated in favor of field_validator; the each_item keyword is unavailable on field_validator, and validator signatures can no longer include field or config arguments.

    2.0.0upgrade guide

New APIs and options 18

  • Adds a method to convert FieldInfo to a dictionary.

    2.12.3release notes

  • Agent accepts an output_retries budget for output retries.

    2.0.0upgrade guide

  • Agent accepts retries as an integer or a mapping with output and tools keys; a bare integer sets both budgets.

    2.0.0upgrade guide

  • Agent specs accept output_retries and tool_retries.

    2.0.0upgrade guide

  • Agent accepts a tool_retries budget for tool retries.

    2.0.0upgrade guide

  • Adds a decorator for customizing serialization.

    2.0.0upgrade guideupgrade guide

  • Generic BaseModel subclasses can be declared by adding Generic as a parent class; mixing V1 and V2 models is not supported.

    2.0.0upgrade guide

  • Choose whether generated JSON schema represents validation inputs or serialization outputs.

    2.0.0upgrade guide

  • Specify model configuration with a class attribute dictionary; inherited configuration is merged across BaseModel parents, with later parents taking precedence for duplicate settings.

    2.0.0upgrade guideupgrade guide

  • Replaces parse_obj() for validating model input and can be used in place of from_orm when from_attributes=True.

    2.0.0upgrade guide

  • Introduced as the replacement for root_validator; under some circumstances it receives a model instance rather than a values dictionary.

    2.0.0upgrade guide

  • run(), run_sync(), run_stream(), iter(), and override() accept output_retries.

    2.0.0upgrade guide

  • The Pydantic V2 package continues to provide access to the Pydantic V1 API through the pydantic.v1 namespace.

    2.0.0upgrade guide

  • run(), run_sync(), run_stream(), iter(), and override() accept retries as a mapping with an output key.

    2.0.0upgrade guide

  • retries can be configured as an integer or as a mapping with output and tools keys.

    2.0.0upgrade guide

  • JSON schema generation methods accept schema_generator so callers can provide a custom GenerateJsonSchema subclass.

    2.0.0upgrade guideupgrade guide

  • Wrap dataclasses with TypeAdapter to validate, generate JSON schema, or access functionality previously requiring __pydantic_model__.

    2.0.0upgrade guide

  • Use typing.Annotated to add custom validation or provide custom core-schema and JSON-schema functions without modifying the type itself.

    2.0.0upgrade guide

Performance 3

  • Skips decorator field checks when no field decorators exist.

    2.14.2release notes

  • Avoids heap allocation for small JSON model field buffers.

    2.14.2release notes

  • Avoids Python tuple allocation during model fields validation.

    2.14.2release notes

Behavior and default changes 7

  • Explicit by_alias now overrides validate_by_alias in validation JSON schemas.

    2.14.2release notes

  • Named tuples are now supported in Sequence serialization.

    2.14.2release notes

  • The allow_reuse keyword argument is no longer necessary; repeated-function detection now errors only for redefinition within a single class.

    2.0.0upgrade guideupgrade guide

  • Generated JSON schema now targets draft 2020-12 by default, with some OpenAPI extensions.

    2.0.0upgrade guide

  • Subclassed models inherit model_config; settings from multiple BaseModel parents are merged, with the later parent's settings overriding duplicates.

    2.0.0upgrade guide

  • Constructor arguments may be copied during validation and coercion, which matters when passing mutable objects.

    2.0.0upgrade guide

  • Union validation preserves the input type when it matches a choice, even when that choice is not first in the union.

    2.0.0upgrade guide

Tooling 2

  • pydantic-core wheels are now published for PyPy 8.0 using the pp80 ABI, making installation available for that runtime.

    2.14.2release notes

  • A beta code transformation tool is available to help migrate project source files to Pydantic V2.

    2.0.0upgrade guide

Fixes and other changes 26

  • Fixes unpickling of generic classes defined in a separate module.

    2.14.2release notes

  • Fixes a crash on deferred empty models.

    2.14.2release notes

  • Calls repr of values lazily during nested union serialization.

    2.14.2release notes

  • Fixes forward annotation evaluation and type variable substitution when rebuilding parametrized generic models.

    2.14.2release notes

  • Fixes pickling of PydanticCustomError and ValidationError instances containing custom errors.

    2.14.2release notes

  • Prevents infinite recursion when validating an invalid default with PydanticUseDefault.

    2.14.2release notes

  • Fixes Self resolution in parametrized generics.

    2.14.2release notes

  • Fixes deep copy of self-referential models.

    2.14.2release notes

  • URL type equality now takes preserve_empty_path into account.

    2.14.2release notes

  • Adds a recursion guard to validate_strings().

    2.14.2release notes

  • Fix missing GC traversal on some struct fields and in GeneralFieldsSerializer.

    2.13.5release notes

  • Validated model fields are counted once in smart unions.

    2.13.5release notes

  • Validators can be reused when plugins are set.

    2.13.5release notes

  • Preserve RootModel core metadata.

    2.13.4release notes

  • Handle AttributeError subclasses when from_attributes is used.

    2.13.3release notes

  • Fixes ValidationInfo.field_name being missing when using model_validate_json().

    2.13.2release notes

  • Fixes ValidationInfo.data being missing when using model_validate_json().

    2.13.1release notes

  • Fixes a pickle error when using model_construct() on a model with MISSING as a default value.

    2.12.5release notes

  • Reverted URL credential percent-encoding in the build() method of AnyUrl and Dsn types.

    2.12.4release notes

  • Validation no longer gets default values from defaultdict, fixing a regression in its validation behavior.

    2.12.4release notes

  • Fields with exclude_if are excluded from JSON Schema required fields.

    2.12.4release notes

  • Fixed serialization of IP address types to JSON when serialize_as_any is used by adding type inference.

    2.12.4release notes

  • Fixed forward references in parent TypedDict classes on Python 3.14 and greater.

    2.12.4release notes

  • Fixed field serializers on nested typed dictionaries.

    2.12.4release notes

  • Mutations on FieldInfo classes reused as Annotated metadata are supported again, although this remains an unsupported pattern.

    2.12.3release notes

  • Generated JSON schema for Optional fields now indicates that null is allowed.

    2.0.0upgrade guideupgrade guide