# Evals

**Who this page is for:** everyone who decides whether a harness is good enough: developers,
product managers, technical analysts and QA engineers. It needs no Python.

An **eval** is a set of cases and the criteria that judge them. You run it against a version
of your harness and get a report. Two reports over the same cases compare, and the
comparison says whether the new version is better, about the same, worse, or whether there is
not enough data to tell.

- **You will learn:** what an eval is made of, how one is run, who writes which part, and
  where evals fit in gvn.
- **Read first:** nothing. The [quickstart](../quickstart.md) helps if you want to know what a
  run of a harness is, but this page explains what it needs.
- **Time:** about 10 minutes.

## The picture

```mermaid
flowchart LR
    cases[("Cases file<br/>support.cases.csv")]
    evalfile[("Eval file<br/>support.eval.toml")]
    version["A version<br/>of your harness"]
    subgraph trial ["One trial, repeated for every case and trial"]
        direction TB
        world["A fresh environment"]
        run["An ordinary gvn run<br/>of the version"]
        criteria["The criteria<br/>code, a judge, a review"]
        world --> run --> criteria
    end
    report["Report<br/>pass rate, solid / flaky / failing"]
    other["Report of<br/>another version"]
    comparison["Comparison<br/>better, about the same,<br/>worse, not enough data"]
    cases --> trial
    evalfile --> trial
    version --> trial
    trial --> report
    report --> comparison
    other --> comparison
```

Two text files describe the eval: a **cases file** (a spreadsheet saved as CSV, one case per
row) and an **eval file** (a short TOML file naming the cases file, how many trials each case
gets and the criteria). `gvn eval run` runs every case against the version you name, judges
every trial and prints the report. `gvn eval compare` puts two reports side by side.

## The words

These words mean the same thing on every page of this section, in the command line and in the
web page.

| Word | What it means |
|---|---|
| **Case** | One example job and what a good result looks like. "Ada forgot her password; the reply must mention *Forgot password*." A row of the cases file. |
| **Trial** | One attempt at one case. A case with 2 trials runs twice, because a harness built on a model does not always do the same thing. |
| **Criterion** | One rule that says whether a trial was good: "the reply states the key fact". Each criterion gives each trial a pass, a fail, or "could not judge". |
| **Must pass** / **measured** | The two kinds of criterion. A trial **passed** when every must-pass criterion passed. Measured criteria are reported beside it and never decide it. |
| **Judge** | A criterion decided by a model: you write a statement in plain words ("the reply is polite"), and a model reads the trial and says whether it holds. |
| **Review** | A criterion decided by a person: you write a question, and someone answers it in the [web page](web-page.md). |
| **Version** | One variant of your harness that the developers offer by name, such as `baseline` or `plain_spoken`. An eval runs against one version at a time. |
| **Environment** | The world a trial works in: the knowledge base, the ticket system, the files. Every trial gets a fresh one, so trials never disturb each other. |
| **Stand-in** | Who answers, during a trial, what a person would answer in production: approving a refund, answering a question. |
| **Eval run** | One run of an eval against one version, recorded under a name such as `support.baseline`. Running the same command again continues it. |
| **Report** | What an eval run found: how many trials passed, each criterion's pass rate, which cases are solid, flaky or failing, and what it cost. |
| **Comparison** | Two reports over the same cases, case by case: is the candidate better than the baseline? |
| **Gate** | A minimum a report must reach, such as "at least 90% of trials passed", checked in CI. |

[Reading reports](reports.md) explains every number a report and a comparison show, and what
to do about each.

## A trial is an ordinary gvn run

Nothing about a trial is special. gvn starts the version's harness on the case, exactly as it
would start it for a real customer, in a fresh environment, under a **Governor** (the part of
gvn that drives every run and records every step in the **journal**). When the harness needs a
person, the stand-in answers. When the run ends, gvn asks the environment what it now holds
(the tickets opened, the files changed) and stores that with the trial. Then the criteria
read what was recorded.

That has three consequences you can rely on:

- **A trial can be read back step by step.** It is in the journal like any run, so the web
  page shows its conversation (*Read the conversation*), and a developer can [replay](../guides/replay-and-evaluation.md) or
  [fork](../guides/forking-a-run.md) it.
- **Criteria never touch the world.** They read what was recorded. So a run can be scored again
  later with changed criteria without running the harness again (`gvn eval regrade`), and a
  criterion added later costs only its own judge calls. A score always belongs to the criterion
  that gave it: when a criterion's statement, judge model or code changes, the old scores wait
  to be scored again instead of being counted.
- **A stopped eval run continues.** If a run stops half way (Ctrl-C, a crash, its budget), the
  same command picks it up: trials already recorded are kept, trials that could not run are
  tried again, missing judgements are asked for again, and the rest are run. What it costs
  counts every attempt.
- **Several people can run one eval run at once.** Each trial is taken by one of them and runs
  once; the others' reports show it as being run elsewhere until it is recorded.

## Where evals fit in gvn

A harness built with gvn is a set of verified state machines driven by the Governor, which
records everything in the journal. Evals add nothing to that path. They sit on top of it:

```mermaid
flowchart TB
    people(["Product managers, QA, analysts<br/>cases file, eval file, gvn eval, web page"])
    developers(["Developers<br/>the Project, written once"])
    console["gvn eval and the web page"]
    evals["Evals<br/>cases, criteria, runner, reports, comparisons"]
    runtime["The runtime<br/>Governor, journal, replay, allowances"]
    harness["Your harness<br/>agents, tools, policy"]
    people --> console
    developers --> console
    console --> evals --> runtime --> harness
```

gvn already has [checks](../guides/replay-and-evaluation.md#checks): rules a single run must
satisfy, such as "no refund ran without a person's approval", checked on recorded history for
free. A check can be a criterion of an eval, unchanged. What evals add is the rest of the
question a team asks before it ships a change: over many examples, run several times each,
how often does this version do the job well, and is it better than what we have?

## Who does what

| Who | Writes | Runs and reads |
|---|---|---|
| **Developers** | The [project](project.md), once: the versions offered, the environments, the stand-ins, the criteria that need code, the models and their prices. | Anything, also from Python. |
| **Product managers** | Cases (what customers ask, what a good answer says) and criteria in plain words: judge statements and review questions. | `gvn eval run`, `gvn eval compare`, the reports and the web page. |
| **QA engineers** | Cases for the edge cases and the regressions they find, tags to select them, and the gates CI applies. | `gvn eval run --only`, `gvn eval gate`, JUnit results in CI. |
| **Technical analysts** | Criteria that measure what the business tracks (cost, calls, a field filled correctly), and reviews that check the judge. | Reports and comparisons, the conversations of single trials. |

Product managers and QA engineers never need to write Python. A cases file and an eval file
can only name what the project offers, and gvn refuses a file that names anything else before
it runs a single trial, saying what the project does offer.

## The loop evals close

gvn's guiding idea is [self-improvement](../guides/self-improvement.md): a harness can be
observed, changed, re-verified and adopted, in a loop.

```mermaid
flowchart LR
    observe["Observe<br/>journal and replay"]
    propose["Propose<br/>a new version"]
    verify["Verify<br/>the verifier"]
    evaluate["Evaluate<br/>an eval run, compared"]
    promote["Promote<br/>a person approves"]
    observe --> propose --> verify --> evaluate --> promote --> observe
```

Evals are the **evaluate** step. Replay can show that a change does harm on runs that already
happened; only new trials, scored, can show that it helps. A comparison's verdict is also a
Decision a gvn workflow can route on, so an improving harness can propose a version, run the
eval and keep the version only when the comparison says *better*.

## The pages of this section

| Page | For | What it covers |
|---|---|---|
| [Your first eval](first-eval.md) | everyone | The support desk example, end to end: list, a smoke run, two full runs, a comparison, the web page. |
| [Writing cases](cases.md) | product managers, QA | The cases file in CSV or JSONL, tags, and adding cases in the web page. |
| [Writing criteria](criteria.md) | product managers, analysts, QA | The eval file: must pass and measured, criteria the project offers, spending limits, judges, reviews, and checking a judge against people. |
| [Reading reports](reports.md) | everyone | Every number in a report and a comparison, rerunning, regrading, cost and budget, gates in CI. |
| [The web page](web-page.md) | everyone | `gvn eval serve`: its six views and how to review. |
| [Writing the project](project.md) | developers | The Project behind the files, and `gvn.evals` from Python. |
