What problem does it solve?
Zod Best Practices helps you prevent invalid or unsafe data from entering your TypeScript app by enforcing correct schema definitions, safe parsing, and high-quality error handling. It reduces runtime crashes, security risks, and confusing user-facing validation messages.
Core Features & Use Cases
- Schema Definition & Type Safety: Use the right primitive validators, enforce string constraints, prefer enums, and avoid unsafe
any patterns.
- Parsing & Validation Guardrails: Use
safeParse() for user/external input, apply parseAsync() for async refinements, validate early at system boundaries, and avoid double validation.
- Error Handling for Real UX: Collect all validation issues, use
flatten()/paths for form-friendly errors, and implement i18n/custom messaging.
- Composability & Maintainability: Use
extend(), pick()/omit(), partial() for updates, discriminated unions, and preprocess()/pipe() for clear transformation pipelines.
- Performance Awareness: Cache schema instances and apply targeted optimizations like Zod Mini when bundle size matters.
Quick Start
Use the zod skill to validate a request body against a Zod object schema by ensuring you use safeParse for user input and apply the rule index in SKILL.md to refactor unsafe validations.