# Sanitizing Inputs Zod

> Advanced input validation and sanitization using Zod. Use to prevent XSS and ensure data integrity before sending to Appwrite.

- Skill: `majiayu000/sanitizing-inputs-zod` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/sanitizing-inputs-zod`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/sanitizing-inputs-zod/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/sanitizing-inputs-zod

---


# Input Sanitization and Zod (Advanced)

## When to use this skill
- Every form that accepts user input (Reviews, Profile updates, Booking special requests).
- Before performing any database mutation in a Server Action.

## Advanced Schema
```typescript
import { z } from 'zod';

export const TourReviewSchema = z.object({
    rating: z.number().min(1).max(5),
    comment: z.string().trim()
        .min(10, "Comment too short")
        .max(500, "Comment too long")
        .refine(s => !s.includes('<script>'), { message: "Invalid characters" }),
});
```

## Instructions
- **Server-Side Only**: Validation MUST happen on the server (Server Action) even if you have client-side validation.
- **Type Inference**: Use `z.infer<typeof Schema>` to generate TypeScript types from your validation logic.
- **Sanitization**: Use `.trim()`, `.toLowerCase()`, and custom transforms to clean data before persistence.

