Skip to main content
Individual guards call .parse() and fail on the first error. Schemas walk the entire structure and collect all errors with full path tracking.

Defining schemas

defineSchemas({ Name: guard })

Pass a map of names to guards. You can use any guard directly, or pass a plain object of guards (auto-wrapped as an object schema).

defineSchema(name, guard)

Creates a single named schema. Useful when you only need one.

Parsing and asserting

schema.parse(data)Result<T, GuardErr[]>

Validates data and returns Ok(T) on success or Err(GuardErr[]) containing every validation failure.

schema.assert(data)T

Returns the validated value or throws AggregateGuardError with all collected errors.

schema.is(data)boolean

Boolean type predicate — delegates to the underlying guard.

Type inference

InferSchema<typeof schemas.Name>

Extracts the validated output type from a schema.

typeof schemas.Name.$infer

Alternative syntax that avoids importing InferSchema.

GuardErr

Each error in a Result<T, GuardErr[]> or AggregateGuardError.errors has this shape:

AggregateGuardError

Thrown by schema.assert() when validation fails.

formatErrors and flattenErrors

Standalone utilities for formatting GuardErr[] arrays outside of AggregateGuardError.
The schema name prefix is stripped from all paths. Root-level errors (no nested path) use the key '_root'.

Complete example