Skip to main content

Normal Steps

You can use Step to define a normal step. Normal steps takes a body function that is called when the step is reached.
This example shows a workflow with two automated steps. The body function of each step can either be defined inline (using the lambda keyword) or as a separate function. Body functions can use the context (ctx) to access data from previous steps or external systems. Read more in the context section. The return value of each function can be accessed by subsequent steps using ctx.get_step_result("step-id"). Normal steps also accept an options={...} argument for step-level behavior such as retries, on_failure, and next_task routing overrides. See Control Flow for those patterns.

Screen Steps

Screen steps are steps that present a UI to the user for input or review. To define a screen step, you need to both define
  • a React component (a .tsx file)
  • a ScreenStep in the workflow that points to the React component by file path
The return value of screen steps is the value passed into the result field of the handleComplete function. In the example above (see greeting-screen.tsx), the return value will be the string "confirmed". When a screen submits an object, downstream workflow steps receive that object directly. Do not unwrap an extra result field when reading the step output:
./src/screens/review-screen.tsx
./src/workflow.py
See the screens section for more information on how to create and customize screens.

Validating Screen Submissions

Use the before_complete option to run backend logic when the user completes a screen, before the workflow moves on. The handler receives the context and the screen’s submitted result, and its return value becomes the step’s result. Raising an ApiError from before_complete rejects the submission: the error is returned to the screen’s handleComplete call with the given HTTP status code, and the task stays open so the user can correct their input and resubmit.
before_complete is the right place for validation that needs backend data — for example, checking a submitted value against an external system before accepting it. Validation that only depends on the form itself is better done in the screen component.
Available in workflows-py >= 0.1.10.

Screen Task Priority

When several screen tasks are open at the same time — for example, from parallel branches or loop iterations — Sample routes the user to the highest-priority task after they complete their current one. Set a screen step’s priority with the priority option, either as a number or as a function of the context:
Higher numbers are routed to first. The default priority is 0, and tasks with equal priority fall back to Sample’s standard routing order.
Available in workflows-py >= 0.1.22.

Step Outputs

Every step in a workflow can return a value. This value can be accessed by subsequent steps using ctx.get_step_result("step-id"). IMPORTANT: All outputs from workflow steps must be JSON serializable. This is critical for Sample Workflows to function properly, as step outputs are stored and passed between steps in a serialized format.

JSON Serializable Types

Step outputs can include:
  • Primitive types: string, number, boolean, null
  • Arrays: Lists of JSON-serializable values
  • Objects: Plain objects with JSON-serializable properties
  • Nested structures: Any combination of the above

Example: Correct Step Output

Example: Incorrect Step Output

If you need to work with non-serializable data, convert it to a serializable format before returning from the step.

Version Control and Deployment

Sample Workflows are version controlled through Git, making it easy to track changes, collaborate with team members, and maintain different versions of your workflows.

Git-Based Version Control

  • Workflow definitions (Python files) and screen components (TypeScript files) are stored in a Git repository
  • This provides full history tracking and the ability to revert to previous versions if needed

Automatic Deployment

When changes are made to workflow files:
  1. Automatic Detection: Sample automatically detects changes to workflow files
  2. Deployment: Updated workflows are deployed and become available for use
  3. Version Management: Previous versions remain accessible, ensuring running workflows can complete even after updates