> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mira-app.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Routing Rules

> Control the flow of a workflow step — continue, retry, or skip based on conditions.

By default, each workflow step runs in sequence and passes its output to the next step. **Routing rules** let you alter that flow based on the engine's output or a fixed condition.

## Rule structure

Each routing rule has three fields:

| Field         | Description                                                                        |
| ------------- | ---------------------------------------------------------------------------------- |
| **Action**    | What to do: `continue`, `retry:N`, or `skip`                                       |
| **Trigger**   | When to apply the action: `auto` or a keyword/phrase to match in the step's output |
| **Condition** | Optional: `contains`, `does_not_contain`, `always`                                 |

## Actions

<Tabs>
  <Tab title="continue">
    ### continue

    Move to the next step immediately. This is the default behaviour — adding an explicit `continue` rule lets you attach a trigger condition to it.

    **Example:** Continue only if the output contains "APPROVED":

    ```
    Action:    continue
    Trigger:   APPROVED
    Condition: contains
    ```
  </Tab>

  <Tab title="retry:N">
    ### retry:N

    Re-run the current step up to `N` times. Useful for quality gates where the engine should keep trying until a condition is met.

    `N` can be 1–5. If the step has not satisfied the trigger after `N` retries, the workflow continues anyway.

    **Example:** Retry up to 3 times if the output does not contain a Markdown table:

    ```
    Action:    retry:3
    Trigger:   |-----|
    Condition: does_not_contain
    ```
  </Tab>

  <Tab title="skip">
    ### skip

    Skip the next step and jump to the step after it. Useful for optional enrichment steps that should only run when the upstream output meets a condition.

    **Example:** Skip the "Risk Flags" step if the document does not contain the word "liability":

    ```
    Action:    skip
    Trigger:   liability
    Condition: does_not_contain
    ```
  </Tab>
</Tabs>

## Auto trigger

Set **Trigger** to `auto` to apply the action unconditionally at the end of the step.

```
Action:    continue
Trigger:   auto
```

This is equivalent to the default step behaviour.

## Multiple rules

A step can have multiple routing rules. MIRA evaluates them top-to-bottom and applies the first rule whose condition is satisfied. If no rule matches, the default `continue` behaviour applies.

<Warning>
  Routing rules operate on the raw text output of a step. If your step produces structured output (JSON, Markdown tables), use a substring from that structure as your trigger keyword.
</Warning>

## Example: Quality gate with retry

This configuration retries the "Summarise" step up to two times if the output is shorter than expected:

```
Step: Summarise findings
Instructions: Summarise the research into exactly 5 bullet points. {{prev_output}}

Routing rules:
  1. Action: retry:2  |  Trigger: "- "  |  Condition: does_not_contain
  2. Action: continue |  Trigger: auto
```

<Note>Edit this page — [Open a pull request](https://github.com/satyendra2013/mira-app/edit/main/docs/features/workflows/routing-rules.mdx)</Note>
