class-validator

Decorator-based validation for TypeScript/JavaScript classes. Add validation decorators (@IsString(), @IsEmail(), @MinLength(5)) to class properties and call validate(instance) to check validity. Works with NestJS DTOs (Data Transfer Objects) as the standard validation approach. Built on validator.js for the underlying validators. Part of the typestack ecosystem alongside class-transformer.

Evaluated Mar 06, 2026 (0d ago) v0.14.x
Homepage ↗ Repo ↗ Developer Tools validation decorators class nestjs typescript dto reflect-metadata
⚙ Agent Friendliness
67
/ 100
Can an agent use this?
🔒 Security
97
/ 100
Is it safe for agents?
⚡ Reliability
85
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
82
Error Messages
82
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
100
Auth Strength
100
Scope Granularity
100
Dep. Hygiene
82
Secret Handling
100

MIT licensed. Input validation reduces attack surface. Whitelist validation (whitelist: true in NestJS) prevents over-posting attacks. Decorator metadata requires reflect-metadata polyfill.

⚡ Reliability

Uptime/SLA
95
Version Stability
82
Breaking Changes
78
Error Recovery
85
AF Security Reliability

Best When

You're building NestJS applications where class-validator is the de-facto standard for DTO validation with NestJS's built-in ValidationPipe.

Avoid When

You're not using NestJS or TypeScript decorators — the decorator-based approach has unnecessary boilerplate outside NestJS context.

Use Cases

  • Validate NestJS DTO classes — the standard approach for request body validation in NestJS applications
  • Define typed data contracts for agent API endpoints with inline validation rules as class decorators
  • Combine with class-transformer to validate and transform plain JSON objects into validated class instances
  • Validate TypeScript domain model classes at runtime using the same decorator definitions used for type checking
  • Implement layered validation with groups (@IsNotEmpty({ groups: ['create'] })) for create vs update scenarios

Not For

  • Non-NestJS or non-decorator TypeScript projects — Zod or Joi provide better DX without TypeScript decorator requirements
  • Plain JavaScript — class-validator requires TypeScript with experimentalDecorators enabled
  • Simple one-off validations — decorator-based approach requires class definitions; use Zod for ad-hoc schema validation

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Local library — no authentication required. MIT licensed.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT licensed. Zero cost.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • Requires tsconfig.json: experimentalDecorators: true and emitDecoratorMetadata: true — without these, decorators silently do nothing
  • Must import 'reflect-metadata' at application entry point: import 'reflect-metadata' — required for decorator metadata to work
  • validate() is ASYNC — returns Promise<ValidationError[]>; use validateSync() for synchronous validation but it has limitations
  • Plain objects are NOT validated — must use class-transformer's plainToInstance() to convert JSON to class instances before validation: const dto = plainToInstance(CreateUserDto, reqBody); validate(dto)
  • Nested object validation requires @ValidateNested() decorator AND class-transformer's @Type() decorator: @ValidateNested() @Type(() => AddressDto) address: AddressDto
  • forbidUnknownValues: true is recommended — without it, unknown properties in the class are silently ignored; set in ValidationPipe options for NestJS

Alternatives

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for class-validator.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered