Skip to main content
The createFlow() function provides a fluent API for building document processing pipelines. This guide covers all flow construction patterns.

Basic Flow Structure

Every flow starts with createFlow() and ends with .build():

Adding Steps

Sequential Steps

Use .step() to add sequential processing stages:
Each step has:
  • id: Unique identifier for the step
  • node: The processing node to execute
  • name (optional): Display name for observability

Step Output Flow

Data flows automatically between steps:
Each step receives the output of the previous step. The final output is the result of the last step.

Conditional Routing

Use .conditional() to route documents based on data:

Conditional Rules

Conditionals must return a node, not a promise or executed result:

Accessing Previous Step Results

The conditional function receives a second context parameter with access to all previous step artifacts:

Parallel Processing with forEach

Use .forEach() to process arrays in parallel:

forEach Requirements

  • Previous step must output an array (e.g., from split node)
  • The callback receives each array item
  • Returns a new Flow for processing that item
  • Results are collected and passed to the next step

Split Document Items

When using split before forEach, each item is a SplitDocument:
The flow automatically extracts .input when passing to child flows.

Output Nodes

Use .output() to explicitly control what data is returned:

Multiple Outputs

Create flows with multiple named outputs:

Input Validation

Restrict accepted input formats:
Supported MIME types:
  • application/pdf
  • image/jpeg
  • image/png
  • image/webp
  • image/gif
  • image/tiff

Flow Options

Configure flow behavior at creation:

Progress Callbacks

Monitor execution with callbacks:

Flow Validation

Validate flows before execution:

Validation Errors

Common validation errors:
  • Empty flow (no steps)
  • Duplicate step IDs
  • Missing node configuration
  • Invalid conditional functions
  • Type incompatibility between steps

Validation Warnings

Warnings don’t prevent execution but indicate potential issues:
  • forEach not preceded by array-producing step
  • Inefficient patterns (e.g., parse → VLM extract where parse is ignored)

Error Handling

Flows wrap errors with context:

Accessing Partial Results

When a flow fails, you can still access completed step results:

Complete Example

Next Steps

Flow Registry

Register and reuse flows

Pre-built Flows

Ready-to-use flow templates