Salt AI Docs
Pipeline Builder

Loop Nodes

Learn how to build Do While loops in Salt, wire the loop handles correctly, and avoid the common failure modes.

The Do While Loop node (SaltIfNodeSimpleLoop) is both a loop controller and a visual container for the nodes that run inside the loop body.

Unlike a traditional while loop, Salt's loop node behaves like a do-while:

  • It runs the loop body once with the starting inputs.
  • It evaluates condition after that pass.
  • It repeats only while condition is true.

Loop node example

How the Loop Works

Think of the loop node as having two phases:

  1. Enter the loop with values from outside the loop.
  2. Feed updated values back into the loop for the next iteration.

The handle names matter:

  • open_value_1, open_value_2, ...: starting values from outside the loop
  • value_1_true, value_2_true, ...: the current iteration values available inside the loop body
  • close_value_1, close_value_2, ...: updated values returned from inside the loop for the next iteration
  • condition: boolean that decides whether the loop continues
  • value_1_false, value_2_false, ...: the final values that leave the loop after condition becomes false

In practice, the data path looks like this:

  • outside node -> open_value_1
  • loop body reads value_1_true
  • loop body writes the next iteration value to close_value_1
  • condition node writes condition
  • post-loop nodes read value_1_false

condition is evaluated after the first pass, but it still must be connected before Salt will run the pipeline.

Wiring Pattern

Use this wiring pattern every time:

  1. Add a Do While Loop node to the canvas.
  2. Drag the nodes you want to repeat inside the loop container.
  3. Feed your starting values into open_value_*.
  4. Connect value_*_true to the first nodes inside the loop body.
  5. Connect the updated values from the loop body back into matching close_value_* inputs.
  6. Connect a boolean-producing node to condition.
  7. Connect value_*_false to the nodes that should run after the loop exits.

Minimal single-value loop

This is the essential shape of a working loop:

{
  "inputs": {
    "condition": ["20", 0],
    "open_value_1": ["14", 0],
    "close_value_1": ["19", 0]
  },
  "class_type": "SaltIfNodeSimpleLoop"
}

In that pattern:

  • node 14 provides the initial value
  • node 19 produces the next iteration value
  • node 20 decides whether to continue

Important Rules

These behaviors are enforced by the editor and execution engine:

  • Only nodes outside the loop should feed open_value_*.
  • Only nodes inside the loop should feed close_value_* and condition.
  • value_*_true stays inside the loop body.
  • value_*_false is the loop exit path and should be used by downstream nodes outside the loop.
  • Nested loops are not supported.
  • A loop without condition is blocked before execution.

Common Gotchas

Forgetting to return updated state

If you never connect close_value_1, the loop falls back to open_value_1 every iteration. That is sometimes useful, but in most cases it means your state never changes.

Sending the wrong branch downstream

Use value_*_false for post-loop work. value_*_true is the in-loop branch.

Using a condition that never changes

If your condition stays true forever, Salt will eventually stop the run. The execution engine starts monitoring loop state after 50 iterations and enforces a hard cap at 500 iterations.

Example Templates

These JSON files are exported pipeline workflows, not API prompt payloads. You can import them directly into the pipeline editor.

They use the current Text input node (SaltTextInput) rather than the legacy Salt Workflow Input node.

  • Basic counter loop: Text -> Primitive Value Converter -> Do While Loop, starts at 10, decrements by 1, and exits at 0
  • Multi-value loop: uses two Text inputs, converts both to integers, and exits only after both counters reach 0
  • Long-running safe loop: uses the same Salt-only building blocks and runs 60 iterations to show that changing state is allowed even past the soft monitoring threshold

When to Use a Loop

Use a loop when you need one of these patterns:

  • retry until a validator passes
  • keep updating a value until it reaches a threshold
  • maintain state across repeated agent or transformation steps
  • iterate multiple related values together and exit only when the combined stop condition is met

If you only need branching, use a conditional node instead of a loop.

On this page