# Pipe Validation Deep Dive {#pipe-validation-deep-dive}


Input validation and transformation using NestJS pipes.


## Global Validation Pipe {#global-validation-pipe}


```typescript
// main.ts
app.useGlobalPipes(
  new ValidationPipe({
    whitelist: true, // Strip unknown properties
    forbidNonWhitelisted: true, // Throw on unknown properties
    transform: true, // Auto-transform payloads to DTO instances
    transformOptions: {
      enableImplicitConversion: true,
    },
  }),
);
```


## Validation Flow {#validation-flow}






```mermaid
graph LR
    Request[Raw Body] --> Pipe[ValidationPipe]
    Pipe --> Transform[class-transformer]
    Transform --> Validate[class-validator]
    Validate -->|Pass| Controller
    Validate -->|Fail| Error[400 Bad Request]
```






## Common Decorators {#common-decorators}


| Decorator            | Validation             |
| -------------------- | ---------------------- |
| `@IsString()`        | Must be string         |
| `@IsNotEmpty()`      | Cannot be empty        |
| `@IsEmail()`         | Valid email            |
| `@IsUUID('4')`       | Valid UUID v4          |
| `@IsEnum(MyEnum)`    | Must be enum member    |
| `@IsDateString()`    | ISO 8601 date string   |
| `@IsOptional()`      | Skip if undefined      |
| `@ValidateNested()`  | Validate nested object |
| `@Type(() => Class)` | Transform to class     |
| `@Transform(fn)`     | Custom transformation  |


## Custom Pipe {#custom-pipe}


```typescript
@Injectable()
export class TenantOrganizationPipe implements PipeTransform {
  transform(value: any) {
    const tenantId = RequestContext.currentTenantId();
    return { ...value, tenantId };
  }
}
```


## UUID Parameter Pipe {#uuid-parameter-pipe}


```typescript
@Get(':id')
async findOne(@Param('id', new ParseUUIDPipe()) id: string) {
  return this.service.findOneByIdString(id);
}
```


## Related Pages {#related-pages}


- [DTO Design Patterns](https://sourcey-gauzy.pages.dev/architecture/dto-design-patterns/index.md) — DTOs
- [Request Lifecycle](https://sourcey-gauzy.pages.dev/architecture/request-lifecycle/index.md) — request flow
- [Error Handling](https://sourcey-gauzy.pages.dev/architecture/error-handling-architecture/index.md) — errors
