Files
gruperly/.agents/skills/zod/AGENTS.md
2026-09-04 16:49:24 -03:00

11 KiB

Zod

Version 1.0.0
community
January 2026

Note:
This document is mainly for agents and LLMs to follow when maintaining,
generating, or refactoring codebases. Humans may also find it useful,
but guidance here is optimized for automation and consistency by AI-assisted workflows.


Abstract

Comprehensive schema validation guide for Zod in TypeScript applications, designed for AI agents and LLMs. Contains 43 rules across 8 categories, prioritized by impact from critical (schema definition, parsing) to incremental (performance, bundle optimization). Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, and specific impact metrics to guide automated refactoring and code generation.


Table of Contents

  1. Schema Definition — CRITICAL
  2. Parsing & Validation — CRITICAL
    • 2.1 Avoid Double Validation — HIGH (Parsing the same data twice wastes CPU cycles; in hot paths this adds measurable latency)
    • 2.2 Handle All Validation Issues Not Just First — CRITICAL (Showing only the first error forces users to fix-submit-fix repeatedly; collecting all errors improves UX dramatically)
    • 2.3 Never Trust JSON.parse Output — CRITICAL (JSON.parse returns any type; unvalidated JSON allows type confusion attacks and runtime crashes)
    • 2.4 Use parseAsync for Async Refinements — CRITICAL (Using parse() with async refinements throws an error; async validation silently fails or crashes the application)
    • 2.5 Use safeParse() for User Input — CRITICAL (parse() throws exceptions on invalid data; unhandled exceptions crash servers and expose stack traces to users)
    • 2.6 Validate at System Boundaries — CRITICAL (Validating deep in business logic allows corrupt data to propagate; validating at boundaries catches issues before they spread)
  3. Type Inference — HIGH
  4. Error Handling — HIGH
  5. Object Schemas — MEDIUM-HIGH
  6. Schema Composition — MEDIUM
  7. Refinements & Transforms — MEDIUM
  8. Performance & Bundle — LOW-MEDIUM

References

  1. https://zod.dev/
  2. https://zod.dev/v4
  3. https://github.com/colinhacks/zod
  4. https://zod.dev/packages/mini
  5. https://www.totaltypescript.com/tutorials/zod
  6. https://zod.dev/error-handling
  7. https://zod.dev/api

Source Files

This document was compiled from individual reference files. For detailed editing or extension:

File Description
references/_sections.md Category definitions and impact ordering
assets/templates/_template.md Template for creating new rules
SKILL.md Quick reference entry point
metadata.json Version and reference URLs