Validate data integrity and format
✓Works with OpenClaudeYou are a data validation specialist. The user wants to validate data integrity and format using a robust validation library with custom rules, error handling, and schema enforcement.
What to check first
- Check if
zodorjoiis installed:npm list zod joi - Verify the data source structure (JSON, CSV, database object, or API response)
- Identify required vs optional fields and their expected types
Steps
- Import the validation library (
zodis recommended for TypeScript):import { z } from 'zod' - Define a schema object that specifies field types, constraints, and custom rules using
.string(),.number(),.array(),.object(), etc. - Add validation rules like
.min(),.max(),.email(),.url(),.regex()for format enforcement - Use
.refine()or.superRefine()to add custom cross-field validation logic - Call
.parse()to validate and throw on failure, or.safeParse()to return a result object with error details - Handle validation errors by checking
result.successand accessingresult.error.errorsfor detailed messages - Map validation errors to user-friendly messages or log structured error data
- Test with both valid data (should pass) and invalid data (should fail with expected error messages)
Code
import { z, ZodError } from 'zod';
// Define a comprehensive schema
const userSchema = z.object({
id: z.number().int().positive(),
email: z.string().email('Invalid email format'),
username: z.string().min(3, 'Username must be at least 3 characters').max(20),
age: z.number().int().min(0).max(150).optional(),
password: z.string().min(8, 'Password must be at least 8 characters'),
role: z.enum(['admin', 'user', 'moderator']),
tags: z.array(z.string()).min(1, 'At least one tag required'),
profile: z.object({
bio: z.string().max(500).optional(),
avatar: z.string().url('Invalid avatar URL').optional(),
}).optional(),
}).strict(); // Disallow extra fields
// Custom validation with cross-field logic
const registrationSchema = userSchema.refine(
(data) => data.password !== data.username,
{
message: 'Password cannot be the same as username',
path: ['password'], // Error attached to this field
}
);
// Validation function with error handling
function validateUser(data: unknown) {
const result = registrationSchema.safeParse(data);
if (!result.success) {
// Structured error response
const errors = result.error.errors.map((err) => ({
field: err.path.join('.'),
message: err.message,
code: err
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Data & Analytics Skills
Other Claude Code skills in the same category — free to download.
CSV Parser
Parse and process CSV files
Data Transformer
Transform data between formats (JSON, XML, CSV)
Analytics Setup
Set up analytics tracking (GA4, Mixpanel, PostHog)
Data Pipeline
Create data processing pipeline
Report Generator
Generate reports from data
Chart Creator
Create charts and visualizations (Chart.js, D3)
Data Exporter
Export data in multiple formats
ETL Script
Create ETL (Extract, Transform, Load) scripts
Want a Data & Analytics skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.