How to use
- Copy the installation command and review the source package before installing it in your own agent environment.
- Check the source document for required tools, credentials and supported hosts.
- Describe your input and desired deliverable; review the output against the source material.
npx skills add https://github.com/j4flmao/agent_skills_nodejs_nestjs --skill validating-nestjs-dtosBefore you start
- Installation does not include a model subscription, API allowance or permission to access your files.
- Repository stars and installation counts describe activity, not an independent quality or security test.
Rendered from the source repository. Headings, examples, code, tables, links, and referenced images are preserved.
Validating NestJS DTOs
When to use
- Adding or refactoring DTOs
- Hardening boundary input
- Removing manual validation from controllers
Core rules
- Global
ValidationPipewithwhitelist: true,forbidNonWhitelisted: true - DTOs use
class-validatordecorators:@IsEmail(),@IsString(),@MinLength() - Use
@Type()from class-transformer for type conversion - No manual validation in controllers
- DTOs in
application/dtos/folder
Reference shape (TypeScript)
DTO with class-validator
import { IsEmail, IsString, MinLength, IsEnum } from 'class-validator';
import { Type } from 'class-transformer';
export class CreateUserDto {
@IsEmail()
email: string;
@IsString()
@MinLength(12)
password: string;
@IsEnum(['user', 'admin'])
role: string;
}Global ValidationPipe
// main.ts
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
transformOptions: { enableImplicitConversion: true },
})
);Examples — Do
@Post()
async create(@Body() dto: CreateUserDto): Promise<ApiResponse<User>> {
return toApiResponse(await this.useCase.execute(dto)); // No manual validation
}Examples — Don't
// ❌ Manual validation in controller
@Post()
create(@Body() body: any) {
if (!body.email) return { error: 'Email required' }; // No!
}Checklist
- [ ] Global ValidationPipe configured
- [ ] DTOs with class-validator decorators
- [ ] No manual validation in controllers
- [ ] DTOs in application/dtos folder
See reference/dto-patterns.md for full patterns.




