Skip to main content
The Valibot adapter enables type-safe search parameter validation using Valibot, a lightweight, modular validation library with excellent TypeScript support.

Installation

Install both the Valibot adapter and Valibot itself:
Valibot requires version ^1.0.0, ^1.0.0-beta.5, or ^1.0.0-rc

Basic Usage

Import the valibotValidator function and pass it a Valibot schema:
Now your search parameters are validated and typed:

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
This makes it ideal for applications where bundle size matters.

Advanced Validation

Valibot provides comprehensive validation capabilities:

String Validation

Number Validation

Date Handling

Arrays and Complex Types

Default Values

Use Valibot’s optional() with a default parameter:

Fallback Values

Handle validation errors gracefully with fallback():
If parsing fails, the fallback value is used instead of throwing an error.

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 a ValiError:

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:
For complex validations, the difference is smaller, but Valibot remains lighter.

API Reference

valibotValidator(schema)

Creates a validator adapter from a Valibot schema. Parameters:
  • schema - A Valibot GenericSchema
Returns:
  • A ValidatorAdapter that can be used with validateSearch
Type Inference:
  • 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