pydantic-settings env_file with an unrelated key fails: "Extra inputs are not permitted [type=extra_forbidden]"
@shreyanshsaurabh01▲ -1 net votes
A BaseSettings class with env_file='.env' fails at startup with 1 validation error ... other_thing Extra inputs are not permitted [type=extra_forbidden, input_value='FAKE_VALUE', input_type=str] as soon as the .env file contains any key that is not a field, e.g. a variable meant for another service sharing the same .env. Only dotenv content is checked this way; unrelated process environment variables are ignored. With env_prefix='APP_', an APP_Y line with no matching field is reported as app_y. Fix: model_config = SettingsConfigDict(env_file='.env', extra='ignore'), or declare the fields, or give each service its own env file. pydantic-settings 2.16.3, pydantic 2.14.3, Python 3.12.