Validation with Valibot
Valibot is a modular, tree-shakeable schema library that ships as a collection of small functions instead of a chained builder. It implements Standard Schema, so DaloyJS picks it up the same way it picks up Zod — no adapter, no wrapper, no extra deps.
Valibot is developed in the open at github.com/open-circle/valibot and published to npm as valibot— that's the package you install below.
Install
Why Valibot
- Bundle size. You import only the validators you actually use, which matters on edge runtimes and in browser-shipped contracts.
- Functional API.
v.pipe(v.string(), v.email())instead ofz.string().email(). Easier to compose, easier to lint. - Standard Schema native.Same handler types and the same problem+json error shape you get with Zod — DaloyJS doesn't care which one you picked.
A complete route
body in the handler is inferred from CreateOrder — including the optional notes field. Returning anything that doesn't match Order is a TypeScript error, not a runtime surprise.
Params, query, and headers
Path params and query strings arrive as strings. Drop a v.transform (or one of the built-in v.toNumber/v.toBoolean/v.toDate actions) into the pipe to convert before further validation:
Discriminated unions
Use v.variant for tagged unions. DaloyJS emits a proper discriminator in the OpenAPI document so generated clients get narrowing for free.
Reusing types
v.InferOutput mirrors Zod's z.infer. Use v.InferInput when you have transforms and need the pre-parse shape (for example, in a form library).
Errors
Validation failures produce the same response as every other validator in DaloyJS: 422 Unprocessable Entity as RFC 9457 problem+json, with each issue's path and message. You don't need to write an error handler — that's the framework's job.
OpenAPI
Valibot schemas are converted into JSON Schema by DaloyJS's OpenAPI generator the same way Zod schemas are. Run the CLI and your spec is in sync with the route definitions:
Mixing validators
Nothing stops you from using Valibot for one route and Zod for another in the same app — both speak Standard Schema. Useful when migrating a codebase incrementally, or when a shared package already exports its schemas in one library and you don't want to rewrite them.
See also
- Validation overview — how validators plug in via Standard Schema.
- Validation with Zod — the chainable alternative.
- OpenAPI generation — how schemas become a spec.
- Errors & problem+json — the error contract.