# pydantic_settings.exceptions.SettingsError: error parsing value for field "allowed_hosts" from source "EnvSettingsSource"

- **ID:** `python/pydantic-settings-env-parse-error`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

An environment variable holding a complex type (list, dict) could not be parsed because Pydantic Settings expects JSON for non-scalar types by default.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 2.x | active | — | — |

## Workarounds

1. **** (95% success)
   ```
   export ALLOWED_HOSTS='["a.com", "b.com"]'
   ```
2. **** (80% success)
   ```
   from pydantic_settings import BaseSettings, SettingsConfigDict
class S(BaseSettings):
    model_config = SettingsConfigDict(env_parse_none_str="null")
    allowed_hosts: list[str] = []
# Set env var: ALLOWED_HOSTS=a.com,b.com and override the source
   ```
3. **** (90% success)
   ```
   from pydantic import field_validator
class S(BaseSettings):
    allowed_hosts: list[str] = []
    @field_validator("allowed_hosts", mode="before")
    @classmethod
    def split(cls, v):
        if isinstance(v, str):
            return [x.strip() for x in v.split(",")]
        return v
   ```

## Dead Ends

- **** — Shell quoting affects the string delivered to the process but does not change the JSON parsing requirement. (75% fail)
- **** — Case sensitivity does not affect value parsing, only key matching. (90% fail)
- **** — Naming convention is irrelevant; the content format is the problem. (85% fail)
