Steps Overview
A Flow consists of multiple steps, each doing a specific task—like generating objects with an LLM, training a model, creating images, or transforming/combining data. Steps run sequentially, in the order they appear in your Flow’s steps array.
Step Execution & Order
When a Flow runs:
- Initialize: The user’s input is validated, and an internal state object is stored.
- Step-by-Step Execution: We process each step in sequence:
- Step 0 → Step 1 → Step 2 → …
- Results: If a step succeeds, its output is stored in the Flow’s state under
$.results.[stepId]. - Referencing Outputs: Steps can read prior steps’ results via JSON Path (like
$.results.someStep.field).
You cannot reference results of a future step. For instance, step 1 can’t read data from step 3, because step 3 won’t have run yet. If you attempt it, you’ll get an error.
Step Types
Each step is an object with { id, type, parameters, ... }. The main types in Lensless are:
-
- Uses an LLM to produce structured JSON objects following a schema.
-
- Trains or fine-tunes a model, typically on user-uploaded images.
- Outputs a
trainingIdthat can be reused for image generation.
-
- Creates images from a base model or a trained model.
- Accepts prompts, negative prompts, size, guidance scale, etc.
-
- Merges, filters, or re-formats JSON data using the Flow Language (including
@Map,@Extend, etc.).
- Merges, filters, or re-formats JSON data using the Flow Language (including
-
- Bundles images and JSON files from prior steps into one
.zipfor easy download.
- Bundles images and JSON files from prior steps into one
Linking Steps via JSON Path
To pass data between steps, each step writes to $.results.[stepId]. A subsequent step’s parameters can read it:
{
id: 'imageGen',
type: 'ImageGenerator',
parameters: {
trainingId: '$.results.modelTrainer.id',
images: [
{
prompt: 'a painting of a cat in the style of $$',
},
],
},
}Flow Language in Steps
You can use the Flow Language to transform or select fields in any step’s parameters or result fields:
"$.input.someField"references a user’s input."$.results.someStepKey.nestedValue"references a previous step’s output.- Operators like
@Map,@Extend,@Indexlet you loop arrays, merge objects, or index items.
For example:
{
id: 'transformer1',
type: 'ObjectTransformer',
result: {
expandedData: [
[
'@Map($.results.objectGenStep.items, i)',
{
'@Extend': '$$',
index: '@Index(i)',
},
],
],
},
}Produces a new array by mapping each item from $.results.objectGenStep.items, merging that item into the new object, and adding an index field.
Execution Flow
- Step 0 executes and writes to
results.step0. - Step 1 can reference
results.step0. - Step 2 can reference both
results.step0&results.step1. - Continue until all steps finish or an error occurs.
If any step fails, the Flow run also fails. A partial result is still stored, indicating where it broke.
Step Example
"steps": [
{
"id": "objectGen",
"type": "ObjectGenerator",
"parameters": { /* Object generator config */ }
},
{
"id": "myModel",
"type": "ModelGenerator",
"parameters": { /* references input or previous step data */ }
},
{
"id": "imageGen",
"type": "ImageGenerator",
"parameters": { /* references myModel's output */ }
},
{
"id": "transFinal",
"type": "ObjectTransformer",
"result": { /* merges objectGen & imageGen data via @Extend or @Map */ }
},
{
"id": "zipEverything",
"type": "Zipper",
"parameters": {
"sources": ["imageGen", "transFinal"],
"filename": "all_results.zip"
}
}
]Summary
- Steps run in order from the beginning of your steps array to the end.
- No referencing future steps—only data from prior steps is available.
- Multiple Step Types let you do everything from generating structured data to training a model and zipping results.
- Flow Language and JSON Path references let you pass data between steps seamlessly.
- See each step type page for specific parameters and advanced examples.
By chaining these step types, you can build powerful AI pipelines that gather user input, generate or transform data, train custom models, produce images, and package outputs.