SWIRLS_
GuidesNodes

Switch

Route execution to one of several branches by running a function that returns one of the defined cases.

Switch nodes let you define named cases and a router function that returns one of them at runtime. Execution continues only along the edge whose label matches the returned value. Use Switch when you need more than two branches or when the routing value is computed (for example, from an LLM or Code node) rather than a simple expression.

Configuration

FieldTypeRequiredDescription
casesstring[]YesList of allowed case names. Each must match /^[a-zA-Z0-9_]+$/. Edge labels must match one of these for the branch to run.
routerstringYesJavaScript function that receives nodes, reviews, secrets, and meta, and must return one of the values in cases.

Input

The function receives the same context as a Code node: nodes (trigger payload and upstream outputs), reviews, secrets, and meta. Use this data to compute which case to return.

Output

Switch nodes do not produce a data output for downstream nodes. They control which outgoing edge is followed:

  • Define cases in the node config (for example, high, medium, low).
  • The router runs at runtime and must return one of those strings.
  • Each outgoing edge has a label. Only the edge whose label equals the return value is followed.
  • Downstream nodes on the chosen branch receive the same input context (trigger payload and upstream outputs) that the Switch node received.

If the function returns a value not in cases, the node fails with an error.

Tips

  • Use clear, descriptive case names and matching edge labels so the graph is easy to read.
  • For boolean branching, use Switch with cases ['true','false'] and a router that returns the expression result.
  • Click an edge in the editor and set its Edge label to match one of the Switch cases so the correct branch runs.
  • Code -- Compute a value before the Switch, or use Switch after an LLM classification.

On this page