# If

Send the flow down the first path whose condition holds. Conditions compare values the run already has, or put one yes-or-no question to the model.

Logic step, If:

- Step kind: `Branch`
- Case: `GreaterThan: Read.Amount, 500`
- Then: `Wait`
- Else: `(continue)`

## Inputs

- `Cases` (case[], required): Tested in order; the first case whose condition holds is taken.
  - `When` (condition, required): An expression over the run’s values, or a Judge question.
  - `Then` (step[], required): The steps this case runs.
- `Else` (step[]): The steps run when no case holds. Where absent, the flow moves on.
- `Output` (output contract): What the taken path’s last value is narrowed to.
- `Attempts` (integer, default `1`): How many tries a Judge question whose reply fails may take.
- `OnExhausted` (policy): What happens when those attempts run out.

## Outputs

- `<last value>` (any): The last value the taken path produced, under the branch’s name. Where no case holds and there is no Else, the branch produces nothing and the flow continues.

## Conditions

| Node | Holds when |
| --- | --- |
| `Equals, NotEquals` | The value at Field equals, or does not equal, Value. |
| `GreaterThan, GreaterOrEqual, LessThan, LessOrEqual` | Numbers or strings compare that way. Values of different types compare false. |
| `Contains, In` | A string holds a string or a list holds a value; or the value is in a list. |
| `Exists` | The path resolves to a value with content: not empty, not absent. |
| `And, Or, Not` | Combine conditions. And and Or stop as soon as the answer is known. |
| `Judge` | The model answers Prompt with yes or no. Plain conditions are tested first. |

## Example

```yaml
- Branch: Check
  Cases:
    - When: { GreaterThan: { Field: Read.Amount, Value: 500 } }
      Then:
        - Wait: Approve
          Operation: Clarification
          Question: This refund is over $500. Approve it?
    - When: { Judge: { Prompt: Does the request mention fraud? } }
      Then:
        - Wait: Review
          Operation: Clarification
          Question: This refund request mentions fraud. Should it go ahead?
```

> **Decided once**
> The case taken is recorded as `branch.taken`. A turn that is resumed later follows the recorded case instead of testing the conditions again.

## Related steps

- [Ask the model](/docs/workflows/steps/ask-the-model/): Produce the values a condition reads.
- [Wait for approval](/docs/workflows/steps/wait-for-approval/): Stop on one path until a person decides.
- [Transform](/docs/workflows/steps/transform/): The expression nodes conditions are built from.
