Docs / Strand / nodes/logic

Logic Node

The Logic node provides conditional and iterative control flow in workflows.

The Logic node's Mode selector — Filter, If/Else, or Foreach — with the If/Else condition field. Mode is an explicit choice, not a default. If/Else routes on the if and else handles; Filter passes or drops the event; Foreach iterates on each and done.

Overview

The Logic node combines multiple control flow operations in one configurable node:

Modes

Filter Mode

Evaluates a condition and only allows events through if true.

Configuration:

Field Type Description
filter_code string Python code that produces True (pass) or False (drop)

Both styles work: return True/False or assigning result = True/False:

python

# Style 1: return the condition
return payload.get('value', 0) > 25
python

# Style 2: assign result
result = payload.get('value', 0) > 25
Empty result defaults to PASS

If the code returns nothing / leaves result as None, the event passes (is not filtered out). Non-boolean results are coerced to a boolean.

Handles:

If/Else Mode

Branches execution into two paths based on a Jinja2 condition.

Configuration:

Field Type Description
condition string Jinja2 expression evaluating to true/false

Example:

jinja

payload.temperature > 25

Handles:

Foreach Mode

Iterates over an array, calling a connected node for each item, then aggregating results.

Configuration:

Field Type Default Description
array_path string payload.items JSONPath or dot-notation path to array
item_var string item Variable name for current item in payload
index_var string index Variable name for current index
batch_size number 10 Items processed per batch
batch_delay_ms number 0 Delay between batches (ms)
max_items number 1000 Safety limit for array size (configurable, max 10,000)

Handles:

Foreach Execution Flow

code

┌─────────────────────┐
│   Foreach Node      │
│   (array of 100)    │
└─────────┬───────────┘
          │
    ┌─────┴─────┐
    │           │
  [each]     [done]
    │           │
    ▼           │
┌─────────┐     │
│ HTTP    │     │
│ Request │     │
└────┬────┘     │
     │          │
     └──────────┤  (results aggregated)
                │
                ▼
        ┌───────────────┐
        │ Process       │
        │ All Results   │
        └───────────────┘

How It Works

  1. The foreach node receives an event with an array
  2. For each item in the array:
  1. After all items are processed:

Batched Execution

Items are processed in batches to control rate and memory:

Example: Processing 100 items with batch_size=10 and batch_delay_ms=1000:

Output Format

The "done" output contains:

json

{
  "payload": {
    "...original payload...",
    "_foreach_results": [
      { "index": 0, "input": "item1", "output": {...}, "success": true },
      { "index": 1, "input": "item2", "output": {...}, "success": true }
    ],
    "_foreach_failed": [
      { "index": 5, "input": "item6", "error": "Timeout", "success": false }
    ]
  },
  "meta": {
    "_foreach_complete": true,
    "_foreach_total": 100,
    "_foreach_processed": 100,
    "_foreach_success_count": 99,
    "_foreach_failed_count": 1
  }
}

Progress Tracking

During execution, progress is tracked in the step run metadata:

This is visible in the Node Execution Details panel.

Examples

Foreach: Process User List

Scenario: Fetch details for each user ID in an array.

  1. Add Logic node, set mode to "Foreach"
  2. Set array_path to payload.user_ids
  3. Connect "each" handle to HTTP Request node
  4. Configure HTTP Request: GET /api/users/{{ payload.item }}
  5. Connect "done" handle to next processing step

If/Else: Route by Priority

Scenario: High priority items go one way, others go another.

  1. Add Logic node, set mode to "If/Else"
  2. Set condition: payload.priority == 'high'
  3. Connect "if" handle to urgent processing
  4. Connect "else" handle to normal processing

Filter: Validate Data

Scenario: Only process events with required fields.

  1. Add Logic node, set mode to "Filter"
  2. Set filter code:
python

   # Simple: return the condition
   return payload.get('email') and payload.get('name')
  1. Connect output to processing node

Best Practices

Tips
1

Foreach batch_size

Start with 10, adjust based on API rate limits

2

Foreach max_items

Set appropriate limits to prevent runaway executions

3

Error handling

Check _foreach_failed array for items that failed

4

Memory

Very large arrays may need external storage for results

Foreach Limitations
  • Default limit of 1,000 items per foreach execution (configurable via max_items in the foreach config, up to a hard maximum of 10,000)
  • Default batch_size is 10, batch_delay_ms is 0
  • Results are held in memory during execution
  • Long-running foreach operations may timeout