data-validation

Validate and sanitize Node.js API request data with Zod or class-validator.

3|Updated Apr 12, 2026
One-click install
npx skills add https://github.com/mauriciodelrio/delriodev-skills --skill data-validation-mauriciodelrio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-validation
Source: https://github.com/mauriciodelrio/delriodev-skills/tree/main/es-skills/software/backend/data-validation
Command: npx skills add https://github.com/mauriciodelrio/delriodev-skills --skill data-validation-mauriciodelrio

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Backend services often receive untrusted input that must be checked for correct format, type safety, and business rules. Without reliable validation, applications risk runtime errors, security vulnerabilities, and inconsistent data handling.

Core Features & Use Cases

  • Choose between Zod (schema‑first) or class‑validator (decorator‑based) for defining DTOs.
  • Apply validation at the controller/middleware layer for format checks and at the service layer for business logic validation.
  • Perform sanitization such as trimming strings, normalizing email case, and stripping unsafe HTML.
  • Validate query parameters, route IDs, pagination, and complex reusable schemas.
  • Follow guidelines to avoid common pitfalls like mixing validation libraries, missing whitelist enforcement, or embedding business logic in schemas.

Quick Start

Use the data‑validation skill to check a user creation request against the provided Zod schema and return any validation errors.

Frequently Asked Questions about data-validation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate and sanitize backend request data in a Node.js API?

Validate and sanitize backend request data by defining DTOs with Zod or class-validator, then applying schema validation at the controller layer to check formats and enforce runtime type safety before processing.

What is the best way to separate validation from business logic in TypeScript DTOs?

Separate validation from business logic by applying format and type checks at the controller layer using Zod or class-validator, while reserving business rule validation for the service layer to maintain clean boundaries.

Should I use Zod or class-validator for validating query parameters and route IDs?

You can use either Zod or class-validator for validating query parameters and route IDs. Zod offers a schema-first approach while class-validator uses decorators, but you should avoid mixing both libraries in the same project.

How do I handle data sanitization like trimming strings and normalizing emails in TypeScript?

Handle data sanitization like trimming strings, normalizing email case, and stripping unsafe HTML by configuring transformation rules within your Zod schemas or class-validator DTOs before the data reaches the service layer.

What are common pitfalls when implementing DTO validation in Node.js APIs?

Common pitfalls when implementing DTO validation include mixing different validation libraries, failing to enforce whitelist properties, and incorrectly embedding business logic directly within your schema definitions instead of the service layer.