pydantic/pydantic · error · PydanticKnownError

greater_than_equal

greater_than_equal

Error message

greater_than_equal

What it means

A `PydanticKnownError('greater_than_equal', {'ge': ...})` raised by `greater_than_or_equal_validator` when the validated value is comparable but is strictly less than the `ge` bound. Pydantic maps this code to a localized `ValidationError` of type `greater_than_equal` so the rendered message reads 'Input should be greater than or equal to {ge}'. It is the normal, expected failure path for a violated `ge` constraint.

Source

Thrown at pydantic/_internal/_validators.py:276

    """
    if isinstance(v, (int, float, str)):
        return v
    return repr(v)


def greater_than_validator(x: Any, gt: Any) -> Any:
    try:
        if not (x > gt):
            raise PydanticKnownError('greater_than', {'gt': _safe_repr(gt)})
        return x
    except TypeError:
        raise TypeError(f"Unable to apply constraint 'gt' to supplied value {x}")


def greater_than_or_equal_validator(x: Any, ge: Any) -> Any:
    try:
        if not (x >= ge):
            raise PydanticKnownError('greater_than_equal', {'ge': _safe_repr(ge)})
        return x
    except TypeError:
        raise TypeError(f"Unable to apply constraint 'ge' to supplied value {x}")


def less_than_validator(x: Any, lt: Any) -> Any:
    try:
        if not (x < lt):
            raise PydanticKnownError('less_than', {'lt': _safe_repr(lt)})
        return x
    except TypeError:
        raise TypeError(f"Unable to apply constraint 'lt' to supplied value {x}")


def less_than_or_equal_validator(x: Any, le: Any) -> Any:
    try:
        if not (x <= le):
            raise PydanticKnownError('less_than_equal', {'le': _safe_repr(le)})

View on GitHub (pinned to cc13d1b8c9)

Solutions

  1. Send a value `>= ge` — fix the upstream data (the most common fix).
  2. If `ge` itself is wrong, lower or remove the bound in the `Field(...)`/`Annotated[..., Field(ge=...)]` declaration.
  3. If the boundary should be inclusive of an empty/zero state, switch to a `Union` (e.g. `Union[Literal[0], Annotated[int, Field(ge=100)]])` so the zero case bypasses the constraint.
  4. Add a `@field_validator` that coerces or rejects before the constraint runs, if business rules need pre-processing.

Example fix

// before
from pydantic import BaseModel, Field

class M(BaseModel):
    age: int = Field(ge=18)

M(age=15)  # -> greater_than_equal

// after (data fix)
M(age=18)

// or: relax the bound
age: int = Field(ge=13)
Defensive patterns

Strategy: validation

Validate before calling

def ensure_ge(value, bound):
    if value < bound:
        raise ValueError(f'{value!r} must be >= {bound!r}')
    return value

# before calling the model:
ensure_ge(payload_age, 18)

Type guard

def meets_ge(value, bound) -> bool:
    try:
        return value >= bound
    except TypeError:
        return False

Try / catch

from pydantic import ValidationError

try:
    M(age=value)
except ValidationError as e:
    if any(err['type'] == 'greater_than_equal' for err in e.errors()):
        # handle the specific ge violation
        ...
    raise

Prevention

When it happens

Trigger: A field declared `Annotated[int, Field(ge=N)]` (or `conint(ge=N)`) receives a value strictly less than N — e.g. `Field(ge=0)` with input `-1`, or `Field(ge=datetime(...))` with an earlier timestamp. Any scalar field (int, float, Decimal, date, datetime, timedelta) with a `ge` bound.

Common situations: Off-by-one in price/quantity fields (`ge=1` receiving `0`); passing a default `0` for a field that requires `ge=1`; timezone- or epoch-based datetime fields where the supplied timestamp predates the floor; Decimal currency fields receiving a negative amount.

Related errors


AI-assisted analysis of pydantic/pydantic@cc13d1b8c9 (2026-08-11). Data as JSON: /api/errors/3256d246f8ca33a8. Report an issue: GitHub.