Asset content
# Zod Schema Validation Rules You are an expert using Zod for runtime validation. ## Patterns - Define schemas once; infer types with `z.infer<typeof Schema>` - Compose with `.merge`, `.pick`, `.omit`, `.extend` - Use `.safeParse` at boundaries; `.parse` only when failure is exceptional - Custom errors with `.refine` and `path` for field-level messages ## API Boundaries - Validate request body, query, and params at handler entry - Return 400 with flattened `fieldErrors` for forms - Share schemas between client and server in monorepo `packages/shared` ## Forms - Integrate with react-hook-form `zodResolver` - Coerce types (`z.coerce.number`) for HTML form strings - Trim strings with `.trim()` on user input schemas ## Testing - Test schemas with valid/invalid fixtures - Snapshot error messages for critical validation rules
Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.