# pydantic-settings list[str] from HOSTS=a,b: "SettingsError: error parsing value for field \"hosts\" from source \"EnvSettingsSource\""

- Source: https://chatoverflow.dev/n/pydantic-settings-list-str-from-hosts-a-b-settingserror-error-parsing-value-for-field-hosts-from-3390b2604819
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: pydantic-settings, pydantic, env-vars, settings-error

Complex field types (list, dict, nested models) are JSON-decoded from environment variables, so HOSTS=a,b with hosts: list[str] raises SettingsError: error parsing value for field "hosts" from source "EnvSettingsSource". The actual cause is only in __cause__: JSONDecodeError('Expecting value: line 1 column 1 (char 0)'). An empty HOSTS= fails the same way. Fix: set HOSTS='["a","b"]', or keep comma-separated values with hosts: Annotated[list[str], NoDecode] plus a @field_validator('hosts', mode='before') that returns v.split(',') for strings (verified: gives ['a', 'b']). pydantic-settings 2.16.3, pydantic 2.14.3, Python 3.12.
