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 initpydantic-core 2156 changes
Breaking changes 90
Attribute docstrings are no longer extracted from nested classes and functions.
For TypedDict and dataclasses with extra=allow, extra data matching a field name is ignored.
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.
The mapping max_length constraint is now checked during validation.
The config setting has been removed; use
frozenequivalently with the inverse of its current use.With a validator using
always=True, standard validators for the annotated type are also applied to defaults.Fields annotated as Any no longer default to None and are required unless an explicit default is provided.
Url and Dsn types no longer inherit from str; convert them with str(url) when using APIs that expect a string.
Coercing int, float, and Decimal values to strings is optional and disabled by default.
Color Types have moved to the separately installable Pydantic Extra Types package.
Arguments passed to model constructors may be copied during validation and coercion, which matters when passing mutable objects.
This config setting has been removed.
A parent type's config is no longer applied to vanilla dataclass fields; use the
configparameter on the@dataclassdecorator to override config.Pydantic dataclasses no longer support extra='allow'; extra='ignore' remains supported but does not store extra fields.
Dataclasses used as fields no longer accept tuples as validation inputs; use dictionaries instead.
Decimal is represented as a string in generated JSON schema and serialization.
This config setting has been removed.
Arbitrary keyword arguments are no longer added to JSON schema; pass extra schema data through json_schema_extra instead.
Use
frozeninstead ofallow_mutation.The
constproperty has been removed.Constraints are no longer automatically pushed down to generic parameters; use typing.Annotated to annotate the parameter type.
Use the typing.Final type hint instead.
Use the
typing.Finaltype hint instead of thefinalproperty.Use
max_lengthinstead ofmax_items.Use
min_lengthinstead ofmin_items.Use
patterninstead ofregex.The
unique_itemsproperty has been removed.Introduced as the replacement for validator, with new features; annotate generic container item types to validate their contents.
Validator functions no longer receive the config argument; access configuration through info.config instead.
The new decorator does not accept the
each_itemkeyword argument; annotate the container's type argument to validate its items.Validator functions no longer receive the field argument; use info.field_name to look up the field in cls.model_fields.
Returns None when no alias is set, rather than returning the field name.
This config setting has been removed; use Annotated on fields to modify them.
Float values convert to integers only when their decimal part is zero, avoiding loss of fractional data.
Renamed from orm_mode.
Generic BaseModel subclasses can be created directly by adding Generic as a parent class.
Removed; generic BaseModel subclasses can now inherit from Generic directly.
Custom types should use __get_pydantic_core_schema__ in place of __get_validators__.
Custom JSON schema hooks use __get_pydantic_json_schema__ in place of __modify_schema__.
Removed because orm_mode and its implementation detail are no longer supported.
Removed along with orm_mode; it was an implementation detail of that feature.
Renamed from keep_untouched.
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.
Iterables of pairs, including empty iterables, are no longer coerced to dictionaries during validation.
This config setting has been removed.
Non-string JSON key values are generally serialized using
str(key), changing outputs such as the serialization of a None key.This config setting has been removed.
Generated JSON schema now targets draft 2020-12 by default, with some OpenAPI extensions.
Renamed from schema_extra; also used to pass extra JSON schema data to Field.
Replaces construct() as the model construction method.
Replaces copy() as the model copying method.
Replaces dict() as the method for dumping model data.
Replaces json() for JSON serialization; output is compacted and may not exactly match json.dumps() output.
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.
Replaces the Pydantic V1
__fields__attribute.Replaces json_schema() as the model JSON schema method.
Replaces update_forward_refs() as the model rebuilding method.
Provides the JSON-loading behavior that previously came from parse_raw.
Replaces
parse_obj()for validating data.Replaces
root_validator; under some circumstances it receives a model instance rather than a dictionary of values.Generated JSON schema no longer preserves namedtuples as namedtuples.
An Optional-annotated field without a default is required but accepts None; Optional no longer implies a default of None.
Optional annotations without a default are required but accept None; Any annotations no longer default to None.
The parse_env_var classmethod has been removed; customize settings sources to provide a parsing function.
Payment Card Numbers have moved to the separately installable Pydantic Extra Types package.
Renamed from allow_population_by_field_name.
Pydantic dataclass __post_init__ is now called after validation rather than before.
This config setting has been removed.
The method has been removed because it became redundant when
__post_init__moved after validation.Pydantic dataclasses no longer expose this attribute or use an underlying BaseModel; use TypeAdapter for related functionality.
Replaces the Pydantic V1
__private_attributes__attribute.Replaces the Pydantic V1
__validators__attribute.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.
Deprecated in favor of model_validator; even when retained, skip_on_failure=False is no longer supported.
Replaces the __root__ field for defining a custom root model; RootModel types do not support arbitrary_types_allowed.
Removed; the default union_mode in Pydantic V2 is 'smart'.
Renamed from max_anystr_length.
Renamed from min_anystr_length.
Renamed from anystr_strip_whitespace.
Renamed from anystr_lower.
Renamed from anystr_upper.
Nested model serialization includes only fields defined on the annotated field type, rather than all fields from a subclass instance.
Wrap dataclasses with TypeAdapter to validate, generate JSON Schema, or access functionality previously provided through
__pydantic_model__.A TypeError raised in a validator is no longer converted into a ValidationError, preventing programming errors from being reported as validation failures.
Removed because Pydantic V2 behaves as though this setting were always True.
Set union_mode='left_to_right' on Field to restore the non-short-circuiting left-to-right union behavior.
URL validation appends a slash when a URL has no path, even if the input omitted the slash.
The decorator formerly named @validate_arguments is now @validate_call; attributes such as raw_function and validate are not preserved.
Renamed from validate_all and can be used to validate defaults, including as an alternative to validator always=True behavior.
Deprecated in favor of
field_validator; validator function signatures can no longer includefieldorconfigarguments.
Deprecations 10
Invalid *after* model validator function signatures now emit a deprecation warning instead of raising an error.
The V1 pattern of defining a Config class in a BaseModel subclass is deprecated; use model_config instead.
Replaces the deprecated
validatordecorator; validators for generic container items should annotate the type argument rather than useeach_item.Deprecated; model_validate can provide similar behavior when from_attributes=True is set in the model config.
Support for specifying json_encoders in model config is deprecated; serialization decorators are recommended for common custom serialization scenarios.
The notes advise against isinstance checks against parametrized generics; subclass the parametrized generic if such checks are needed.
Deprecated; load the data and pass it to model_validate.
Deprecated; use model_validate_json for JSON input or load the data before passing it to model_validate.
Calling result.usage() continues to work with a deprecation warning until V3; result.usage is a property.
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.
New APIs and options 18
Adds a method to convert FieldInfo to a dictionary.
Agent accepts an output_retries budget for output retries.
Agent accepts retries as an integer or a mapping with output and tools keys; a bare integer sets both budgets.
Agent specs accept output_retries and tool_retries.
Agent accepts a tool_retries budget for tool retries.
Adds a decorator for customizing serialization.
Generic BaseModel subclasses can be declared by adding Generic as a parent class; mixing V1 and V2 models is not supported.
Choose whether generated JSON schema represents validation inputs or serialization outputs.
Specify model configuration with a class attribute dictionary; inherited configuration is merged across BaseModel parents, with later parents taking precedence for duplicate settings.
Replaces parse_obj() for validating model input and can be used in place of from_orm when from_attributes=True.
Introduced as the replacement for root_validator; under some circumstances it receives a model instance rather than a values dictionary.
run(), run_sync(), run_stream(), iter(), and override() accept output_retries.
The Pydantic V2 package continues to provide access to the Pydantic V1 API through the pydantic.v1 namespace.
run(), run_sync(), run_stream(), iter(), and override() accept retries as a mapping with an output key.
retries can be configured as an integer or as a mapping with output and tools keys.
JSON schema generation methods accept schema_generator so callers can provide a custom GenerateJsonSchema subclass.
Wrap dataclasses with TypeAdapter to validate, generate JSON schema, or access functionality previously requiring __pydantic_model__.
Use typing.Annotated to add custom validation or provide custom core-schema and JSON-schema functions without modifying the type itself.
Performance 3
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.
Behavior and default changes 7
Explicit by_alias now overrides validate_by_alias in validation JSON schemas.
Named tuples are now supported in Sequence serialization.
The allow_reuse keyword argument is no longer necessary; repeated-function detection now errors only for redefinition within a single class.
Generated JSON schema now targets draft 2020-12 by default, with some OpenAPI extensions.
Subclassed models inherit model_config; settings from multiple BaseModel parents are merged, with the later parent's settings overriding duplicates.
Constructor arguments may be copied during validation and coercion, which matters when passing mutable objects.
Union validation preserves the input type when it matches a choice, even when that choice is not first in the union.
Tooling 2
pydantic-core wheels are now published for PyPy 8.0 using the pp80 ABI, making installation available for that runtime.
A beta code transformation tool is available to help migrate project source files to Pydantic V2.
Fixes and other changes 26
Fixes unpickling of generic classes defined in a separate module.
Fixes a 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 with PydanticUseDefault.
Fixes Self resolution in parametrized generics.
Fixes deep copy of self-referential models.
URL type equality now takes preserve_empty_path into account.
Adds a recursion guard to validate_strings().
Fix missing GC traversal on some struct fields and in GeneralFieldsSerializer.
Validated model fields are counted once in smart unions.
Validators can be reused when plugins are set.
Preserve RootModel core metadata.
Handle AttributeError subclasses when from_attributes is used.
Fixes
ValidationInfo.field_namebeing missing when usingmodel_validate_json().Fixes
ValidationInfo.databeing missing when usingmodel_validate_json().Fixes a pickle error when using model_construct() on a model with MISSING as a default value.
Reverted URL credential percent-encoding in the
build()method ofAnyUrlandDsntypes.Validation no longer gets default values from
defaultdict, fixing a regression in its validation behavior.Fields with
exclude_ifare excluded from JSON Schema required fields.Fixed serialization of IP address types to JSON when
serialize_as_anyis used by adding type inference.Fixed forward references in parent TypedDict classes on Python 3.14 and greater.
Fixed field serializers on nested typed dictionaries.
Mutations on FieldInfo classes reused as Annotated metadata are supported again, although this remains an unsupported pattern.
Generated JSON schema for Optional fields now indicates that null is allowed.