Skip to content

Data Validation & Schema Usage

IdentityFlow embraces the Standard Schema specification, a common interface for TypeScript validation libraries. This approach allows you to use your preferred validation tools, like Valibot, Zod, and ArkType (all of which are Standard Schema compliant), ensuring flexibility and interoperability. Learn more at standardschema.dev.

Schema Validation

Use Standard Schema to validate workflow inputs and outputs with your preferred validation library.

Type Safety

Get full TypeScript type inference from your validation schemas. See Type-Safe Development.

Multiple Libraries

Choose from popular validation libraries like Valibot, Zod, and more.

Lightweight validation library with excellent TypeScript support (v1.0+).

import * as v from '@identity-flow/sdk/valibot';
import { defineWorkflow } from '@identity-flow/sdk';
const UserSchema = v.object({
id: v.string([v.uuid()]),
email: v.string([v.email()]),
role: v.union([v.literal('admin'), v.literal('user')]),
});
export default defineWorkflow(
'user-onboarding',
{
schema: UserSchema, // Validate workflow input
},
async (flow) => {
const user = flow.params; // Typed as User
await flow.do('create user', async () => {
await createUser(user);
});
},
);

Validate Early

Add schemas to workflow definitions to catch invalid data before processing starts.

Type Safety

Let TypeScript infer types from schemas for compile-time checks.

Consistent Validation

Use the same schemas across related workflows to maintain consistency.

export default defineWorkflow('order-processing', async (flow) => {
await flow.do('validate order', { schema: OrderSchema }, async (input) => {
// input is typed from OrderSchema
return processOrder(input);
});
});

See the main Error Handling guide for detailed strategies.

export default defineWorkflow('user-registration', async (flow) => {
try {
await flow.do('create user', {
schema: UserSchema
}, async (input) => {
return createUser(input);
});
} catch (error) {
if (error instanceof ValidationError) {
flow.error('Invalid user data', {
errors: error.errors
});
}
throw error;
}
});
const AddressSchema = v.object({
street: v.string(),
city: v.string(),
country: v.string(),
postal: v.string(),
});
const UserSchema = v.object({
id: v.string([v.uuid()]),
email: v.string([v.email()]),
addresses: v.array(AddressSchema),
});
export default defineWorkflow('user-registration', { schema: UserSchema }, async (flow) => {
// flow.params is typed with nested address array
await flow.do('create user', async () => {
return createUser(flow.params);
});
});