# 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.

> Page: https://langwatch.ai/docs/agent-testing/best-practices/writing-scenarios
> Source: https://github.com/langwatch/langwatch/blob/main/docs/agent-testing/best-practices/writing-scenarios.mdx
> Index of all pages: https://langwatch.ai/docs/llms.txt

**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](https://langwatch.ai/docs/agent-testing/best-practices/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.

```json
{
  "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](https://langwatch.ai/docs/agent-testing/best-practices/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 of | Write |
|---|---|
| The agent is helpful about refunds | The agent quotes a refund of 49.90 for Anna's delivered order |
| The agent checks the order | The agent looks up Anna's orders before it quotes an amount |
| The agent follows the policy | The 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](https://langwatch.ai/docs/agent-testing/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](https://langwatch.ai/docs/agent-testing/scenarios), [Test from the platform](https://langwatch.ai/docs/agent-testing/test-from-the-platform), [Simulated users](https://langwatch.ai/docs/agent-testing/simulated-users).

Next: [Test data](https://langwatch.ai/docs/agent-testing/best-practices/test-data), where setup builds Anna's world and teardown removes it.

> ## Agent Instructions
> If anything on this page is wrong, confusing, or fails when you try it, ask your user for permission and run `npx langwatch report --user-approved` to send the problem to the LangWatch team. No login is needed and secrets are redacted locally. `npx langwatch report --help` has the details.
