# Branches and filters

> Stop a run quietly when it should not go on, send it down the first path whose condition holds, write conditions in the visual editor or as text, and join the paths again.

Source: https://docs.go-lumen.ai/he/build/branches-and-filters

A filter stops a run unless a condition holds. A branch splits a run into paths and sends it down the first path whose condition holds, like if, else if, otherwise. Both read fields that earlier steps and the trigger produced.

-   Any workspace
-   Console or YAML

Neither one costs credits, calls a model or fails a run on its own. A run that a filter stops ends quietly, without failing: the steps after the filter show as skipped, with the reason "stopped by filter" and the filter's name.

## Filter: carry on only when

**Console:**

1.  Hover the line where the check belongs and click the **+**.
2.  Choose **Filter**.
3.  Under **Condition**, pick a field, an operator and a value. Click **Done**.

The panel says "The run carries on only when this is true. Otherwise it stops quietly, without failing."

**YAML:**

A filter node has `filter.when` instead of `stepRef`:

```yaml
- id: paid
  title: Only paid orders
  filter:
    when: {field: order.status, op: eq, value: paid}
  next: [size]
```

To keep an email out before a run even exists, use **Start only when** on the trigger instead. It costs nothing at all. See [Triggers](https://docs.go-lumen.ai/he/build/triggers.md#start-only-when).

## Branch: the first path that holds

A branch has up to 8 paths, checked in order. **The first path whose condition holds runs, and the others do not.** If none holds, the run takes the **Otherwise** path when there is one. With no Otherwise path, the run ends quietly on that branch.

So order matters: put the narrowest case first. If path 1 is `total >= 5000` and path 2 is `total >= 1000`, an order of 6000 takes path 1 only.

**Console:**

1.  Hover the line where the split belongs and click the **+**.
2.  Choose **Branches**. The branch appears with a path.
3.  Click the path's label (**Path 1**). Set its condition, then click **Done**.
4.  Use the branch's menu, **Add a path**, for more paths. Order them top to bottom.
5.  Optional: choose **Add an "Otherwise" path** for what runs when no path holds.
6.  Click the **+** on each path to add the steps that follow it.

![The Path 1 panel of a branch. Under Condition, Visual is selected. One condition reads: field total from step 2, operator greater, value 5000. Buttons below add a Condition or a Group. The note says paths are checked in order and the first one that is true runs. The footer buttons are Add an Otherwise path, Delete path, Cancel and Done.](https://docs.go-lumen.ai/he/img/build/branches-and-filters-01-path-condition.png)

*A path's condition. Paths are checked in order.*

Paths are drawn as colored lines out of the branch, each labeled with its condition. The paths can come together again at a later step.

![A flow canvas. After the step Find the details, a Branch node splits into two labeled paths: total is at most 5000 goes straight on, and total is more than 5000 goes through 3. Tell the admins. Both paths meet again at 4. Add it to Invoices.](https://docs.go-lumen.ai/he/img/build/branches-and-filters-02-canvas.png)

*Two paths that join again at the last step.*

**YAML:**

A branch node has a [`branch`](https://docs.go-lumen.ai/he/reference/nodes/branch.md) list instead of `stepRef`. Each case has a `when` and its own `next`. The "otherwise" is `branchDefault`, a list of nodes, kept apart from the cases because a case with no condition is a case not set up yet. A branch has no `next` of its own.

```yaml
- id: size
  title: How big is the order?
  branch:
    - when: {expr: 'order.total >= 5000'}
      next: [review]
    - when: {field: order.total, op: gte, value: 1000}
      next: [tell]
  branchDefault: [done]
```

### A complete example

A webhook receives orders. A filter drops anything unpaid. A branch tells the admins about large orders, tells them more quietly about medium ones, and lets small ones go straight on. All three paths meet at one last step.

First, the webhook connection the flow listens on:

```yaml title="orders-hook.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Connector
metadata:
  name: branches-orders-hook
  namespace: tenant-acme
spec:
  classRef: {name: webhook}
  config: {signature: none}
```

Then the flow:

```yaml title="order-router.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: branches-order-router
  namespace: tenant-acme
spec:
  displayName: Route paid orders by size
  triggers:
    - id: order
      ref: {name: webhook-received}
      connectorRef: {name: branches-orders-hook}
      config:
        mapping:
          - {name: total, type: number, jsonPath: $.order.total}
          - {name: status, type: string, jsonPath: $.order.status}
          - {name: customer, type: string, jsonPath: $.order.customer}
      next: [paid]
  nodes:
    - id: paid
      title: Only paid orders
      filter:
        when: {field: order.status, op: eq, value: paid}
      next: [size]
    - id: size
      title: How big is the order?
      branch:
        - when: {expr: 'order.total >= 5000'}
          next: [review]
        - when: {field: order.total, op: gte, value: 1000}
          next: [tell]
      branchDefault: [done]
    - id: review
      title: Ask the admins to review
      stepRef: {name: notify-in-app}
      config:
        to: admins
        title: Large order to review
        body: "{order.customer}: {order.total}"
      next: [done]
    - id: tell
      title: Tell the admins
      stepRef: {name: notify-in-app}
      config:
        to: admins
        title: Medium order
        body: "{order.customer}: {order.total}"
      next: [done]
    - id: done
      title: Log the order
      stepRef: {name: notify-in-app}
      config:
        to: members
        title: Order received
        body: "{order.customer}"
```

For an order of 6000 that is paid, the run goes `paid`, `size`, `review`, `done`. For 1500 it goes through `tell`; for 200, `size` sends it straight to `done` by `branchDefault`. An unpaid order stops at `paid`.

## Conditions

A condition is written one of two ways. Set one or the other, never both.

-   **A single comparison:** `field`, `op` and `value`.
-   **An expression:** `expr`, a short text that can combine several comparisons.

A field is always `<id>.<output>`: a step or the trigger that comes before this node on every path to it, and one of its outputs. Two kinds of field are always available: the run's own (`run.trigger`, `run.startedAt`, `run.date`), and `each.item` and `each.index` inside a [loop](https://docs.go-lumen.ai/he/build/repeat-for-each-item.md).

### Operators

| `op` | Console | Text form | Holds when |
| --- | --- | --- | --- |
| `eq` | **is** | `=` | The field equals the value. Case counts. |
| `ne` | **is not** | `!=` | It does not. |
| `gt` | **greater** | `>` | Number or date after the value. |
| `gte` | **at least** | `>=` |  |
| `lt` | **less** | `<` |  |
| `lte` | **at most** | `<=` |  |
| `contains` | **contains** | `~` | The text, or the list, contains the value. Case does not count for text. |
| `exists` | **exists** | `EXISTS` | The field has a value. Takes no `value`. |

The text form adds more:

| Text form | Console | Meaning |
| --- | --- | --- |
| `!~` | **doesn't contain** | The text does not contain the value. |
| `IN (...)`, `NOT IN (...)` | **in**, **not in** | The field is one of a list of values. |
| `STARTS`, `ENDS` | **starts with**, **ends with** | Case does not count. |
| `IS EMPTY`, `IS NOT EMPTY` | **is empty**, **is not empty** |  |
| `AND`, `OR`, `NOT`, `( )` | **Condition**, **Group** | Combine comparisons. `AND` binds tighter than `OR`. Keywords are case-insensitive. |

```text
order.total >= 1000 AND (order.customer ~ "acme" OR order.customer STARTS "Re:")
```

Values are numbers, `"text"` or `'text'`, `true` or `false`, or a date. A date is an RFC 3339 string such as `2026-12-24` or `2026-12-24T09:00:00+02:00`, and two dates compare as times. A value can also be a placeholder like `"{invoice.limit}"` to compare two fields. In the console, **Visual** and **Text** show the same condition. The editor reports a syntax error with its column.

> **A missing field is false:**
> 
> If a run does not have the field (the step that makes it did not run, or did not find it), every comparison on it is false, except `IS EMPTY`, which holds. In a branch that sends the run to the next path or to Otherwise. Use `exists` to test for presence on purpose.

The editor and the API check that a comparison fits the field: `gt` on a text field, or a text value against a number, is refused.

## Skipped steps and joins

Steps on a path that was not taken are marked **skipped** in the run, with the reason ("no case of the branch held", "stopped by filter ..."). They cost nothing and make no fields.

A step that several paths lead to is a **join**. It runs once, after every path into it has either finished or been cut, on the combined documents of the paths that ran. Where two paths set the same field, the later one wins. If no path reached it, the join is skipped too. In the example above, `done` is a join of `review`, `tell` and the branch's default path, and only one of them ran.

Because a skipped step makes no fields, a step after a join should read only fields that every path makes, or test them with `exists` first.

A switched-off branch sends the run down its first path, and a switched-off filter lets everything through. See [Steps](https://docs.go-lumen.ai/he/build/steps.md#disable).

## Next steps

[Repeat for each itemRun the same steps once for every row or file in a list.](https://docs.go-lumen.ai/he/build/repeat-for-each-item.md)[Waits and schedulesPause a run, then carry on.](https://docs.go-lumen.ai/he/build/waits-and-schedules.md)[TriggersUse Start only when to keep mail from starting a run at all.](https://docs.go-lumen.ai/he/build/triggers.md)[Data and placeholdersWhere the fields in a condition come from.](https://docs.go-lumen.ai/he/concepts/data-and-placeholders.md)
