# Test and evaluate

> Try one step, run a flow by hand, or run it on a whole table of test cases in test mode and get a pass rate. Nothing leaves Lumen while you test.

Source: https://docs.go-lumen.ai/he/build/test-and-evaluate

There are three ways to check a flow, from small to thorough: test one step, run the whole flow on a file, or evaluate it on a table of test cases and read a pass rate. Evaluations are how you change a flow, or the AI behind it, without wondering what you broke.

-   Build
-   Before you change a flow
-   YAML and console

## Test one step

Open a step in the editor and use its **Test step** section. It runs that one step with the settings you have on screen, saved or not, and shows what came out.

-   If you opened the editor from a run (**Open in editor with this run's data**), the step runs on that run's data. Without one it runs on an empty document.
-   A step that sends or saves something runs as a **dry run**: it shows what it would do and does nothing. Switch on **Really send (emails, saves, API calls)** to make a test act for real.
-   A step test is metered but never charged, and it never appears in the run list.

## Run the whole flow

Click **Run** in the editor and drop in files. This is a real run: it costs what any run costs and it sends the emails the flow sends. [Your first flow](https://docs.go-lumen.ai/he/getting-started/first-flow.md) walks through it.

When you want to test without sending anything, evaluate.

## Evaluate a flow

An evaluation runs your flow once for each row of a table of test cases, in **test mode**, and checks each result against what the row says it should be. The share of runs that pass is the **pass rate**.

*Diagram: An evaluation: rows, test runs, scores and a pass rate.* The evaluation trigger names a table of test cases. Each row of the table becomes one test run of the flow. At most maxConcurrent test runs are running at the same time, four by default, and the rest wait to start. Every test run happens in test mode: steps that would change something outside Lumen are captured as dry runs, approvals are answered from the row, and AI steps run for real. At the end of each run the score step checks what the run made against what the row expects and marks the run passed or failed. The results of all the runs are added up into one pass rate. In the picture, two of three runs pass.

*Each row becomes a test run, each run is scored by the flow's score step, and the scores add up to the evaluation's pass rate.*

You set up three things: a table of cases, an [`evaluation`](https://docs.go-lumen.ai/he/reference/triggers/evaluation.md) trigger that names it, and a [`score`](https://docs.go-lumen.ai/he/reference/steps/score.md) step that checks the result.

### 1\. A table of test cases

The dataset is a [table](https://docs.go-lumen.ai/he/data/databases-and-tables.md) in your workspace with one row per case. Some column names have a meaning:

| Column | Becomes |
| --- | --- |
| `from`, `to`, `cc`, `subject`, `body` | The email the test run starts with, so `{email.subject}` reads the case. |
| `attachments` | Paths in your [Files](https://docs.go-lumen.ai/he/data/files.md), one per line. Each is copied the way an arriving email's attachments are, so a test starts from the same document a live run does. |
| `approve` | The answer to an approval step: approve or reject, yes or no. |
| any other column | Available to the flow and to the score step as `{run.case.<column>}`. |

Add your own columns for what you expect, for example `expected_supplier`. Every column is a `run.case` field, whether or not it has a special meaning.

To start from a real run, open it and use **Save as test case**: the run's email and files become a row. On a flow's **Evaluations** tab, **Set up evaluation** creates the table with starter columns and adds the trigger for you.

### 2\. The evaluation trigger

A flow keeps its real trigger and gains a second one, **Test cases** (`evaluation`). It starts nothing by itself: no email and no schedule ever starts a run from it, and neither does **Run**. Only an evaluation does.

| Console label | YAML key | Default | What it does |
| --- | --- | --- | --- |
| **Table of test cases** | `dataset` | required | The table to read, by name. |
| **Runs per case** | `repeat` | 1 (1 to 10) | Runs each case this many times, to see how steady the AI is. |
| **Most cases per evaluation** | `maxRows` | 50 (1 to 200) | Stops an evaluation from running a huge table by accident. |
| **Pass rate needed** | `minPassRate` | 1 (0 to 1) | The share of runs that must pass for the evaluation to pass. |
| **Most tokens per case** | `maxTokensPerCase` | no limit | A run that uses more fails its case, however well it scored. |
| **Most credits per case** | `maxCreditsPerCase` | no limit | The same, in credits. |
| **Runs at once** | `maxConcurrent` | 4 (1 to 50) | How many test runs run at the same time. |
| **Approval answers** | `approvals` | the `approve` column | Which column answers which approval step: `{node: approver, column: approve}`. |
| **Model class** | `modelClass` | the workspace's test model | The model class the AI steps use during a test. |

`maxConcurrent` limits how many test runs are going at once. The rest wait, unstarted and unbilled, and each run that ends lets the next one start, in the order of the table. The AI calls of a test queue behind each other anyway, so starting every case at once only makes each one slower. Set it on the trigger, or in the `maxConcurrent` field of the API request that starts the evaluation, which overrides the trigger.

### 3\. A score step

The **Score a test run** step (`score`) compares what the run made with what the case expects. Each check reads a field from a step's output (`details.supplier`) and compares it with a value you write or a column of the case.

| `op` | Passes when |
| --- | --- |
| `equals` | The values are equal. Numbers compare by value, text is trimmed. |
| `contains` | The text contains the expected text, ignoring case. |
| `matches` | The value matches a regular expression. |
| `json` | The expected JSON is part of the value. |
| `count` | A list has the expected length, or a number is the expected number. |
| `exists` | The field is there (expected `false`: it is not). |
| `changes` | A list of changes matches the expected list. In `equal` mode (the default) a change nobody expected is a wrong write and fails the check. `include` needs only the expected ones. |

A run passes when all its checks pass. Set `minScore` on the step (0 to 1) to allow a share of them to fail. The step changes nothing and costs nothing.

Put the score step behind a branch on `run.test`, so live runs skip it:

```yaml title="evaluate-invoice-intake.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: evaluate-invoice-intake
  namespace: tenant-acme
spec:
  displayName: Invoice intake with test cases
  triggers:
    - id: email
      ref: {name: email-arrives}
      connectorRef: {name: invoices-inbox}
      next: [text]
    - id: cases
      title: Test cases
      ref: {name: evaluation}
      config:
        dataset: invoice-cases
        repeat: 1
        minPassRate: 0.9
        maxTokensPerCase: 80000
        maxConcurrent: 4
      next: [text]
  nodes:
    - id: text
      stepRef: {name: read-text}
      next: [details]
    - id: details
      stepRef: {name: chat-agent}
      config:
        instructions: Find these details in the invoice.
        fields: [{name: supplier}, {name: total, hint: Amount due, type: money}]
        files: {mode: ifNoText}
      next: [tell]
    - id: tell
      title: Send the details to accounting
      stepRef: {name: send-email}
      config:
        to: accounting@acme.example
        subject: "Invoice from {details.supplier}"
        body: "Total: {details.total}"
      next: [is-test]
    - id: is-test
      title: Is this a test?
      branch:
        - when: {field: run.test, op: eq, value: true}
          next: [score]
    - id: score
      title: Check the details
      stepRef: {name: score}
      config:
        checks:
          - {name: supplier, actual: details.supplier, op: equals, expectedColumn: expected_supplier}
          - {name: total, actual: details.total, op: equals, expectedColumn: expected_total}
```

## What test mode does

A test run is a normal run, started from a row, in a copy of the flow made for testing. The worker runs it step by step as it runs any run. What changes is what each step is allowed to do.

| The step | In a test run |
| --- | --- |
| AI and agent steps, and the logic steps (branches, filters, fields) | Run for real. An agent may use only tools that are safe to try: no MCP tools, no browser. |
| Steps that read or compute, such as read the text, merge or split a PDF, rename a file, classify | Run for real. |
| Update a spreadsheet | Runs for real, writing a new file under the run's own key. The workbook in Files is never written. |
| Steps that send or write outside the run: send, reply to and forward email, save a file, add or update a row, an HTTP request, WhatsApp, Jira and GitHub writes, in-app notifications, run code, dedupe | **Captured.** The step shows what it would have done, and nothing happens. |
| Approvals | Answered from the case's column. |
| Steps that cannot be held back: apps' remote steps, delay, memory steps | **Refused.** |

If a flow holds a step that is refused, the evaluation does not start: Lumen names each such step first, so nothing runs by surprise. A step Lumen has not classified is refused too.

Inside a test run, `{run.test}` is true, and `{run.case.<column>}` is the row. A flow that [runs another flow](https://docs.go-lumen.ai/he/build/run-another-flow.md) starts its child in test mode too. The evaluation scores the parent's run. A score step in the child runs and shows on the child's run, but does not count toward the pass rate.

## Run an evaluation

**Console:**

1.  Open the flow and choose the **Evaluations** tab. It shows your table of test cases and its row count.
2.  If the flow has no evaluation yet, click **Set up evaluation**. Then add rows to the table, or save runs as test cases.
3.  To run each case more than once, click the gear beside **Run evaluation** and set **Runs per case**. More than one shows how much the AI varies.
4.  Click **Run evaluation**. The row for it shows its progress ("Running 3/12") and fills in when every run has ended.

**CLI:**

```sh
lumen eval flow evaluate-invoice-intake
lumen eval flow evaluate-invoice-intake --repeat 3 --captured
lumen eval flow evaluate-invoice-intake --rows r-1,r-2 --json
```

The command waits for every run (up to 30 minutes, `--timeout` changes that), prints a row per run, and exits with status 1 when the share of runs that passed is below the trigger's pass rate. `--captured` also prints what each run would have sent, saved or called. `--no-wait` starts it and prints the name. `lumen eval save-run <run>` turns a live run into a test case.

## Read the results

The **Evaluations** tab lists every evaluation, newest first: its date, **Pass rate** (such as `32/32 · 100%`), **Wrong writes** with a red mark when there are any, **Cost**, **Duration**, the **Model** and who started it. A small line chart shows the pass rate over time, so you see whether a change helped.

Click an evaluation to open it. A grid shows each case against each check, with the tokens and credits it used and a link to its test run. **Failures only** narrows it to the runs that need a look. A run opens onto its checks. A `changes` check is drawn as a diff: **As expected**, **Missing: expected, not made**, **Wrong write**, or **Extra, allowed**. **Held back** lists what the run would have sent, saved or called.

An evaluation passes when the share of runs that passed reaches `minPassRate`. A run that failed to finish counts as a failure.

## What it costs

AI steps run for real in a test, so an evaluation is charged at the normal rate. Its usage is marked as an evaluation in [Billing and usage](https://docs.go-lumen.ai/he/operate/billing-and-usage.md), so you can tell testing from customer work. Test runs are not listed with your flow's real runs and are never counted in a [budget](https://docs.go-lumen.ai/he/concepts/credits-and-budgets.md): a budget never holds an evaluation back, and an evaluation never uses up a flow's budget. The step test is the exception: it is metered and not charged.

During a test, AI steps run on the workspace's test model unless the request or the trigger names another with `modelClass`. The evaluation records which model it used and how it was billed.

> **Keep the table small and sharp:**
> 
> Ten cases that each cover a different mistake tell you more than a hundred of the same kind. Add a case every time a live run goes wrong, with **Save as test case**, and the flow gets harder to break.

## Next steps

[Run another flowEvaluate a router and the flows it calls.](https://docs.go-lumen.ai/he/build/run-another-flow.md)[When a run failsRetries, error replies and limits on a run.](https://docs.go-lumen.ai/he/build/when-a-run-fails.md)[Databases and tablesWhere your table of test cases lives.](https://docs.go-lumen.ai/he/data/databases-and-tables.md)[Models and costWhat the AI in a test costs.](https://docs.go-lumen.ai/he/ai/models-and-cost.md)
