Data Validation Rules
Designs comprehensive, multi-layer data validation strategies for web applications, APIs, and data pipelines. Covers schema validation (Zod, Joi, JSON Schema), business rule enforcement, cross-field dependency validation, format validation (email, phone, URL), data quality scoring, database-level constraints, and validation error reporting with user-friendly messages.
Usage
Describe the data entity, its fields, business rules, and where validation needs to occur (client-side, API layer, database). Specify your tech stack and validation library preferences. The skill designs a complete validation strategy with rules at each layer and consistent error formatting.
Examples
- "Create Zod schemas for a user registration form with email, password strength, and age verification"
- "Design validation rules for an order system where discount codes, quantities, and totals must be consistent"
- "Build a data quality framework that scores incoming CSV records and routes invalid rows for review"
- "Create cross-field validation: if country is US, require state and zip in 5-digit format; if UK, require postcode"
Guidelines
- Validate at every layer: client (UX), API (security), service (business logic), database (integrity)
- Use schema validation libraries (Zod, Joi) for type safety and derive TypeScript types from schemas
- Separate syntactic validation (format, type, length) from semantic validation (business rules, uniqueness)
- Return all validation errors at once, not just the first one — users should fix everything in one pass
- Use consistent error format: {field, code, message} for programmatic handling and user display
- Implement cross-field validation for dependent rules (end_date must be after start_date)
- Sanitize inputs (trim whitespace, normalize unicode) before validation, not after
- Add database CHECK constraints and NOT NULL as the final safety net — never rely solely on app-level validation