serhii.net

In the middle of the desert you can say anything you want

14 Feb 2026

Passing complex CLI params to Pydantic settings

Settings Management - Pydantic Validation is nice but doesn’t cover everything.

Passing None through CLI

 it will default to “null” if cli_avoid_json is False, and “None” if cli_avoid_json is True .

Fun fact, works inside complex nested JSON flags as well.

Passing complex JSON-like fields incl. tuples

# Assume this
class MySettingsClass(BaseSettings):
    I_am_a_list_of_tuples: list[tuple[str, str, str | None]] = Field(
        default=FILE_PAIRS, validation_alias=AliasChoices("fp", "file_pairs")
    )
	
FILE_PAIRS = [
    (
        "infer_doc_simplecriteria/pred_doc_simplecriteria.json",
        "merge_gold_simplecriteria/gold_simplecriteria.json",
    ),
    (
        "file2-1",
        "file2-2",
    ),
]
# Passing as a list of lists parses as a tuple
# if done wrong the tuple is parsed as a list of strings
uv run thing --I-am-a-list-of-tuples \
'"merge_gold_simplecriteria/gold_simplecriteria.json",  "infer_doc_simplecriteria/pred_doc_simplecriteria.json"'
Nel mezzo del deserto posso dire tutto quello che voglio.
comments powered by Disqus