ZodValidationPipe refers to a custom validation pipe pattern that uses the Zod schema library for validation in NestJS. It is not built-in — it’s a pattern demonstrated in the official docs.
The pipe accepts a ZodSchema in its constructor and calls schema.parse(value) in transform(). On success, it returns the parsed value; on failure, it catches the error and throws a BadRequestException.
export class ZodValidationPipe implements PipeTransform {
constructor(private schema: ZodSchema) {}
transform(value: unknown, metadata: ArgumentMetadata) {
try {
return this.schema.parse(value);
} catch (error) {
throw new BadRequestException('Validation failed');
}
}
}Bound via @UsePipes(new ZodValidationPipe(schema)). Can be used alongside built-in pipes on different parameters.