Installation
Install both the Valibot adapter and Valibot itself:Valibot requires version
^1.0.0, ^1.0.0-beta.5, or ^1.0.0-rcBasic Usage
Import thevalibotValidator function and pass it a Valibot schema:
Why Valibot?
Valibot is designed to be:- Lightweight - Smaller bundle size than Zod (~1.5kb min+gzip for basic usage)
- Modular - Tree-shakeable, only bundle what you use
- Fast - Optimized for runtime performance
- Type-safe - Excellent TypeScript inference
Advanced Validation
Valibot provides comprehensive validation capabilities:String Validation
Number Validation
Date Handling
Arrays and Complex Types
Default Values
Use Valibot’soptional() with a default parameter:
Fallback Values
Handle validation errors gracefully withfallback():
Transformations
Valibot makes it easy to transform validated data:Type Safety
Valibot provides full type inference:Custom Validation
Create custom validators with Valibot’s pipe system:Error Handling
When validation fails, Valibot throws aValiError:
Real-World Example
Here’s a complete example with pagination, filtering, and sorting:Bundle Size Comparison
Valibot’s modular design means you only bundle what you use:API Reference
valibotValidator(schema)
Creates a validator adapter from a Valibot schema.
Parameters:
schema- A ValibotGenericSchema
- A
ValidatorAdapterthat can be used withvalidateSearch
- Input type: Inferred from
InferInput<TSchema> - Output type: Inferred from
InferOutput<TSchema>
Migration from Zod
If you’re switching from Zod, here are the key differences:Next Steps
Zod Adapter
Full-featured validation with Zod
ArkType Adapter
TypeScript-like validation syntax