Skip to content

Option to disable generation of --no-<flag> for implicit boolean flags #703

@Else00

Description

@Else00

With cli_implicit_flags=True, pydantic-settings always generates both --flag and --no-flag. For some CLIs this is noisy and undesirable; we’d like a way to expose only the positive form.

Current behavior
Boolean fields become implicit flags and the help shows --flag, --no-flag (mirrors argparse’s BooleanOptionalAction).

Desired behavior
Add an opt-in switch to disable the negated form, at least at model level, with a per-field override. For example:

  • SettingsConfigDict(cli_boolean_negation="both" | "positive_only", ...) (default: "both"), or
  • a field-level annotation like CliPositiveOnlyFlag[bool], or
  • a field kwarg e.g. Field(cli_negation=False).

Why

  • Cleaner help (-v | --version without --no-version).
  • Matches many established CLIs where only the positive form exists; reduces confusion and boilerplate in docs.
  • Backward compatible if default stays as today.

Alternatives considered
Integrating a custom root parser to replace BooleanOptionalAction with store_true only for certain flags. Works, but is a workaround and leaks argparse details into user code.

References

  • Docs: implicit boolean flags always generate --flag/--no-flag. (Pydantic)
  • Related discussion about boolean flag UX. (GitHub)

Environment
pydantic-settings 2.11.0
Python 3.13.8

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions