Available Validators
Drizzle supports four popular validation libraries:Zod
The most popular TypeScript-first schema validation library
Valibot
Modular and lightweight validation library
TypeBox
JSON Schema Type Builder with static type inference
ArkType
TypeScript-native runtime validation with 1:1 type/validator syntax
Zod
Installation
Basic Usage
Customizing Schemas
Override Field Validation
Refine Fields
Refine fields before they become optional/nullable:Pick Specific Fields
API Validation Example
Features
- Create select schemas for tables, views, and enums
- Create insert and update schemas for tables
- Full type inference from Drizzle schemas
- Supports all PostgreSQL, MySQL, and SQLite dialects
- Refine and customize generated schemas
Valibot
Installation
Basic Usage
Customizing Schemas
Refining Fields
TypeBox
Installation
Basic Usage
Customizing Schemas
Refining Fields
ArkType
Installation
Basic Usage
Customizing Schemas
Refining Fields
Comparison
- Bundle Size
- Performance
- Developer Experience
| Library | Minified | Gzipped |
|---|---|---|
| Valibot | Smallest | ~5 KB |
| ArkType | Small | ~12 KB |
| TypeBox | Medium | ~15 KB |
| Zod | Larger | ~14 KB |
Common Patterns
Multi-step Form Validation
API Request/Response Validation
Partial Updates
Nested Relations Validation
Framework Integration
Next.js Server Actions
app/actions.ts
tRPC Integration
server/routers/users.ts
Hono Validation
Best Practices
Generate once, reuse everywhere
Create validation schemas once and export them for use across your application:
schemas/users.ts
Next Steps
Drizzle Seed
Generate test data that validates against your schemas
API Development
Build type-safe APIs with Drizzle and validation