zod

Validate TypeScript data schemas with Zod using safeParse and parseAsync.

Updated Apr 2, 2026
One-click install
npx skills add https://github.com/rhuangabrielsantos/skills --skill zod-rhuangabrielsantos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: zod
Source: https://github.com/rhuangabrielsantos/skills/tree/main/skills/zod
Command: npx skills add https://github.com/rhuangabrielsantos/skills --skill zod-rhuangabrielsantos

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve?

Prevents runtime type errors, inconsistent validation logic, and unsafe data flowing through TypeScript applications by centralizing schema definition, validation, and type inference with Zod. It helps teams catch input errors at system boundaries, produce actionable validation messages, and maintain a single source of truth for data shapes.

Core Features & Use Cases

  • Schema Definition Best Practices: Guidance on primitives, enums, coercion for form/query data, and avoiding optional abuse to keep schemas strict and meaningful.
  • Parsing & Validation Patterns: Recommendations for safeParse, parseAsync for async refinements, handling all issues, avoiding double validation, and validating at boundaries.
  • Type Inference & Composition: Advice on z.infer, z.input/z.output distinctions, branded types for domain safety, discriminated unions, and composition utilities (extend, pick, omit, intersection, pipe, preprocess).
  • Error Handling & UX: Techniques for custom messages, internationalization, flattening errors for forms, adding paths to refinement errors, and using superRefine for multiple issues.
  • Performance & Production Concerns: Caching schemas, avoiding dynamic creation in hot paths, lazy loading large schemas, and recommending Zod Mini for bundle-sensitive frontends.
  • Use Case Example: Validate incoming API JSON at the endpoint using safeParse, coerce query params to correct types, and infer downstream TypeScript types to eliminate defensive null checks.

Quick Start

Use the zod skill to validate incoming JSON at the API boundary with safeParse, coerce query/form strings to numbers/booleans, and infer types with z.infer for downstream code.

Frequently Asked Questions about zod

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

FAQPage Schema
How do I validate incoming API JSON safely in TypeScript without throwing runtime errors?

Validate incoming API JSON safely using Zod's safeParse method, which returns a success object containing parsed data or an error object containing validation issues, preventing runtime exceptions at system boundaries.

What is the best way to coerce form and query string data to correct types in TypeScript?

Coerce form and query string data to correct types using Zod's z.coerce properties, which automatically transform input strings into numbers, booleans, or other primitives before applying standard schema validation rules.

How do I handle complex validation logic and return multiple custom errors in a TypeScript schema?

Handle complex validation logic and return multiple custom errors using Zod's superRefine method, allowing context-aware checks that append custom messages and specific error paths to the validation issues array.

How do I infer TypeScript types from a defined schema to eliminate defensive null checks downstream?

Infer TypeScript types from a defined schema using Zod's z.infer utility, automatically generating static input and output types that eliminate defensive null checks and ensure type safety across downstream application code.

Does schema validation impact bundle size, and how can I optimize it for frontend applications?

Schema validation impacts bundle size, so optimize frontend applications by caching schemas, lazy loading large schemas, avoiding dynamic creation in hot paths, and utilizing Zod Mini for bundle-sensitive environments.

Why should I use discriminated unions over optional fields when defining TypeScript schemas?

Use discriminated unions over optional fields to keep schemas strict and meaningful, preventing optional abuse by enforcing exact shape matching based on a specific literal tag rather than loosely accepting undefined properties.