Seals (Validation) — Aquilia Documentation
Comprehensive guide and documentation for Seals (Validation) in the Aquilia framework. View API reference, examples, and implementation patterns.
Docs / Contracts / Seals & Validation Seals & Validation Sealing is validation. The is_sealed() method runs type checks, constraint enforcement, and custom @ward validators. Validation Pipeline , , , , , ].map(p => ( ))} Execution # Instantiate with request body bp = ProductContract(data=await ctx.json()) # Run validations if not bp.is_sealed(): return Response.json(bp.errors, status=422) # Persist product = await bp.imprint() Pass raise_fault=True to raise a SealFault instead of returning False. The fault carries the same field errors on .field_errors, so a fault handler can render them without re-running validation. Cross-Field Validation Use the @ward decorator to enforce dependencies between multiple fields. A ward receives the validated data as its second argument, so every field it reads has already been cast and constraint-checked: from aquilia.contracts import Contract, ward from aquilia.contracts.facets import DateFacet class EventContract(Contract): start_date = DateFacet() end_date = DateFacet() @ward def dates_ordered(self, data): """Ensure end_date is strictly after start_date.""" if data["end_date"] Accumulating Errors self.reject(field, message) records an error and lets the remaining wards run, so a form reports every problem at once rather than one per round trip: Set Spec.fail_fast = True to stop at the first ward error instead — useful for pipelines where a later rule's output would be noise once an earlier one has failed. See Validation Control. Nested Contracts A nested Contract runs its full pipeline, not just its field checks. Its wards and its validate() hook enforce rules exactly as they do at the top level, and errors are reported at the failing field's path: class LineItem(Contract): qty = IntFacet() @ward def qty_positive(self, data): if data["qty"] Changed in v1.3.5. Before this release a nested Contract was validated structurally only, so its wards and validate() override never ran. Payloads that previously passed may now be rejected — correctly. See the release notes. Async Validation A ward that needs to await — a uniqueness check, a remote lookup — declares mode="async" and is run by is_sealed_async(): Before v1.3.5 this produced a "This field is required" error per field — a misdiagnosis that sent developers hunting the wrong bug. Clients that parse a 422 body should render __all__ separately from field errors. Facets Projections )
Go to Homepage