# Data flow — pydantic/pydantic-settings

> Canonical page: https://codevetter.com/unpack/pydantic-settings/data-flow

# Data flow — pydantic/pydantic-settings

Scanned commit 5927b441848c330853eac74c82358bc283cd3640 (2026-10-02). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Inputs become dictionaries before final Pydantic validation. Constructor inputs and field aliases are normalized so source values can merge under compatible keys. Environment-shaped providers share decoding and nested expansion, whereas structured files parse into mappings first. The pipeline retains intermediate source dictionaries for dependent sources and optional diagnostics, then produces a validated model.
- _settings_init_sources resolves explicit constructor controls against model_config, with ENV_FILE_SENTINEL preserving the distinction between omitted dotenv configuration and an explicit None. — [pydantic_settings/main.py#L388-L415](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/main.py#L388-L415) [pydantic_settings/sources/types.py#L47-L50](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/types.py#L47-L50)
- InitSettingsSource matches constructor keys using configured case rules and alias preference, writes matched values under canonical preferred aliases, removes duplicate matches, and retains unmatched extras. — [pydantic_settings/sources/base.py#L323-L372](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/base.py#L323-L372)
- EnvSettingsSource snapshots os.environ during initialization; parse_env_vars normalizes names, optionally drops empty strings, and marks configured null strings with EnvNoneType. — [pydantic_settings/sources/providers/env.py#L75-L94](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/providers/env.py#L75-L94) [pydantic_settings/sources/utils.py#L60-L78](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/utils.py#L60-L78)
- Field acquisition searches extracted environment names in order; preparation decodes complex values and deep-merges delimiter-expanded nested values over a decoded top-level mapping. — [pydantic_settings/sources/providers/env.py#L109-L158](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/providers/env.py#L109-L158) [pydantic_settings/sources/providers/env.py#L285-L302](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/providers/env.py#L285-L302)
- Structured file sources call ConfigFileSourceMixin._read_files, skip non-files, merge later file mappings over earlier ones shallowly or deeply, then feed the result through InitSettingsSource. — [pydantic_settings/sources/base.py#L215-L235](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/base.py#L215-L235) [pydantic_settings/sources/providers/json.py#L36-L55](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/providers/json.py#L36-L55) [pydantic_settings/sources/providers/toml.py#L61-L78](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/providers/toml.py#L61-L78)
- CLI parsing produces a namespace or dictionary, resolves repeated values and selected subcommands, marks unselected subcommands as null, and converts the result into env_vars for inherited environment-style preparation. — [pydantic_settings/sources/providers/cli.py#L559-L575](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/providers/cli.py#L559-L575) [pydantic_settings/sources/providers/cli.py#L602-L620](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/providers/cli.py#L602-L620) [pydantic_settings/sources/providers/cli.py#L638-L668](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/providers/cli.py#L638-L668)
- Before each source call, _settings_build_values supplies current_state and settings_sources_data; it records the source result and applies deep_update(source_state, state), giving previously merged sources priority. — [pydantic_settings/main.py#L556-L572](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/main.py#L556-L572) [pydantic_settings/sources/base.py#L118-L144](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/sources/base.py#L118-L144)
- After merging, unchanged default-source values are removed, optional debug output is emitted, original constructor key names are restored, and BaseModel.__init__ validates the resulting mapping. — [pydantic_settings/main.py#L574-L585](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/main.py#L574-L585) [pydantic_settings/main.py#L618-L649](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/main.py#L618-L649) [pydantic_settings/main.py#L286-L286](https://github.com/pydantic/pydantic-settings/blob/5927b441848c330853eac74c82358bc283cd3640/pydantic_settings/main.py#L286-L286)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
