Reduce Block
The Reduce block enables powerful looping patterns in Scout workflows. It calls a sub-workflow for each item in an array, passing along an accumulator that builds up results—similar to the reduce function in JavaScript or Python.
New to iteration? The Reduce block is perfect when you need to process items sequentially and each step depends on the previous result. More iteration blocks (like Map for parallel processing) are coming soon!
How It Works
Provide an array of items
Either hardcode a JSON array directly (e.g., ["a", "b", "c"]) or reference data from another block using Jinja (e.g., {{ block_id.output | tojson }}).
Select a reducer workflow
Choose a published workflow that will process each item. This workflow receives two inputs: accumulator (the running result) and item (the current array element).
Configuration
Array to iterate over. You can either hardcode an array or use a Jinja template to reference data from other blocks.
Hardcoded array:
Reference from another block (use | tojson to ensure proper formatting):
The value should be a valid JSON array. If it evaluates to a single value, it will be wrapped in an array automatically.
The workflow to call for each item. This workflow must:
- Be published (drafts won’t appear in the dropdown)
- Handle two inputs:
accumulatoranditem - Return a value that becomes the new accumulator
Starting value for the accumulator. Supports Jinja templating.
Common initial values:
[]— for building arrays{}— for building objects0— for counting or summing""— for string concatenation
If not specified, defaults to an empty string.
Explicitly select which block’s output in the reducer workflow becomes the new accumulator.
If not specified, the workflow’s designated output block (marked with is_output) is used.
Creating a Reducer Workflow
Your reducer workflow needs to handle two special inputs and produce one output.
Inputs Your Reducer Receives
Accessing Inputs
Use Jinja templates in your reducer workflow’s blocks to access these inputs:
Outputs
The final accumulated value after processing all items.
Number of iterations completed.
Number of items successfully processed.
Examples
Example 1: Summarize Multiple Documents
Summarize Multiple Documents
Process a list of documents and build a combined summary.
Setup:
- Items:
{{ fetch_documents.output }} - Initial Value:
"No documents processed yet." - Reducer Workflow: A workflow with an LLM block
Reducer Workflow Logic:
Result: A single summary that incorporates all documents.
Example 2: Collect Results into an Array
Collect Results into an Array
Process items and collect the results into an array.
Setup:
- Items:
{{ input.items }} - Initial Value:
[] - Reducer Workflow: Process each item and append to array
Reducer Workflow Logic (JSON block):
Result: An array of processed items.
Example 3: Calculate a Running Total
Calculate a Running Total
Sum up values from an array of numbers.
Setup:
- Items:
{{ data_block.output.numbers }} - Initial Value:
0 - Reducer Workflow: Simple addition
Reducer Workflow Logic (JSON block):
Result: The sum of all numbers in the array.
Example 4: Build an Object from Array
Build an Object from Array
Transform an array into a keyed object.
Setup:
- Items:
{{ users_block.output }} - Initial Value:
{} - Reducer Workflow: Add each item as a key-value pair
Reducer Workflow Logic (JSON block):
Result: An object with user IDs as keys.
Best Practices
- Keep reducer workflows simple — Each iteration adds latency, so minimize complexity in your reducer workflow.
- Match initial value types — Your initial value should match what you’re building (array for arrays, object for objects, etc.).
- Test with small arrays first — Debug your reducer logic with 2-3 items before processing large datasets.
- Use the Output Block selector — When your reducer has multiple blocks, explicitly select which output to use for clarity.
- Consider memory — If accumulating large objects, be mindful that each iteration passes the full accumulator.
Limitations
Common Issues
Reducer workflow doesn't appear in dropdown
Solution: Make sure your reducer workflow is published. Draft workflows won’t appear in the selector. Go to your reducer workflow and click “Publish” to create a published revision.
Empty output or unexpected results
Solution: Check that your reducer workflow’s output block is correctly configured. Use the Output Block selector to explicitly choose which block’s output becomes the accumulator.
'Call depth exceeded' error
Solution: You have nested Reduce blocks (or other sub-workflow blocks) that exceed 10 levels deep. Restructure your workflow to reduce nesting, or combine logic into fewer workflows.