Valibot
Type-safe schema validation library for TypeScript with a modular API and minimal bundle footprint.
Official Documentation ↗v1. Check the official docs for the latest API surface.Installation
npm install valibotpnpm add valibotMethods
No methods match this filter.
Type-safe schema validation library for TypeScript with a modular API and minimal bundle footprint.
Overview
Valibot describes data shapes as schemas and validates unknown input against them, then infers the TypeScript output type automatically. Schemas compose: objects hold field schemas, pipe chains actions, and picklist, optional, nullable, and recursive structures build on the same primitives.
Its functional style means small composable functions, which tree-shake well for browser bundles. safeParse returns structured issues for every failure, making it a natural boundary validator for forms and HTTP handlers.
Core Methods
The most frequently used entry points, with signatures and runnable examples:
v.object— Defines an object schema whose field schemas describe each property of the input.v.parse— Validates and returns the typed output, throwing ValiError with structured issues on failure.v.safeParse— Returns a discriminated result object instead of throwing, for API boundary handling.v.pipe— Chains validation and transformation actions in order; each step sees the previous output.
Usage Notes
- Infer types from schemas instead of declaring interfaces twice.
- Use safeParse at API boundaries and parse where throwing is convenient.
- Compose reusable actions with pipe rather than one-off custom validators.
Common Pitfalls
- Importing valibot as
import valibot from "valibot"pulls the whole namespace; preferimport * as vwith named usage for tree-shaking. - Optional fields still validate when present; use nullish only when undefined and null are both acceptable.
- Issue paths are key objects, stringify them explicitly for client-facing messages.
FAQ
- How does Valibot compare to Zod?
- Both offer schema validation with inferred types. Valibot emphasizes a modular design where unused parts tree-shake aggressively, which can cut bundle size for client and edge targets; API ergonomics are similar enough that migration is mostly mechanical.
- What do issues look like?
- Each issue carries a path of keys to the failing field, a message, and the kind of failure. safeParse returns all issues at once, so error responses can render every problem instead of only the first.
- Can I transform data during validation?
- Yes: pipe chains transformations, trim, toLowerCase, custom map functions, with validations, and the inferred output type reflects the transformed shape, not just the raw input.
Report a problem with this API docOpens a pre-filled issue on GitHub.