Files
baserow/docs/testing/ai-assistant-eval-analysis.md
Davide Silvestri dc62052c97 [4/4] test: harden assistant evals and tool contracts (#6007)
* test: bring Kuma eval baseline and dataset updates from #6006

* test: harden assistant evals and tool contracts

Add production-replay datasets, resilient eval execution and comparison UI, a committed baseline, and broad tool contract and chain coverage on top of the runtime behavior changes.

* test: align tool contracts with #6006 list_tables and permission output

* fix: restore the eval runner results tab and pin it structurally

The Results tab shipped unable to execute: the closing brace of usageCell
was dropped, renderResults read an undeclared totals, the cost cell still
called the old four-argument usageCell, and a second pane clear wiped the
dataset errors appended just above it. Two tests covered the tab by
asserting substrings of the page, so all four passed against dead script.

Check the page structurally instead, with a small tokenizer, because the
backend CI image has no JavaScript engine and a node-based test would
silently skip there. Replace the sampled tool-visibility assertions with
the full routed-tool map, so adding a tool has to state its reach rather
than inherit one.

* test: score eval checks against the call that actually ran

An incomplete cross-mode call is answered with a re-call redirect, so the first create_workflows call can hold a pre-switch guess rather than the arguments that executed. Score the executed call instead, recognising the redirect through the router's own helper in both its retry and tool-result forms.

* test: score the update_row target from the database, not the first draft

The check read row_id out of the recorded create_workflows arguments,
which are the model's raw output. When those arguments fail validation
the toolset's argument-repair agent fixes them and the tool runs with the
repaired payload, so a workflow that correctly names its row still scored
as missing one. Measured over ten repetitions this produced one false
failure; the trace shows execute_tool succeeding and a fix_agent span
right behind it.

Read the persisted service instead, like the neighbouring trigger and
action checks already do.

* test: check saved values in the prod-replay evals

Replay checks now verify the form collects the order fields, the page was inspected, the requested tables have rows, ISO week numbers and signed amounts are correct for seeded rows, no broken formula is left behind, and all 30 employee rows carry typed values.

* fix: compare eval results only across the same case population

A baseline captured on an older dataset version ran a different set of cases, so its means are not comparable. The Results tab now requires the experiment and baseline to share a dataset version and says when they do not.

* test: expect Kuma to ask when an implied app table is missing

#6006 decided that a request to show records refers to workspace data, so Kuma asks where the projects come from instead of inventing a table. The eval had been flipped to expect building; restore the ask expectation while the explicit example-app case still builds.

* test: accept date subtraction as a correct date-difference answer

Subtracting two date fields returns a duration (verified: 5 days for 2026-01-01 to 2026-01-06), so an answer that subtracts the dates is correct even when it does not name date_diff. Retrieval rarely surfaces the reference-guide passage for date_diff, which made this case fail three times in four on an accurate answer.

* test: expect Kuma to offer a sample-data table when app records are missing

When no table holds the records an app should show, Kuma should create nothing and ask, offering a table with sample data among the next steps.

* test: accept a plain-text question when Kuma must ask

ask_user only records a question for the final answer, so a run that asks in its reply and builds nothing behaves the same for the user. The ask checks still require that nothing was created.

* test: match docs keywords through Markdown emphasis

Answers bold feature names, so '**File** field' missed 'file field'. Keyword matching now ignores emphasis markers, and the OCR case accepts 'AI prompt', the field type's name in the product.

* chore: recapture the Kuma eval baseline on the final stack

Three repetitions of all 122 cases on 3ca6497591 with Groq GPT-OSS 120B (harness v5): 355/366 passed. Docs 192/192, core 9/9, database 61/63, builder 55/60, automation 20/21, prod-replay 18/21.

* chore: drop an import the develop rebase left unused

* test: expect docs search in every mode

* test: require complete tracker and employee replay data

* fix: compare Kuma eval results using recorded cases and checks

* fix: correct Kuma eval scoring and preserve baseline runs

* test: reuse the seeded user in Kuma builder contracts

* test: isolate async docs-search database fixtures

Create users and workspaces in synchronous pytest fixtures so their writes stay inside the rollback transaction. Async setup previously used a separate autocommit connection and leaked users, causing later data-sync tests to fail on duplicate usernames.

Remove the global async-safety bypass, enforce Django's guard locally, and keep the real database hybrid test synchronous around its async tool call.

Verified the seeded two-test reproduction fails before and passes after with no leaked users. All 71 focused tests and 1,742 broader tests pass; one existing test is skipped. Scoped pre-commit checks pass.

* docs: update Builder eval count after rebase

* fix: grade saved assistant results and preserve eval errors
2026-10-01 09:18:04 +02:00

129 lines
6.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Evaluating AI Assistant Results
How to read an eval run, compare it to the baseline, and decide whether a
change is good. Prerequisites: [running evals](./ai-assistant-evals.md),
[reading a trace](../development/ai-assistant-tracing.md#reading-a-trace).
## The baseline
The baseline is a committed snapshot of a full-suite run (default model,
current branch) at
`enterprise/backend/src/baserow_enterprise/assistant/evals/baseline.json`.
The eval runner imports it automatically on startup, so every Phoenix
instance — a fresh dev stack or the team one — has a `baseline (imported)` experiment
on each dataset without re-running anything. Manually: `just b eval-baseline
import`.
To refresh it after a meaningful improvement lands:
```bash
# Run each dataset with a recognizable name, then capture those experiments
just b eval-run --dataset kuma-docs --name baseline-candidate
# ...repeat per dataset, or run them all from the runner page...
just b eval-baseline capture --experiment-name baseline-candidate
```
Commit the regenerated `baseline.json` with the change that earned it.
## Comparing a run to the baseline
Open the dataset in Phoenix → select your live `baseline` experiment and yours →
**Compare**. Select `baseline (imported)` for historical inspection, checking its
case and scoring compatibility before drawing conclusions. The three scores:
- `checklist` — fraction of the case's checks that passed (the explanation
lists exactly which failed, with hints).
- `passed` — 1.0 only when every check passed. The strictest signal.
- `answer_quality` (`kuma-docs` only) — LLM-judge 0–1 for correctness,
helpfulness, and groundedness; graded against the reference answer when
one exists. Read its explanation, not just the number.
Phoenix compares within one dataset. For **all datasets in one view**, use
the runner page's **Results** tab: pick an experiment name (a run started
from the page lands under the same name in every dataset it touched) and see
each dataset's mean scores, execution status, and recorded run count. Baseline
deltas require complete live experiments with matching dataset versions,
recorded case counts, and check implementation hashes (`evaluator_source_hash`).
Imported snapshots remain available for individual inspection, but are excluded
from automatic deltas and Overall comparisons: the importer assigns the current
Phoenix dataset version, so matching version IDs cannot prove that historical
cases and checks match. Use Phoenix to inspect the per-case evidence before
drawing conclusions from an imported baseline.
The committed snapshot holds three repetitions of every case, with the source
commit, model settings, and harness version in its metadata. Recapture it from a
clean commit whenever cases, checks, or prompts change. Automatic deltas require
a compatible live baseline experiment, even after importing a refreshed snapshot.
The tab also shows **time and cost** per dataset: time is the
sum of run latencies (the runner executes sequentially, so it approximates
wall clock), cost and tokens come from Phoenix's per-model token prices
(Settings → Models for unknown models). A quality-neutral change that halves
cost or latency is a win too — and a score improvement that triples cost is
a trade-off to state explicitly. The baseline's time/cost are frozen into
the snapshot at capture time, since imported baselines carry no traces to
price. Partial and all-skipped experiments are marked incomplete and excluded
from deltas and the Overall row, which only compares compatible complete datasets.
Overall uses each experiment's recorded case count (expected runs divided by
repetitions), not today's registry, and includes only cases covered by each metric.
Skipped and ungraded cases do not contribute to scores; inspect their coverage
in Phoenix. Compatible runs may use different `--runs` counts: scores are means,
and time/cost are normalised per pass over the dataset. Whole-dataset experiments include
UI-added examples while the committed baseline holds code cases only; check
their per-case coverage before making a manual comparison.
Look at **per-case deltas, not the aggregate**: a +0.02 mean can hide one
real regression cancelled by two flaky recoveries. Suspected flakiness?
Re-run with `--runs 3` and compare the spread.
## Four outcomes, and what to do with each
**Improvement** — the cases your change targets go up, nothing else moves.
> Prompt override on `kuma-search-docs-agent` lifts `answer_quality` on the
> formula questions 0.62 → 0.85; every other delta is within ±0.05. Adopt:
> promote the prompt to code and refresh the baseline.
**Regression** — a case at 1.0 on baseline now fails.
> After a system-prompt edit, `builder/creates-contact-form` drops
> `checklist` 1.0 → 0.5; its trace shows the agent stopped calling
> `create_elements` and just described the form. The change is not
> mergeable as is, even if docs scores improved.
**Pre-existing gap** — the case fails in *both* columns.
> `docs/mcp-server` scores 0.1 on baseline and 0.1 on your run because the
> knowledge base predates MCP. Your change didn't cause it; don't let it
> block the change — file it (KB refresh, missing capability, or a new eval
> that pins the desired behavior).
**Flake** — the same case swings between repetitions of one experiment.
> `automation/creates-router-workflow` passes twice and fails once with a
> `tool_errors_within_budget` breach; the failing trace shows a provider
> 429 mid-run. Judge the mean across `--runs 3`, and treat persistent
> flakes as their own bug (retry behavior, ambiguous prompt), not noise.
## Diagnosing a failing case
Read in this order — cheapest signal first:
1. **`checklist` explanation** — the failed check names what's missing and
its hint carries the evidence (answer snippet, tools called).
2. **`answer_quality` explanation** — the judge says *why* the answer is
wrong or ungrounded.
3. **The linked trace**, with these signatures:
- *Wrong tool / no tool called* → open the first `chat` span: did the
system prompt, UI context, and tool manifest actually give the model
what it needed?
- *Right tool, wrong result* → the `execute_tool` span shows the exact
arguments and what came back.
- *Docs answer ungrounded or "can't find"* → the `search_user_docs`
span's retrieved chunks: if the topic isn't in them, it's a knowledge
base gap, not a model problem.
- *Many `chat` spans in a row* → retry loop; the last tool span's output
shows the validation error the model kept hitting.
- *Score fine but slow/expensive* → sort spans by tokens/duration; a
sub-agent making 10 calls where 2 would do is a real finding too.
When the diagnosis is "the model can't do this yet", keep the case failing —
a red case that pins a known gap is the cheapest regression alarm we have
for the day it starts passing.