Skip to main content
Mastra v1 is coming in January 2026. Get ahead by starting new projects with the beta or upgrade your existing project today.

Step

The Step class defines individual units of work within a workflow, encapsulating execution logic, data validation, and input/output handling.

UsageDirect link to Usage

const processOrder = new LegacyStep({
id: "processOrder",
inputSchema: z.object({
orderId: z.string(),
userId: z.string(),
}),
outputSchema: z.object({
status: z.string(),
orderId: z.string(),
}),
execute: async ({ context, runId }) => {
return {
status: "processed",
orderId: context.orderId,
};
},
});

Constructor ParametersDirect link to Constructor Parameters

id:

string
Unique identifier for the step

inputSchema:

z.ZodSchema
Zod schema to validate input data before execution

outputSchema:

z.ZodSchema
Zod schema to validate step output data

payload:

Record<string, any>
Static data to be merged with variables

execute:

(params: ExecuteParams) => Promise<any>
Async function containing step logic

ExecuteParamsDirect link to ExecuteParams

context:

StepContext
Access to workflow context and step results

runId:

string
Unique identifier for current workflow run

suspend:

() => Promise<void>
Function to suspend step execution

mastra:

Mastra
Access to Mastra instance

On this page