Schema Validation
@novu/framework accepts three kinds of schemas for both payloadSchema (workflow level) and controlSchema (step level):
| Schema | Best for | Type inference |
|---|---|---|
| Zod | TypeScript-first projects | Best — automatic via z.infer |
| JSON Schema | OpenAPI-style projects, advanced features (oneOf, if/then/else, $ref) | Good — requires as const |
| Class Validator | OOP-style apps, NestJS DTOs | Requires class-validator-jsonschema and reflect-metadata |
Zod (Recommended)
Novu supports Zod v3.Install
Workflow Payload
Step Controls
What gets rendered in the Dashboard
| Zod feature | Dashboard input |
|---|---|
z.string() | Text input |
z.string().email() | Email input with validation |
z.string().url() | URL input |
z.string().regex(...) | Text input with pattern validation |
z.string().min/.max | Length-validated input |
z.number() | Number input |
z.boolean() | Toggle |
z.enum([...]) | Dropdown |
z.array(...) | Repeatable section |
.default(value) | Pre-filled value |
Zod doesn’t support custom title on fields — the Dashboard label is derived from the property name.
JSON Schema
Use JSON Schema when you need features Zod doesn’t expose:oneOf, if/then/else, $ref, enumNames, etc.
Workflow Payload
Withoutas const, TypeScript infersstringfortypeinstead of the literal"object", and you lose type inference onpayload.
Examples
Simple object
Nested array
$ref reuse
oneOf discriminated union
if/then/else
Regex validation
Class Validator
For OOP-style projects (especially NestJS DTOs).Install
class-validator-jsonschemais required to convert decorators to JSON Schema.reflect-metadatamust be imported once at app entry (import "reflect-metadata").
Define DTOs
Caveats
- Class Validator does not support default values out of the box — set them in your resolver.
- Class Validator does not support custom titles — Dashboard labels come from the property name.
- Nested schemas can have inconsistencies — see
class-validator-jsonschemadocs.
Choosing a Schema
| You want… | Use |
|---|---|
| Best DX, type inference, Vercel-style validation | Zod |
| Already use NestJS / DTOs | Class Validator |
Need oneOf, $ref, if/then/else, share schemas with API consumers | JSON Schema |
| Want only IDE intellisense (no Dashboard schema) | Plain TS interfaces — but you lose Dashboard form generation |
Other Resources
- JSON Schema specification
- JSON Schema validator playground
- React JSON Schema Form — same UI engine Novu uses for the Dashboard
- Zod docs
- class-validator docs