Skip to content
@pyreon/validate
fundamentals · schema validation

Write it like Zod. It won all 12 cells of our workload bench.

s is a schema library with the chain you already know, compiled to one flat function on first parse. The same schema runs light in the browser and strict on the server, and Zod, Valibot or ArkType schemas plug into every Pyreon package that takes one.

bun add @pyreon/validate
Documentation
workload bench
12 of 12 cells fastestvs Zod, Valibot, ArkType; one run.
results
parse() never throws{ ok, value } or { ok, issues }; parseOrThrow() when you want one.
also accepts
Zod, Valibot, ArkTypeAny Standard Schema, in forms, stores and state trees.
mini entry
5.2 KB gz for a 4-field schemaNext release, author-measured; 13.8 KB through the main entry.
One failing check, reported with its path, code and key Schema: const User = s.object({ email: s.string().email(), age: s.number().int().min(18) }). User.safeParse runs on { email: 'ada@pyreon.dev', age: 17 }: the email check and the integer check pass, min(18) fails, and the result is ok: false with one issue at path age with code too_small, key validate.number.too-small and message 'Must be at least 18'. With age 18 the same call returns ok: true. @PYREON/VALIDATE · S const User = s.object({ email: s.string().email(), age: s.number().int().min(18), }) ✓ ✗ ✓ compiles to one function on first parse User.safeParse({ email: 'ada@pyreon.dev', age: 17 }) age: 18 }) result … ok: false issues[0] path: ['age'] code: 'too_small' key: 'validate. number.too-small' message: 'Must be at least 18' ok: true value: typed as User each issue: code, i18n key, params · formatErrorsByPath(issues, t)
  • 12 / 12 cells won on a multi-schema workload against Zod, Valibot and ArkType.BENCHMARKS.md §9 'Validate — multi-schema megamorphic workload', final pass 2026-11-05, one run
  • 18 / 24 cells won or tied in a 10-library bench, including every invalid-input parse.BENCHMARKS.md §9 'Validate — 10-library protocol bench', final pass, one run
  • 1.40× faster than Zod rejecting a bad string: the closest of the twelve cells (34.9 vs 48.7 ns).BENCHMARKS.md §9 megamorphic, invalid scalar string, one run

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

Why it is worth a new import.

  1. Fast where forms and APIs live

    Each schema compiles to one monomorphic function the first time it parses. Rejecting bad input, which every form and endpoint does all day, is where it is strongest: in the 10-library bench it never loses an invalid-input parse.

  2. Light in the browser, strict on the server

    Import @pyreon/validate/server on the server and every .email() and .phone() upgrades to strict RFC 5322 and full E.164, with a disposable-domain blocklist. None of that code reaches the client bundle.

  3. Checks that need your database

    .serverCheck('email-unique') passes in the browser and is listed in r.pending so the UI can say "checking". On the server, parseAsync runs the check you registered. One schema, no second copy.

  4. Errors ready to translate

    Every issue carries a code, an i18n key like validate.string.email and its params. formatErrorsByPath(issues, t) turns them into one message per field, in any language.

the difference

One schema for both sides, and the browser knows what it skipped.

Zod, a database check

A second schema for the server, so the DB call stays out of the bundle. The two drift, and the client never learns a check is pending.

// shared/signup.ts
import { z } from 'zod'

const Signup = z.object({
  email: z.email(),
  password: z.string().min(10),
})

// server/signup.ts: a second schema, so the DB call never reaches the bundle
const ServerSignup = Signup.superRefine(async (v, ctx) => {
  if (await db.users.exists(v.email)) {
    ctx.addIssue({ code: 'custom', path: ['email'], message: 'Email already taken' })
  }
})
// ...and the browser has no idea a server check exists
with @pyreon/validate

The check is part of the shared schema. The browser records it as pending; the server runs it, plus strict email rules.

// shared/signup.ts: imported by the browser and the server
import { s } from '@pyreon/validate'

export const Signup = s.object({
  email: s.string().email().serverCheck('email-unique', { message: 'Email already taken' }),
  password: s.string().min(10),
})

// client/signup.ts: cheap checks run, the server check is recorded as pending
import { Signup } from '../shared/signup'

const r = Signup.parse({ email: 'ada@example.com', password: 'correct horse' })
// r.ok === true, r.pending → [{ path: ['email'], key: 'email-unique' }]

// server/signup.ts: strict RFC 5322 email, disposable-domain blocklist, the DB check
import { registerServerCheck } from '@pyreon/validate/server'
import { Signup } from '../shared/signup'

registerServerCheck('email-unique', async (email) => !(await db.users.exists(email as string)))

async function handleSignup(body: unknown) {
  const verdict = await Signup.parseAsync(body)
  return verdict.ok ? { ok: true } : { ok: false, issues: verdict.issues }
}
which package do I need?

One product, two packages.

Validation ships as two npm packages with similar names. Most apps install only the first.

install this

@pyreon/validate

The validator you write schemas with: s.object, s.string().email() and the rest. Plus helpers for labels, translated errors and live validation that also work on Zod, Valibot and ArkType schemas.

bun add @pyreon/validate
@pyreon/validation
comes with forms and stores

The plumbing. Forms, Store and State-tree use it to accept any schema, and it's installed with them. You only import it yourself for its typed Zod, Valibot or ArkType adapters.

coming from

Coming from Zod or Valibot?

Rename z to s, read ok instead of success.

Zod
import { z } from 'zod'

const User = z.object({
  name: z.string().min(1),
  email: z.email(),
  age: z.number().int().min(18).optional(),
})
type User = z.infer<typeof User>

const r = User.safeParse(input)
if (r.success) save(r.data)
else show(r.error.issues)
Pyreon

The chain is the same for the common cases. Or keep Zod: Pyreon's form, store and state-tree accept a Zod schema as it is.

import { s, type Infer } from '@pyreon/validate'

const User = s.object({
  name: s.string().min(1),
  email: s.string().email(),
  age: s.number().int().min(18).optional(),
})
type User = Infer<typeof User>

const r = User.parse(input) // never throws
if (r.ok) save(r.value)
else show(r.issues)

Same functional style, same tree-shaking, from /mini.

Valibot
import * as v from 'valibot'

const User = v.object({
  name: v.pipe(v.string(), v.minLength(1)),
  email: v.pipe(v.string(), v.email()),
  age: v.optional(v.pipe(v.number(), v.integer(), v.minValue(18))),
})
type User = v.InferOutput<typeof User>

const r = v.safeParse(User, input)
if (r.success) save(r.output)
else show(r.issues)
Pyreon

From the next release @pyreon/validate/mini ships without the runtime JIT; call enableJit() from @pyreon/validate/jit once if you want its speed back.

import { email, integer, minLength, minValue, number, object, optional, pipe, string, type Infer } from '@pyreon/validate/mini'

const User = object({
  name: pipe(string(), minLength(1)),
  email: pipe(string(), email()),
  age: optional(pipe(number(), integer(), minValue(18))),
})
type User = Infer<typeof User>

const r = User.parse(input)
if (r.ok) save(r.value)
else show(r.issues)
try it

One schema, validated twice.

Type an email and validate. The browser runs the light format check and lists email-unique as pending; the server pass runs the strict email rules, the disposable-domain blocklist and the uniqueness check. Try ada@example.com (taken) and test@mailinator.com (disposable).

Try ada@example.com (taken), test@mailinator.com (disposable), or your own

  • browser · format—
  • browser · email-unique—
  • server · strict format—
  • server · email-unique—

The server half runs in a Web Worker in this page, with its own copy of @pyreon/validate/server. The round-trip delay and the user table are simulated.

benchmarks

Fastest in all 12 cells of the multi-schema workload.

The workload bench runs many schemas through one call site, the way a real app does. In the 10-library protocol bench, Zod's compiled mode, ArkType and typia take six cells, all on valid input or email; they are in the table.

vs Zod 4 (interpreted and compiled), Valibot, ArkType, typia, TypeBox, Yup and Joi · bun (JavaScriptCore)Pyreonrival · lower is better
  • multi-schema workload, 12 cells
    winfastest in 12 of 12 vs Zod, Valibot, ArkType
  • invalid scalar string (closest cell)
    34.9 ns
    44.7 ns
    win1.28× vs Valibot · 1.40× vs Zod (CI margin 0.1 ns)
  • protocol bench, 24 cells
    splitwins or ties 18, including every invalid-input parse
  • parse email, valid
    29 ns
    24 ns
    lossZod compiled mode ahead
  • parse int, valid
    5 ns
    3 ns
    lossZod compiled mode ahead
  • parse array of 20, valid
    119 ns
    107 ns
    lossZod compiled mode ahead
  • parse user object, valid
    43 ns
    35 ns
    lossArkType ahead (returns the input, no clone)
  • check email, valid
    27 ns
    21 ns
    losstypia 21 · ArkType 22
  • check email, invalid
    22 ns
    19 ns
    lossArkType ahead
  • adapter tax, @pyreon/validation
    loss−24 to +436 ns over raw Zod / Valibot / ArkType (overnight run)
Apple M3 Max · record of 2026-11-05 · final pass, one run · author-run, syntheticFull method, every loss →
what's included

What is in the box.

  • The full chain strings, numbers, bigints, dates, literals, enums, objects, arrays, tuples, records, maps, sets, unions, discriminated unions, intersections, lazy recursion.
  • String formats email, url, uuid, ulid, nanoid, cuid, jwt, ip, cidr, phone, creditCard, emoji, iso.date, iso.dateTime, iso.time, duration.
  • Object algebra .pick, .omit, .partial, .required, .extend, .merge, .keyof, .catchall, .strict.
  • Refine and transform .refine, .superRefine, .transform, .pipe, s.preprocess, s.coerce; async members work inside every composition via parseAsync.
  • Resilient parsing .catch(fallback) for bad fields, .readonly() for frozen output.
  • .is() for a boolean a verdict-only compiled path that builds no output and no issues.
  • JSON Schema out toJsonSchema() emits draft 2020-12 for OpenAPI, editor autocomplete or an LLM's structured output.
  • Strict CSP configure({ jit: false }) runs the interpreter with identical results when unsafe-eval is off.
  • Labels on any schema withField(z.string().email(), { label, placeholder }) attaches metadata to Zod, Valibot, ArkType or s schemas.
  • Shared native schemasnext release A declared s.object({...}) compiles to a native struct on iOS and Android, and its parse returns the same { ok, value, issues } there. Experimental.
recipes

Things to build with it.

Error messages in German, from the issue keys

Every built-in issue has an i18n key and params, so translation is a lookup, not a regex over English text.

import { formatErrorsByPath, s } from '@pyreon/validate'

// every built-in issue carries an i18n key and params
const messages: Record<string, string> = {
  'validate.string.too-short': 'Mindestens {min} Zeichen',
  'validate.string.email': 'Ungültige E-Mail-Adresse',
}
const t = (key: string, params?: Record<string, unknown>) =>
  (messages[key] ?? key).replace(/\{(\w+)\}/g, (_, k: string) => String(params?.[k] ?? ''))

const Signup = s.object({ name: s.string().min(2), email: s.string().email() })

const r = Signup.parse({ name: 'A', email: 'nope' })
if (!r.ok) console.log(formatErrorsByPath(r.issues, t))
// { name: 'Mindestens 2 Zeichen', email: 'Ungültige E-Mail-Adresse' }
A schema an LLM or an OpenAPI spec can read

Emit JSON Schema from the same object you validate with, then check what comes back.

import { s } from '@pyreon/validate'
import { toJsonSchema } from '@pyreon/validate/json-schema'

const Ticket = s.object({
  title: s.string().min(3).describe('One-line summary'),
  priority: s.enum(['low', 'normal', 'urgent']),
  tags: s.array(s.string()).max(5).optional(),
})

// draft 2020-12, ready for an OpenAPI spec or an LLM's structured output
console.log(JSON.stringify(toJsonSchema(Ticket), null, 2))

// ...and the same schema checks what comes back
const reply = Ticket.parse(JSON.parse('{"title":"Login loops","priority":"urgent"}'))
console.log(reply.ok) // true
Validate a signal as it changes

parseReactive gives a computed result for templates; watchValid calls you only when validity flips.

import { signal } from '@pyreon/reactivity'
import { parseReactive, s, watchValid } from '@pyreon/validate'

const Coupon = s.string().regex(/^[A-Z]{4}-\d{4}$/, { message: 'Looks like ABCD-1234' })
const code = signal('')

// a Computed result for templates...
const result = parseReactive(Coupon, code)
// ...and a callback that fires only when validity flips
const stop = watchValid(Coupon, code, (valid) => console.log('valid:', valid)) // valid: false

code.set('SAVE-2026') // valid: true
code.set('save') // valid: false
console.log(result().issues?.[0]?.message) // 'Looks like ABCD-1234'
stop()
api

One namespace for schemas, a few helpers for the rest.

Every export has a reference page with its signature, an example and the mistakes people make with it.

schemas · s · 16
  • s.string
  • s.number
  • s.boolean
  • s.date
  • s.enum
  • s.literal
  • s.object
  • s.array
  • s.tuple
  • s.record
  • s.union
  • s.discriminatedUnion
  • s.lazy
  • s.coerce
  • s.preprocess
  • s.custom
on every schema · 10
  • parse
  • safeParse
  • parseOrThrow
  • parseAsync
  • is
  • optional
  • refine
  • transform
  • catch
  • serverCheck
helpers · 9
  • withField
  • getMeta
  • parseReactive
  • parseReactiveAsync
  • watchValid
  • formatErrors
  • formatErrorsByPath
  • configure
  • installFormatValidator
server · @pyreon/validate/server · 5
  • registerServerCheck
  • strictEmail
  • strictPhone
  • isDisposableEmail
  • addDisposableDomains
JSON Schema · @pyreon/validate/json-schema · 1
  • toJsonSchema
subpaths · 1
  • @pyreon/validate/mini
next release · @pyreon/validate/jit · 1
  • enableJit
adapters · @pyreon/validation · 5
  • zodSchema
  • valibotSchema
  • arktypeSchema
  • isStandardSchema
  • standardSchemaToValidator
good to know

Good to know before you start.

The result shape is { ok }, not { success }

parse() and its alias safeParse() return { ok, value } or { ok, issues } and never throw. Use parseOrThrow() where an exception reads better.

Strict CSP: one line skips the JIT

The JIT uses new Function. Under a CSP without unsafe-eval it falls back to the interpreter after one blocked attempt; call configure({ jit: false }) at startup to skip that attempt. Results are identical, only slower.

The chain does not tree-shake

Chain methods live on prototypes. For the smallest bundle import from @pyreon/validate/mini, or let pyreon({ optimizeValidators: true }) rewrite module-level schemas for you.

A browser ok is not the final word

.serverCheck always passes in the browser and shows up in pending. Treat the server's parseAsync as the verdict.

questions

What people ask first.

Where does it lose, and why?

Six of 24 protocol cells: Zod's compiled mode parses a valid email, int and 20-item array faster; ArkType parses a valid user object faster because it hands back your input instead of a clean copy; typia and ArkType check emails faster. On email the grammars also differ: ArkType accepts a..b@x.com and a@-x.com, which Zod, Valibot and s reject.

Are those numbers independent?

No. We wrote the bench, it is synthetic, and the validate rows are one run on one machine. Every library is checked for identical results before timing. Run it yourself: cd packages/fundamentals/validate && bun bench/validation.ts.

@pyreon/validate or @pyreon/validation?

Install @pyreon/validate: it is the s schema library plus helpers. @pyreon/validation is the small adapter layer (zodSchema, valibotSchema, arktypeSchema, the Standard Schema bridge) that forms, stores and state trees use to accept any validator. It comes with them.

Do I have to switch from Zod?

No. withField, parseReactive, formatErrors and every Pyreon package that takes a schema work with a Zod, Valibot or ArkType schema directly. Switch when the speed or the server split is worth it to you.

What about async rules?

.refine and .transform can be async anywhere in the tree; call parseAsync. A sync parse() of an async schema returns one issue telling you to use parseAsync, instead of a wrong answer.

Keep the chain. Lose the second schema.

bun add @pyreon/validate
Read the validation guide