
zod-schema-validation
Best practices for Zod schema validation and type inference in TypeScript applications.
- Installs
- 1.2K
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/mindrally/skills --skill zod-schema-validation- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads zod-schema-validation automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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
.inferto 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
Transform and Refine
const schema = z.string()
.transform((val) => val.trim().toLowerCase())
.refine((val) => val.length > 0, 'Cannot be empty')
Form Integration
- Use Zod with react-hook-form via
@hookform/resolvers/zod - Define form schemas that match your form structure
- Handle validation errors in UI appropriately
- Use
.partial()for optional update forms
API Validation
- Validate request bodies in API routes
- Validate query parameters and path params
- Return structured error responses
- Use discriminated unions for different response types
Error Handling
- Implement custom error messages for better UX
- Use
.format()for structured error output - Create custom error maps for i18n support
- Handle nested object errors appropriately
Advanced Patterns
Discriminated Unions
const ResultSchema = z.discriminatedUnion('status', [
z.object({ status: z.literal('success'), data: UserSchema }),
z.object({ status: z.literal('error'), message: z.string() }),
])
Recursive Schemas
const CategorySchema: z.ZodType<Category> = z.lazy(() =>
z.object({
name: z.string(),
children: z.array(CategorySchema),
})
)
Performance
- Precompile schemas that are used frequently
- Avoid creating schemas inside render functions
- Use
.passthrough()or.strict()intentionally - Consider partial validation for large objects
FAQ
What does the zod-schema-validation skill do?
Best practices for Zod schema validation and type inference in TypeScript applications.
How do I install zod-schema-validation?
Run npx skills add https://github.com/mindrally/skills --skill zod-schema-validation in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/zod-schema-validation/ (personal) or .claude/skills/zod-schema-validation/ (project).
Which AI agents can use zod-schema-validation?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is zod-schema-validation safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains zod-schema-validation?
It is published by mindrally in mindrally/skills. It has 1,166 recorded installs.
More from mindrally/skills
fastapi-python
mindrally/skills
Expert in FastAPI Python development with best practices for APIs and async operations
nextjs-react-typescript
mindrally/skills
Expert in TypeScript, Node.js, Next.js App Router, React, Shadcn UI, Radix UI and Tailwind
web-scraping
mindrally/skills
Expert in web scraping and data extraction with Python tools
computer-vision-opencv
mindrally/skills
Expert guidance for computer vision development using OpenCV, PyTorch, and modern deep learning techniques for image and video processing.
framer-motion
mindrally/skills
Expert guidelines for building performant animations with Framer Motion/Motion library in React applications
chrome-extension-development
mindrally/skills
Expert guidelines for Chrome extension development with Manifest V3, covering security, performance, and best practices. Use when building browser extensions, creating popup UIs, implementing content scripts, working with Chrome APIs, managing extension permissions, or publishing to Chrome Web Store.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.