pypi / pydantic-settings
pydantic-settings
What changed in pydantic-settings 2, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
22 breaking2 security1 deprecations28 new APIs and options14 behavior and defaults75 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initpydantic-settings 2142 changes
Breaking changes 22
Loading stops with a SettingsError after 10,000 entries.
Secret files that resolve outside secrets_dir are skipped with a warning, preventing links in the directory from making the application load arbitrary readable files.
An explicit secrets_dir on the wrapper now takes precedence over the wrapped source's directory and model config, including when the explicit value is an empty list.
With case_sensitive=False, only registered CLI options are lowercased; arguments after -- and CliUnknownArgs values keep their case.
Each CliUnknownArgs field now receives only leftover arguments from its own subcommand.
An empty JSON array now parses as an empty list instead of [''].
JSON config files are read as UTF-8 by default instead of the locale encoding; this option still overrides it.
With this enabled, a discriminated union default is dropped only when the incoming value selects a different union member.
Python 3.10 is no longer supported; pydantic-settings now requires Python 3.11+.
When false, aliases are ignored in every source; environment variables, secrets, CLI flags and defaults use only field names.
Takes precedence over alias when the two differ, so JSON/YAML/TOML file and CLI values load instead of being silently ignored.
YAML config files are read as UTF-8 by default instead of the locale encoding; this option still overrides it.
The setting now applies to init kwargs and JSON/TOML/YAML config-file sources; because it defaults to False, matching is case-insensitive for these sources. Nested keys remain case-sensitive.
Non-JSON environment values for strict fields now raise
ValidationErrorinstead of a less specific error.Inaccessible secrets now return None.
Python 3.9 is no longer supported.
Environment variables are coerced even when strict is True.
Importing common removed names, or checking them with hasattr() or getattr(), raises an ImportError naming the replacement and linking the migration page; code supporting V1 and V2 should detect the version with try/except ImportError.
The parse_env_var classmethod has been removed; customize settings sources to provide a custom parsing function.
The provider moved from pydantic_ai.providers.google to pydantic_ai.providers.google_gla.
The provider moved from pydantic_ai.providers.google_cloud to pydantic_ai.providers.google_vertex.
BaseSettings moved from pydantic to pydantic-settings; import it from pydantic_settings.
Security 2
With
case_sensitive=True, the GCP source skips thelist_secretscall, lowering the required IAM permissions toroles/secretmanager.secretAccessor.The source no longer follows symlinks that point outside
secrets_dir.
Deprecations 1
Calling result.usage() still works but emits a deprecation warning until V3; result.usage is a property.
New APIs and options 28
Adds an extra for installing the AWS Systems Manager Parameter Store source.
Adds an AWS Systems Manager Parameter Store source that recursively reads parameters under an ssm_path, mapping / onto nested models.
Adds named variadic CLI options that accept multiple values after one option as well as repeated options; required fields need at least one value.
Returns a process-local singleton per settings class; calling the class directly still builds a fresh instance.
Clears the cache used for process-local cached settings instances.
Enables environment variable names to appear in generated CLI help, making
--helpoutput useful as configuration documentation.Set this environment variable to a truthy value with
DEBUGlogging enabled to inspect source contributions, value precedence, and env-file or secret-file resolution.Lets you root settings at a nested table in any TOML file, rather than only in
pyproject.toml.JSON, TOML, and YAML file sources accept
Traversableresources, allowing packaged configuration files, including files in zip or wheel distributions, to be loaded without casting toPath.Allows customizing the dotenv setting source to filter variables.
Allows overriding the default help on the CLI internal parser.
Adds support for CLI serialization styles.
Adds CliDualFlag for defining dual CLI flags.
Adds CliToggleFlag for defining toggle-style CLI flags.
Adds the env_prefix_target setting.
Adds format_help method support for the CLI.
Adds the SecretVersion annotation for per-field GCP secret versioning.
AWS Secrets Manager sources support the VersionId parameter for selecting a secret version.
Adds the NestedSecretsSettings source.
Agent accepts output_retries=N to set the output retry budget.
Agent accepts retries as a mapping with output and tools budgets; a bare integer sets both budgets.
Agent specs accept output_retries and tool_retries, and retries as an integer or a mapping with output and tools keys.
Agent accepts tool_retries=N to set the tool retry budget.
Sources can now receive case_sensitive as an argument.
Sources can now receive env_prefix as an argument.
Pydantic Json fields are now supported.
run(), run_sync(), run_stream(), iter(), and override() accept output_retries=N.
run(), run_sync(), run_stream(), iter(), and override() accept retries={'output': N}.
Behavior and default changes 14
Fields with unresolved forward references now emit this warning, which tells you to call
model_rebuild(); warning-as-error configurations may turn it into a failure.The GCP settings source can obtain
project_idfrom an earlier settings source, rather than only from the constructor orGOOGLE_CLOUD_PROJECT.Supports reading .env files from FIFOs, including those used by 1Password Environments.
The CLI coerces numeric types.
Union discriminator choices are shown in CLI help.
The CLI help message no longer includes the default value for CliToggleFlag.
Config file sources support deep merging, allowing nested configuration values from multiple sources to be combined.
File sources accept non-Path files, such as Traversable objects, and open files using Path.open.
yaml_config_section supports nested paths.
Enum values support kebab case.
Non-explicit default values are stripped.
Settings sources follow the order init > env > dotenv > secrets > defaults.
SettingsConfigDict is now public, so developers can import and use it directly.
Source class initialization parameters now have default values, allowing initialization without supplying every parameter.
Fixes and other changes 75
Serialization keeps each level's CliUnknownArgs before that level's subcommand token, so parsing the output again no longer moves a parent's unknown args onto the subcommand.
Hidden entries (names starting with
.) are skipped again, restoring the behavior from before 2.14.2.With secrets_nested_subdir=True, directories reached through a second symlink are loaded again, fixing lost nested secrets in layouts such as Kubernetes secret volumes.
Symlink loops inside secrets_dir are skipped instead of aborting the load with RuntimeError on Python 3.11 and 3.12.
CliApp.run now rebuilds AliasPath inputs for BaseModel and pydantic dataclass commands, respects AliasChoices priority, and leaves unsupplied path defaults to the model.
A stdlib dataclass default on a discriminated union field no longer raises NameError when another dataclass field has a string annotation naming a local class.
Dictionary values typed as unions now JSON-decode nested environment values; only arrays and objects are decoded, and decoding follows enable_decoding and the field's NoDecode/ForceDecode.
Inner discriminated unions declared with Annotated and Field(discriminator=...) are now detected; when an incoming tag selects another member, default fields are no longer merged into it.
Fixed-length tuple positionals and NamedTuples are single-valued again; variable-length tuples remain variadic.
A field typed as an alias of a list of dicts accepts a JSON list again instead of merging its objects into one dict.
A bare single-segment AliasPath no longer tries to JSON-decode plain string values.
Resolving a named Annotated type alias no longer mutates shared FieldInfo metadata, avoiding validators running twice on subclasses or after model_rebuild().
Case-insensitive matching now works for nested pydantic dataclasses.
Tuples, frozenset, MutableSequence and other collection subtypes, including named collection type aliases, are treated as repeatable or variadic options.
cli_exit_on_error=False is now honored by CliSubCommand parsers, which raise SettingsError instead of exiting.
No longer crashes when cli_prefix is set in model_config.
Serialized output now round-trips through CliApp.run for enums, tuples, dates, Decimal values, explicit None, empty containers, CliVariadicArg values, and populated CliUnknownArgs fields.
Serialization now preserves explicit None values.
Serialization now preserves empty containers.
Serialization now handles populated CliUnknownArgs fields without raising IndexError.
Serialized CLI output now parses for enums, tuples, dates and Decimal values.
Serialization now preserves CliVariadicArg values.
Aliases keep their case when case_sensitive=False.
Set, MutableSet and AbstractSet fields now JSON-decode environment values.
dash_to_underscore=True now works for nested Azure Key Vault model fields.
DotenvFiltering is now exported from pydantic_settings.sources.types.
A bare typing.Dict field no longer raises IndexError when env_nested_delimiter is set.
Azure Key Vault and GCP Secret Manager now honor env_parse_none_str.
With extra='allow', a non-lowercase env_prefix is now stripped from dotenv extras.
An empty JSON config file is treated as an empty mapping instead of crashing.
Named union type aliases now decode like inline equivalents in environment and dotenv sources, including under Optional, Annotated and custom validation aliases.
The source now validates its specific constructor arguments.
Adds support for pydantic 2.14, including fixes for CliApp.run and validate_by_alias=False handling.
Adds support for Python 3.15.
secrets_case_sensitive=True is now honored on Windows.
An explicit empty tuple overrides the model config to read the TOML file root.
Home-directory paths are expanded when checking whether the TOML table-header file exists.
Environment values for nested model fields using
AliasPathare now JSON-decoded.Environment variables now load on Windows when
case_sensitive=True, despiteos.environkeys being upper-cased.Dotenv extras are no longer wrongly claimed by a complex field that shares their name prefix.
Enum names now parse through nested annotations such as
Optional[Annotated[MyEnum, ...]]when enum parsing is enabled.Case-insensitive field matching now works for optional nested models.
Secret subclasses no longer crash when loaded from the environment.
Secret files are now read as UTF-8 rather than using the platform locale encoding, avoiding corruption of non-ASCII secrets on some Windows code pages.
This package is no longer required at runtime.
An empty section now falls back to defaults instead of raising an
AttributeError.Fixes conflicts between a field named cls and a classmethod parameter.
Fixes AliasChoices being ignored when provider priority changes.
Fixes a RecursionError when CLI handles mutually recursive models.
Preserves CLI descriptions under python -OO by falling back to json_schema_extra.
Fixes cli_ignore_unknown_args=True not working on subcommands.
Fixes
env_filefrommodel_configbeing ignored when running CliApp.Fixes a crash for CliPositionalArg[list[CustomType]].
Fixes parsing environment variables into Optional Strict types.
Fixes coercion of Literal[numeric Enum] values for CLI and environment variables.
Ensures environment and CLI providers discover nested discriminated unions.
Resolves a KeyError for underscore field names in run_subcommand.
Fixes CLI recognition of field names when validate_by_name and AliasChoices are used.
Fixes a regression affecting bool fields introduced in 2.13.0.
Fixes a RecursionError with self-referential models in CliApp.
Fixes an AttributeError when nested environment variables are used with dict fields.
Fixes JSON decoding for parameterized PEP 695 type aliases.
Fixes CLI parsing errors for set field types introduced in 2.13.0.
Allows snake_case_conversion to be used with env_prefix for the Azure Key Vault source.
Fixes handling of duplicate enum field values in the CLI.
Fixes handling of CliImplicitFlag[bool] when cli_kebab_case="all".
Fixes loading nested configuration from environment variables.
Fixes handling of external list arguments in the CLI.
Fixes case-insensitive retrieval in the Google Secret Manager settings source.
Restoring init kwargs now uses a deterministic order.
Avoids conflicts with the NAME environment variable in WSL.
Type aliases are unpacked when looking for NoDecode, so the annotation is recognized through aliases.
Only overrides preferred_key when no value was found.
Init kwarg names are restored before the final state dictionary is returned.
Adds support for Python 3.14.