createFlow() function provides a fluent API for building document processing pipelines. This guide covers all flow construction patterns.
Basic Flow Structure
Every flow starts withcreateFlow() and ends with .build():
Adding Steps
Sequential Steps
Use.step() to add sequential processing stages:
- 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: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 secondcontext 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
splitnode) - The callback receives each array item
- Returns a new
Flowfor processing that item - Results are collected and passed to the next step
Split Document Items
When usingsplit before forEach, each item is a SplitDocument:
.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:application/pdfimage/jpegimage/pngimage/webpimage/gifimage/tiff
Flow Options
Configure flow behavior at creation:Progress Callbacks
Monitor execution with callbacks:Flow Validation
Validate flows before execution: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:forEachnot 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