# Branch

> Splits the run into paths. The first path whose condition holds runs; otherwise the "otherwise" path, if there is one.

Source: https://docs.go-lumen.ai/reference/nodes/branch

## At a glance

| Property | Value |
| --- | --- |
| **Node field** | `branch` (set instead of `stepRef` on a FlowNode) |
| **Side effects** | no |

A FlowNode sets exactly one of `stepRef`, `branch`, `filter`, `forEach`, `wait` and `approval`.

The value is a list; each item has the settings below.

Conditions use the expression language: a field, an operator and a value, as in `{field: details.total, op: gte, value: 10000}`.

## Settings

The value of the node field, with these settings.

| Setting | Type | Default | Description |
| --- | --- | --- | --- |
| `when` | object |  | When is the case's condition. It may be left out while the case is not set up yet: the webhook then reports the Flow incomplete, so it can be saved suspended as a draft. When present, its field is strict. |
| `when.expr` | string |  | Expr is the condition as text. Every field in it is a node or trigger upstream on every path to this one, and one of its outputs. |
| `when.field` | string |  | Field is <nodeId>.<field>: a node or trigger upstream on every path to this one, and one of its outputs. |
| `when.op` | string |  |  |
| `next` (required) | list of string |  |  |

The full JSON Schema of these settings: [branch.schema.json](https://docs.go-lumen.ai/schemas/nodes/branch.schema.json).

## Use it in a flow

```yaml title="flow.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Connector
metadata:
  name: my-email-forward
  namespace: tenant-acme
spec:
  classRef: {name: email-forward}
  config: {}
---
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: branch-example
  namespace: tenant-acme
spec:
  displayName: "Branch"
  triggers:
    - id: start
      ref: {name: email-arrives}
      connectorRef: {name: my-email-forward}
      next: [text]
  nodes:
    - id: text
      stepRef: {name: read-text}
      next: [details]
    - id: details
      stepRef: {name: chat-agent}
      config:
        instructions: Find the total in the invoice.
        fields: [{name: total, type: money}]
        files: {mode: ifNoText}
      next: [route]
    - id: route
      branch:
        - when: {field: details.total, op: gte, value: 10000}
          next: [large]
      branchDefault: [small]
    - id: large
      stepRef: {name: notify-in-app}
      config:
        to: admins
        title: A large invoice came in
        body: "Total: {details.total}"
    - id: small
      stepRef: {name: save-file}
      config: {destination: lumen}
```
