Skip to content

Schemas and validation

Use a Schema to describe and validate data arriving at an HTTP route, a Realtime method or an MCP tool. Declare Python field types, attach structural bounds such as minimum length and add application rules such as email or password confirmation. A successful validation returns an instance whose fields you can use; invalid input produces errors keyed by field.

Schemas use msgspec.Struct internally. Field aliases typing.Annotated; Orionis compiles its constraints and rule plans when the class is declared.

The package separates declaration from validation. Direct construction trusts already typed Python values under msgspec constructor semantics. orionis.schemas.validator.Schema.validate() and validateAsync() convert untrusted payloads and raise an Orionis ValidationException containing field-indexed failures.

  • Python 3.14 or newer; schema compilation relies on deferred annotation evaluation.
  • Explicit imports from fields, constraints, metadata, rules, validator, and exceptions for advanced features; the package root deliberately exports only Schema.
  • A booted database connection for Unique, and network/file context for rules that perform those checks.
  1. Declare schemas and convert data.
  2. Handle validation errors.
  3. Add application rules.
  4. Look up constraints and metadata.

Continue with HTTP, database or MCP.