Omnist logo Omnist Tutorial Step 7 of 15

Validation

Check whether a Document conforms to a Schema, and read the real diagnostics.

schema.validate(doc) returns a ValidationResult with .ok and .errors — validation ignores edge order entirely, since a schema describes a set of possible documents, not a sequence.

from omnist import parse_schema, doc

s = parse_schema('record R { "items" [1,]: integer }\nroot R')
r = s.validate(doc({"items": []}))
r.ok
print(r)
Output
ok: False
invalid:
  at $: field 'items' occurs 0 time(s), expected at least 1

Each Error carries a .path, a human-readable .message, and a stable, machine-readable .code (here, validate.cardinality) — the code is what you'd branch on in real code; the message is for a human reading logs.

Learn more