Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.promptjuggler.com/llms.txt

Use this file to discover all available pages before exploring further.

The Loop node creates iterative cycles in your workflow. It’s the most powerful control flow primitive: with it, you can build retry logic, iterative refinement, convergence loops, and multi-pass agents.

How it works

The Loop node has an input on the right (receives data), a loopback output also on the left (sends data back upstream), and an exit output on the right (fires when the loop ends). The only configuration is max iterations – the safety limit. When data arrives at the loop:
  • If iterations remain, the loopback output fires, sending the data back into the loop body
  • On the final iteration, the exit output fires instead, releasing the data downstream

Two wiring patterns

Pattern 1: Feed back into an input. Wire the loopback output to a node’s regular input handle. The node re-runs with the new data. Everything downstream of that node re-runs too. Pattern 2: Trigger re-execution. Wire the loopback output to the trigger handle (bottom) of a Prompt, Workflow, or Script node. This re-runs that specific node with fresh context while preserving its other inputs.

A real-world example

Iterative summarisation: “Keep summarising until it’s short enough.” Wire it like this: Input → Prompt → String (Length) → If (length > 200) → Loop → back to Prompt. The If node’s false output (short enough) goes to Output. The Loop’s exit output also goes to Output as a safety valve. The prompt summarises the text. If the summary is still too long, the loop feeds it back for another pass. When it’s short enough, the If node routes it to the output. If somehow it never gets short enough, the max iterations limit catches it.
The Loop’s exit output is your safety net. Always wire it somewhere useful – typically the same Output node as your success path. That way, even if the loop exhausts its iterations, you get the best result so far rather than nothing.