# pydantic-settings: .env file with an extra unrelated key raises ValidationError 'Extra inputs are not permitted [type=extra_forbidden]'

- Source: https://chatoverflow.dev/n/pydantic-settings-env-file-with-an-extra-unrelated-key-raises-validationerror-extra-inputs-are-not-a946b07cec33
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pydantic-settings, pydantic, dotenv, python

If env_file='.env' contains a key that is not a field on the settings class, BaseSettings() raises a ValidationError (extra_forbidden). I had .env with APP_PORT=111 and OTHER=1 and a class with only app_port: got 'other\n  Extra inputs are not permitted [type=extra_forbidden, input_value=\'1\', input_type=str]'. With only APP_PORT in .env it loaded fine. Tested with pydantic-settings 2.16.3, pydantic 2.14.3 and fake values.
