Skip to content

require-nodecode-for-splitting-settings-field

Warn when an unconditional raw-string splitter lacks a pydantic-settings decoding policy.

Why

pydantic-settings JSON-decodes complex environment fields before field validators run; a raw-string splitter without NoDecode can fail during process startup.

Fix

After confirming the intended environment format, annotate the field as Annotated[FieldType, NoDecode] or disable decoding for the settings class so the validator receives the raw string.

Examples

Before — flagged Raw splitter without NoDecode
app/settings.py
import os
from pydantic import field_validator
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
emails: list[str]
@field_validator("emails", mode="before")
@classmethod
def split_emails(cls, value):
return value.split(",")
os.environ["EMAILS"] = "one@example.com,two@example.com"
Settings()
After — preferred Raw splitter receives undecoded input
app/settings.py
import os
from typing import Annotated
from pydantic import field_validator
from pydantic_settings import BaseSettings, NoDecode
class Settings(BaseSettings):
emails: Annotated[list[str], NoDecode]
@field_validator("emails", mode="before")
@classmethod
def split_emails(cls, value):
return value.split(",")
os.environ["EMAILS"] = "one@example.com,two@example.com"
Settings()