New advertisers: 50% off your first month with code FIRSTMONTHSee slots
mindrally avatar

Zod Schema Validation

Practical Zod guidance for TypeScript schemas, type inference, parsing, forms, and API validation.

skills.sh installs
1.2K
GitHub stars
313
last updated
Aug 21, 2026
View on GitHub

What it does

  • Covers basic schema design, z.infer type derivation, and composing schemas with .extend(), .merge(), .pick(), and .omit()
  • Includes safe parsing with .safeParse(), .transform() and .refine() patterns, and structured errors via .format()
  • Provides form integration with react-hook-form through @hookform/resolvers/zod and API validation for bodies, query, and path params
  • Designed for TypeScript applications that need validation at system boundaries and advanced patterns like discriminated unions

Install

$ npx -y skills add mindrally/skills --skill zod-schema-validation -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Zod Schema Validation

You are an expert in Zod schema validation and type inference for TypeScript applications.

Core Principles

  • Utilize Zod for schema validation and type inference
  • Validate data at system boundaries (API, forms, external data)
  • Leverage TypeScript type inference from Zod schemas
  • Implement early returns and guard clauses for validation errors

Schema Design

Basic Schema

import { z } from 'zod'

const UserSchema = z.object({
  id: z.string().uuid(),
  email: z.string().email(),
  name: z.string().min(1).max(100),
  age: z.number().int().positive().optional(),
  role: z.enum(['admin', 'user', 'guest']),
  createdAt: z.date(),
})

type User = z.infer<typeof UserSchema>

Best Practices

  • Define schemas close to where they're used
  • Use .infer to derive TypeScript types
  • Compose schemas using .extend(), .merge(), .pick(), .omit()
  • Create reusable base schemas for common patterns

Validation Patterns

Safe Parsing

const result = UserSchema.safeParse(data)
if (!result.success) {
  console.error(result.error.format())
  return
}
// result.data is typed as User

Details

Repository
github.com/mindrally/skills
Categories
Frontend & UI Code, Backend & APIs
First seen
Jun 3, 2026

More from mindrally/skills

All 240

Similar to Zod Schema Validation

More Frontend & UI Code