Validators

didactic.api.validates

validates(
    *field_names: str, mode: str = "after"
) -> Callable[
    [Callable[..., FieldValue]], Callable[..., FieldValue]
]

Mark a class method as a Python-side validator for one or more fields.

PARAMETER DESCRIPTION
*field_names

Names of the fields this validator applies to. At least one is required.

TYPE: str DEFAULT: ()

mode

Either "before" (run before type validation, may convert) or "after" (run after, receives the typed value).

TYPE: str DEFAULT: 'after'

RETURNS DESCRIPTION
Callable

A decorator that tags the wrapped method for the metaclass to register on the field spec.

Notes

Validators are deliberately not lifted into the Theory; for cross-language constraints, use __axioms__ or Annotated[T, ...] metadata instead.

Examples:

>>> import didactic.api as dx
>>> class User(dx.Model):
...     email: str
...
...     @dx.validates("email")
...     @classmethod
...     def _email_lower(cls, v: str) -> str:
...         return v.lower()

didactic.api.ValidationError dataclass

ValidationError(
    entries: tuple[ValidationErrorEntry, ...],
    model: type | None = None,
)

Bases: Exception

One or more validation failures, surfaced as a single exception.

didactic collects all failures during construction or mutation and raises them together (no fail-fast). This mirrors Pydantic's behaviour so users who grep "for the list of errors" find one.

PARAMETER DESCRIPTION
entries

The individual failures.

TYPE: tuple[ValidationErrorEntry, ...]

model

The model class that failed validation. None when the failure precedes class identification (e.g. discriminated-union dispatch).

TYPE: type | None DEFAULT: None

See Also

ValidationErrorEntry : the per-issue record.

didactic.api.ValidationErrorEntry dataclass

ValidationErrorEntry(
    loc: tuple[str | int, ...],
    type: str,
    msg: str,
    axiom: str | None = None,
    vertex_id: str | None = None,
)

A single validation failure.

PARAMETER DESCRIPTION
loc

Path through the schema where the failure was detected, e.g. ("orders", 2, "shipping_address", "postal_code"). Empty tuple means "the model itself".

TYPE: tuple[str | int, ...]

type

Error category. One of "type_error", "axiom_violation", "missing_required", "extra_field", "converter_error", "validator_error", or a panproto-side identifier.

TYPE: str

msg

Human-readable description.

TYPE: str

axiom

The panproto-Expr term that failed, when applicable. None for non-axiom failures.

TYPE: str | None DEFAULT: None

vertex_id

The schema vertex id where the violation lives, when known.

TYPE: str | None DEFAULT: None