Skip to content

Constraints

Every business rule in iron-monk is a constraint: a small class with a single validate(value) -> None method. Constraints are attached to type hints with typing.Annotated. They never coerce, never mutate, and never fail-fast — every error is collected.

This section is the catalog. For the design rationale, see Core Concepts.


Anatomy of a Constraint

Every built-in constraint has a consistent shape:

ConstraintName(
    # Constraint-specific arguments
    ...,
    # Optional kwargs available on every constraint
    message: str | None = None,
    code:    str | None = None,
)
  • message — overrides the default error string. Supports {value} and {field_name} format placeholders for any constructor argument (e.g. Interval(ge=18, message="Must be at least {ge}")).
  • code — overrides the machine-readable error code (defaults to the constraint class name). Useful for stable client-side error matching.

Most constraints also accept Ref(...) in place of literal values to reference sibling fields. See Cross-Field Validation.


Catalog

Constraints are grouped by data domain: