Skip to contentSkip to page list

Docs

Write Scenarios a Judge Can Check

Give every scenario the world it assumes, write criteria a judge can verify, and let the judge read the agent's traces.

On this page

Where we are in the story: we have a refund-support agent and one case to test: Anna, a gold customer, asks for a refund on an order that was delivered. This page turns that case into a scenario. The overview has the whole story.

Every scenario needs its world

A scenario is a situation and criteria, and it also assumes a world: the records that must exist for the situation to make sense. Anna's scenario assumes a customer named Anna on the gold tier, with one delivered order of 49.90. Without that customer in the agent's own system, the agent cannot find the order, and the verdict says more about the data than about the agent.

Write the world down next to the scenario, as fixtures: the entities and only the fields the scenario cares about.

example.jsonJSON
{  "customers": [{ "name": "Anna", "loyaltyTier": "gold" }],  "orders": [{ "customerId": { "$ref": "customers[0].id" }, "status": "delivered", "total": 49.9 }]}

A different world is a different scenario. Anna with an order still in transit is a second scenario with its own fixtures and its own criteria, not a switch on the first. Test data covers how setup turns these fixtures into records.

Write criteria a judge can verify

The judge reads the conversation, the test state and, when you turn it on, the agent's traces. A criterion passes or fails on evidence in those, so name facts the judge can check against them.

Instead ofWrite
The agent is helpful about refundsThe agent quotes a refund of 49.90 for Anna's delivered order
The agent checks the orderThe agent looks up Anna's orders before it quotes an amount
The agent follows the policyThe agent does not ask a gold customer to return the item first

The judge and the simulated user receive the run's state, so they know Anna's real order id and total. A criterion can then hold the agent to the actual data, not to a number the agent made up. Include at least one "must not" criterion for the failure you fear most, such as quoting another customer's order.

On the code path, passing the state to scenario.run needs the Scenario SDK release after langwatch-scenario 1.7.1 and @langwatch/scenario 1.8.2.

Judge from traces, not from claims

A reply can say "I looked up your order" without doing it. When the judge reads the agent's traces, a criterion such as "looks up Anna's orders before it quotes an amount" is checked against the tool call that really happened. Turn on trace fetching for scenarios in code, and connect the agent's tracing for scenarios in the platform: see Linking your traces.

A criterion about an internal action comes back Inconclusive when the traces did not arrive. Treat that as a broken connection to fix, not as a pass.

Also check: Scenarios, Test from the platform, Simulated users.

Next: Test data, where setup builds Anna's world and teardown removes it.

Documentation