zod

Applies Zod schema validation best practices for TypeScript type safety, parsing, and error handling.

Updated Aug 15, 2025
One-click install
npx skills add https://github.com/yehezkieldio/topaz --skill zod-yehezkieldio
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: zod
Source: https://github.com/yehezkieldio/topaz/tree/main/.agents/skills/zod
Command: npx skills add https://github.com/yehezkieldio/topaz --skill zod-yehezkieldio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) and assets (resource) components.

What problem does it solve? Writing Zod schemas without established patterns leads to overly permissive validation, unhandled exceptions from parse(), cryptic error messages, and TypeScript types that drift out of sync with runtime validation. ## Core Features & Use Cases - Schema Definition Rules: Enforces correct primitive selection, string validations, enums, and coercion for form and query data. - Parsing & Error Handling Guidance: Covers safeParse(), parseAsync for async refinements, collecting all validation issues, and flatten() for form error display. - Type Inference & Composition Patterns: Promotes z.infer over manual types, branded types, discriminated unions, and reusable schema composition with pick, omit, partial, and extend. - Use Case: When building a Next.js API route that accepts user registration data, apply these rules to validate input with safeParse, return all field-level errors with custom messages, and infer the TypeScript type directly from the schema. ## Quick Start Review my Zod schemas and refactor them to follow the validation best practices in this skill.

Frequently Asked Questions about zod

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate user input with Zod safely?▼

Use safeParse() instead of parse() for user input so validation failures return a result object instead of throwing exceptions. This prevents unhandled errors from crashing servers and lets you collect all issues for user feedback.

What is the difference between z.infer and z.input in Zod?▼

z.infer (same as z.output) captures the post-transform type, while z.input captures the pre-transform shape. When schemas use transform() or pipe(), choose the type that matches where the data is consumed.

Should I use z.any() or z.unknown() in Zod schemas?▼

Use z.unknown() instead of z.any(). z.any() bypasses TypeScript's type system entirely, while z.unknown() forces type narrowing before the value can be used, preserving type safety.

Does Zod support async validation refinements?▼

Yes, but async refine() or superRefine() callbacks require parseAsync() or safeParseAsync(). Calling synchronous parse() on a schema with async refinements throws an error.

When should I use strict() vs strip() on Zod objects?▼

Use strict() to reject unknown keys when enforcing API contracts or catching schema mismatches. Use strip() (the default) to silently remove extra keys when cleaning data, and passthrough() only when proxying unvalidated fields.

How do I reduce Zod bundle size for frontend apps?▼

Use Zod Mini, which is roughly 1.9kb gzipped compared to about 17kb for full Zod. Also cache schema instances at module level and lazy load large schemas to reduce initial bundle and parse time.