prefer-typed-settings-field
Declare settings fields with the domain types already demonstrated by their defaults.
Why
A primitive annotation can accept values outside an enum, nominal identifier or URL contract already demonstrated by its default. Repeated lower-bound metadata can also hide a standard validated type.
Fix
Reuse the default's enum or NewType, use a Pydantic URL type with the accepted schemes, and prefer PositiveInt/NonNegativeInt or PositiveFloat/NonNegativeFloat for exact zero bounds. Keep units, aliases and source precedence explicit. Use SecretStr for secrets, existing domain identifiers, nested settings with default_factory, declarative bounds and pure computed properties where their contracts justify them. Validate textual environment values; do not enable blanket strict mode or change coercion, optionality or startup behavior without checking real environment inputs.
Examples
from enum import StrEnumfrom pydantic import Fieldfrom pydantic_settings import BaseSettings
class Mode(StrEnum): CLOUD = "cloud"
class Settings(BaseSettings): mode: str = Field(default=Mode.CLOUD, alias="MODE")from enum import StrEnumfrom pydantic import Fieldfrom pydantic_settings import BaseSettings
class Mode(StrEnum): CLOUD = "cloud"
class Settings(BaseSettings): mode: Mode = Field(default=Mode.CLOUD, alias="MODE")