Writing Scenarios and Checks
A Scenario is one file, unsnag/scenarios/<id>.yaml. Its id is the file name. The examples on this page are for a made-up shop CLI that looks up and changes orders.
goal: What was the total of my last order?
tags: [lookup]
setup: |
shop-seed --orders 3 --last-total 42.50
checks:
- answer: { number: 42.5, tolerance: 0.01 }
solution:
commands: shop orders list --limit 1 --json
answer: Your last order came to $42.50.
wrong_answers: [Your last order came to $24.50.]Every field is in the Scenario reference. unsnag schema scenario prints them as a JSON Schema, which editors with a YAML language server can use.
The goal
Each Agent gets the goal verbatim, after one fixed line: You have the `shop` CLI available. Write it the way one of your users would ask a colleague:
- Ask for the outcome, in the user's words. "Cancel the order I placed by mistake this morning", not "Use the cancel command on the most recent order".
- Give away no command. The goal measures whether an Agent can find its way through your CLI. A goal that names
orders cancelor--forcemeasures whether it can copy. The leak lint (below) catches most of these. - Make the result checkable. "Tidy up my orders" has no fixed right answer; "Cancel every order that's still unpaid after 30 days" does.
- Cover what users really do. The drafter spreads its drafts over archetypes, which make good
tagsfor your own Scenarios too:lookup,aggregate,bulk,debug,guarded-write,multi-step-write,automationandexit-code.
Setup and the Run's workspace
setup is a shell script run as root in /work before the Agent starts. Use it to put the world into the state the goal assumes: files in /work, a config file, rows in a Mock. /work is a fresh git repository holding the Context Condition's files, which is handed to the Agent's user (agent) when setup finishes. The Agent runs in /work; your CLI is the only thing Unsnag records it calling.
teardown runs after the Checks, as root. Its result is recorded but never changes the outcome.
Checks
The Checks decide pass or fail. Every Check must pass for the Run to pass. They see only the result, never how the Agent got there, so an Agent that solves the goal some unexpected way still passes. There are three kinds.
command: the final state
A shell script run as root in /work after the Agent stops. Exit 0 passes.
checks:
- command: test -f /work/orders.csv
- command: test "$(wc -l < /work/orders.csv)" -eq 4
- command: shop-admin orders get ORD-7781 | grep -q 'status: cancelled'A Check can use any tool your install steps put in the image, such as an admin tool that reads your backend's state (or a Mock's state endpoint, with curl).
A Check that can't run (exit 126 or more: not found, not executable, killed) makes the Run error, not fail, so a broken Check never looks like an Agent's failure. To report a near miss (wrong, but close: the near_miss Signal collects these), print {"near_miss": "<what was close>"} as the last line of stdout: the Check then fails as a near miss, whatever its exit code.
Check the state the goal is about, and only that. A Check that also insists on how it got there (a particular file name nobody asked for, a log line) fails Agents that did the job.
answer: the final answer
A fixed match on the Agent's final answer, for goals that ask a question.
checks:
- answer: { contains: ORD-7781 }
- answer: { regex: "\\b42\\.50?\\b" }
- answer: { number: 42.5, tolerance: 0.01, near_miss: 1 }
- answer: { contains: { truth: "shop-admin orders last --id" }, ignore_case: true }containsandregexmatch text;ignore_case: trueignores case.numbertakes every number the answer states (1,234.50included) and passes when the closest one is withintolerance. Withinnear_miss, it is a near miss.- Any expected value can be
{ truth: <shell command> }instead of a literal: the command runs after the Agent, and its stdout is the expected value. Use it when the right answer depends on state thatsetupcreates or that changes over time.
judge: a free-text answer
When the answer is an explanation that no fixed match can grade, the Jury decides:
checks:
- judge:
rubric: Says the payment failed because the card expired, and that updating the card fixes it.
expected: The card on file expired on 2026-09-30.Three models from three vendors each see the goal, the rubric, the true answer (expected, a literal or a truth command) and the final answer, never the transcript, and vote pass, near miss or fail. Two pass votes pass. Judged Checks cost a little per Run (the Jury's calls, outside the Run budget) and add noise, so prefer answer wherever a fixed match works.
The Reference Solution
solution is how an expert would reach the goal: the shell commands they would type (run as the Agent's user in /work) and the answer they would give. No Agent ever sees it. It proves the Scenario can be solved, and the Report compares the Agents' turns and calls with it.
wrong_answers are plausible answers that must fail: a near-by number, the wrong order id, the answer for last month instead of this one. They catch Checks too loose to tell right from almost right.
Verify
unsnag scenarios verifyVerify proves each Scenario fair and solvable, in the same kind of container a Run gets, with the Reference Solution in the Agent's place:
- Vacuity:
setup, then the Checks with the final answer "I couldn't determine this.". Every Check must fail: a Check that passes on an untouched world grades nothing. - Solvability:
setup, thensolution.commands, then the Checks withsolution.answer. Every Check must pass, ajudgevote must be unanimous, and each ofwrong_answersmust be rejected by the Checks that read the answer. The solution must also call at least one of your CLI's commands, itself or in a script it writes that a Check runs: a solution that only states the answer proves nothing about your CLI, and a goal that needs no call of it is not a Scenario about it. Unsnag sees every call your CLI gets, so the commands the solution used are listed with the result (usesin--json).
A pass is cached in unsnag/.cache/ under the Scenario's content (and the version of these rules), so verifying an unchanged Scenario again is free. The cache doesn't know about your CLI: after changing it, delete unsnag/.cache/verify/ to verify again. unsnag run verifies every Scenario it runs and refuses to start while one fails, naming each and why. A Scenario without a solution can't be verified; run runs it with a warning.
The leak lint
Verify first checks each goal against your CLI's Command Tree, crawled from its --help. It flags a goal only where it writes a command out, and each hit fails verify:
- a command in backticks (
`cancel`or`orders cancel`); - your CLI's name followed by a command (
shop orders cancel); - a flag (
--all, or a short flag your CLI has); - a skill invocation (
$shopor/shop).
A plain word that happens to be a command's name is never a hit: "Cancel my last order" is fine even if your CLI has a cancel command.
unsnag validate runs the same lint, for free, against the Command Tree crawled last (by unsnag scenarios verify or unsnag run): each hit is a config error on the goal. Before your first crawl it can check only flags and skill invocations.
If a goal has to write something out, list the hits you accept on purpose in allow:
goal: My script calls `shop orders` and gets nothing back. Why?
allow: [shop orders]unsnag scenarios lists the Scenarios and the Draft Scenarios in two sections, with each one's tags, verify status and lint hits, and says which of your CLI's commands and flags the Scenarios' Reference Solutions exercise, which only the drafts do, and which none do yet. unsnag scenarios --verbose adds a grid of which Scenario exercises each command and flag. unsnag draft --uncovered drafts Scenarios for exactly those.
Drafts
unsnag draft writes Draft Scenarios to unsnag/drafts/, which is committed like unsnag/scenarios/. unsnag run skips them unless given --include-drafts, and a Report that includes them is partial, so it stays off the trend line. Reject a draft by deleting its file; accept drafts with unsnag scenarios accept <id>..., which moves them into unsnag/scenarios/ (a rename in git) and never overwrites a Scenario. notes is for you: what the Scenario is for, why its Check is shaped the way it is. No Agent sees it.
Limits
A Scenario can set its own timeout and budget (the Run's time and model spend), when it needs more than the Benchmark's defaults. A Run that hits either fails with the reason timeout or budget, or errors if the Agent hadn't called your CLI yet.