# switch

Canonical URL: https://developers.iagenify.com/sdk/workflows/steps/switch/
Language: en

`type: "switch"`

Several branches. One value, a list of cases, and a default — with an edge for every one of them.

Status: free · cases required · default always exists

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `value` | any |  | What to test. Usually a template. |
| `cases` | array | required | `[{ key, operator, value }]`. At least one. |

```javascript
{ id: "route", type: "switch", config: {
    value: "{{steps.classify.output.kind}}",
    cases: [
      { key: "billing", operator: "eq", value: "billing" },
      { key: "bug",     operator: "eq", value: "bug" },
    ],
} }

edges: [
  { from: "route", to: "to_finance", branch: "billing" },
  { from: "route", to: "to_support", branch: "bug" },
  { from: "route", to: "to_inbox",   branch: "default" },
]
```

## Case keys {#keys}

A letter, then letters, digits, `_` or `-`. They may not be `next`, `true`, `false` or `default`, and they may not repeat — all four are refused on save, because each one would make an edge ambiguous.

## default is not optional {#default}

> **Every case needs an edge, and so does default**
>
> A value matching nothing takes default. Without that edge the run would end there, without a word — the same reason a condition needs both branches.

## Output {#output}

```javascript
{{steps.route.output.branch}}   // the case key taken, or "default"
{{steps.route.output.value}}
```

## The first matching case wins {#order}

They are tried in order, so put the specific ones first.

- [condition](/sdk/workflows/steps/condition): Two branches.
- [merge](/sdk/workflows/steps/merge): Bringing them back.
- [Workflow steps](/sdk/workflows/steps): The 23 types.

```python
{"id": "route", "type": "switch", "config": {
    "value": "{{steps.classify.output.kind}}",
    "cases": [
        {"key": "billing", "operator": "eq", "value": "billing"},
        {"key": "bug", "operator": "eq", "value": "bug"},
    ],
}}

edges = [
    {"from": "route", "to": "to_finance", "branch": "billing"},
    {"from": "route", "to": "to_support", "branch": "bug"},
    {"from": "route", "to": "to_inbox", "branch": "default"},
]
```

```python
"{{steps.route.output.branch}}"   # the case key taken, or "default"
"{{steps.route.output.value}}"
```
