Skip to content
Discussion options

You must be logged in to vote

Hey @stdedos! The doc example uses 1,2,3 because pydantic_settings splits by comma by default. When you have only one value like A_IDS=1228, you need to wrap it in brackets so it parses as a list.

The cleanest way is to change your .env to:

export A_IDS="[1228]"

This makes pydantic_settings treat it as a JSON array with one element. The response above with "[123]" is on the right track.

But if you really need to keep the format as A_IDS=1228 without brackets, you can use a field validator:

from pydantic import BaseModel, field_validator
from pydantic_settings import BaseSettings

class Settings(BaseSettings):
    a_ids: list[int]
    
    @field_validator('a_ids', mode='before')
    @clas…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@stdedos
Comment options

Answer selected by stdedos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants