{"record":{"id":"3256d246f8ca33a8","repo":"pydantic/pydantic","slug":"greater-than-equal","errorCode":"greater_than_equal","errorMessage":"greater_than_equal","messagePattern":"greater_than_equal","errorType":"validation","errorClass":"PydanticKnownError","httpStatus":null,"severity":"error","filePath":"pydantic/_internal/_validators.py","lineNumber":276,"sourceCode":"    \"\"\"\n    if isinstance(v, (int, float, str)):\n        return v\n    return repr(v)\n\n\ndef greater_than_validator(x: Any, gt: Any) -> Any:\n    try:\n        if not (x > gt):\n            raise PydanticKnownError('greater_than', {'gt': _safe_repr(gt)})\n        return x\n    except TypeError:\n        raise TypeError(f\"Unable to apply constraint 'gt' to supplied value {x}\")\n\n\ndef greater_than_or_equal_validator(x: Any, ge: Any) -> Any:\n    try:\n        if not (x >= ge):\n            raise PydanticKnownError('greater_than_equal', {'ge': _safe_repr(ge)})\n        return x\n    except TypeError:\n        raise TypeError(f\"Unable to apply constraint 'ge' to supplied value {x}\")\n\n\ndef less_than_validator(x: Any, lt: Any) -> Any:\n    try:\n        if not (x < lt):\n            raise PydanticKnownError('less_than', {'lt': _safe_repr(lt)})\n        return x\n    except TypeError:\n        raise TypeError(f\"Unable to apply constraint 'lt' to supplied value {x}\")\n\n\ndef less_than_or_equal_validator(x: Any, le: Any) -> Any:\n    try:\n        if not (x <= le):\n            raise PydanticKnownError('less_than_equal', {'le': _safe_repr(le)})","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/pydantic/pydantic/blob/cc13d1b8c978eaf78ed5308329cd41f03ecc3144/pydantic/_internal/_validators.py#L258-L294","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Send a value `>= ge` — fix the upstream data (the most common fix).","If `ge` itself is wrong, lower or remove the bound in the `Field(...)`/`Annotated[..., Field(ge=...)]` declaration.","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.","Add a `@field_validator` that coerces or rejects before the constraint runs, if business rules need pre-processing."],"exampleFix":"// before\nfrom pydantic import BaseModel, Field\n\nclass M(BaseModel):\n    age: int = Field(ge=18)\n\nM(age=15)  # -> greater_than_equal\n\n// after (data fix)\nM(age=18)\n\n// or: relax the bound\nage: int = Field(ge=13)","handlingStrategy":"validation","validationCode":"def ensure_ge(value, bound):\n    if value < bound:\n        raise ValueError(f'{value!r} must be >= {bound!r}')\n    return value\n\n# before calling the model:\nensure_ge(payload_age, 18)","typeGuard":"def meets_ge(value, bound) -> bool:\n    try:\n        return value >= bound\n    except TypeError:\n        return False","tryCatchPattern":"from pydantic import ValidationError\n\ntry:\n    M(age=value)\nexcept ValidationError as e:\n    if any(err['type'] == 'greater_than_equal' for err in e.errors()):\n        # handle the specific ge violation\n        ...\n    raise","preventionTips":["Validate boundary inputs at the API edge before constructing the model.","Use Field(ge=...) consistently for lower bounds; reserve gt for strict positivity.","Document the boundary in the field's description= so callers know the contract.","Write a unit test that exercises both the bound value (valid) and bound-1 (invalid)."],"tags":["pydantic","validation","constraints","numeric"],"backgroundTag":null,"analyzedSha":"cc13d1b8c978eaf78ed5308329cd41f03ecc3144","analyzedAt":"2026-08-11T16:38:52.905Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}