# Workflow Class
[EN] Source: https://mastra.ai/reference/workflows/workflow

The `Workflow` class enables you to create state machines for complex sequences of operations with conditional branching and data validation.

## Usage example

```typescript title="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
import { createWorkflow } from "@mastra/core/workflows";
import { z } from "zod";

export const workflow = createWorkflow({
  id: "test-workflow",
  inputSchema: z.object({
    value: z.string(),
  }),
  outputSchema: z.object({
    value: z.string(),
  }),
});
```

## Constructor parameters

<PropertiesTable
  content={[
    {
      name: "id",
      type: "string",
      description: "Unique identifier for the workflow",
    },
    {
      name: "inputSchema",
      type: "z.ZodType<any>",
      description: "Zod schema defining the input structure for the workflow",
    },
    {
      name: "outputSchema",
      type: "z.ZodType<any>",
      description: "Zod schema defining the output structure for the workflow",
    },
    {
      name: "stateSchema",
      type: "z.ZodObject<any>",
      description:
        "Optional Zod schema for the workflow state. Automatically injected when using Mastra's state system. If not specified, type is 'any'.",
      isOptional: true,
    },
    {
      name: "options",
      type: "WorkflowOptions",
      description: "Optional options for the workflow",
      isOptional: true,
    },
  ]}
/>

### WorkflowOptions

<PropertiesTable
  content={[
    {
      name: "tracingPolicy",
      type: "TracingPolicy",
      description: "Optional tracing policy for the workflow",
      isOptional: true,
    },
    {
      name: "validateInputs",
      type: "boolean",
      description:
        "Optional flag to determine whether to validate the workflow inputs. This also applies default values from zodSchemas on the workflow/step input/resume data. If input/resume data validation fails on start/resume, the workflow will not start/resume, it throws an error instead. If input data validation fails on a step execution, the step fails, causing the workflow to fail and the error is returned.",
      isOptional: true,
      defaultValue: "false",
    },
    {
      name: "shouldPersistSnapshot",
      type: "(params: { stepResults: Record<string, StepResult<any, any, any, any>>; workflowStatus: WorkflowRunStatus }) => boolean",
      description:
        "Optional flag to determine whether to persist the workflow snapshot",
      isOptional: true,
      defaultValue: "() => true",
    },
  ]}
/>

## Workflow status

A workflow's `status` indicates its current execution state. The possible values are:

<PropertiesTable
  content={[
    {
      name: "success",
      type: "string",
      description:
        "All steps finished executing successfully, with a valid result output",
    },
    {
      name: "failed",
      type: "string",
      description:
        "Workflow encountered an error during execution, with error details available",
    },
    {
      name: "suspended",
      type: "string",
      description:
        "Workflow execution is paused waiting for resume, with suspended step information",
    },
  ]}
/>

## Related

- [Step Class](./step)
- [Control flow](/docs/workflows/control-flow)