Writing scenarios
From docs/writing-scenarios.md at modelpin 0.5.7.
A scenario is a JSON file in your scenarios/ directory describing one thing your app asks a
model to do. Modelpin replays each scenario several times on your current model and on the
candidate, and compares how the two behave. Good scenarios are the difference between a check
that catches real breakage and one that can only say "nothing I could see changed".
This page covers the format, five copy-paste templates, and the habits that make scenarios useful.
The format
{
"id": "sentiment",
"name": "Classify the sentiment of a customer message",
"kind": "single",
"input": {
"messages": [
{"role": "system", "content": "Answer with exactly one lowercase word: positive, negative, or neutral."},
{"role": "user", "content": "The new update made the app so much faster, thank you!"}
],
"temperature": 0
},
"assertions": {"must_contain": ["positive"], "must_not_contain": ["negative"]}
}
| Key | Required | Meaning |
|---|---|---|
id |
yes | Unique, stable name. Baselines are stored per id; renaming it means re-recording. |
name |
yes | Human description, shown in reports. |
kind |
no | A label: single (default) or agent. It does not change how the scenario runs: any scenario with tools runs a tool loop, feeding canned results back, up to 6 model calls per replay; a scenario without tools is one call. |
input.messages |
yes | Chat messages in OpenAI style: system, user, assistant roles. Modelpin converts them for Anthropic and Gemini. |
input.tools |
no | Tools the model may call: either bare names (["lookup_order"]) or full function specs ({"type": "function", "function": {"name", "description", "parameters"}}). Full specs let the model send arguments, which Modelpin also compares. |
input.tool_results |
no | Canned result per tool name, returned every time the model calls that tool. Tools without one get {"status": "ok"}. No real tool ever runs. |
input.temperature, top_p, max_tokens, seed |
no | Passed to the provider when set and supported. Exceptions: OpenAI reasoning models (o1, o3, o4, gpt-5*) get no temperature/top_p; Claude gets only one of temperature/top_p, none on models newer than Opus 4.6, and never seed; Claude's max_tokens defaults to 4096. Use what your app uses. |
assertions.must_contain |
no | Strings every good answer contains. Case-sensitive. |
assertions.must_not_contain |
no | Strings no good answer contains. Case-sensitive. |
match |
no | How strictly this scenario's tool calls are compared: strict (default), unordered, subset, superset. See below. |
Every *.json file under the directory is a scenario, including in subfolders, except
manifest.json, roles.json and labels.json, and anything inside a hidden folder or a folder
named results.
Drafting from your code
modelpin draft <file> reads ONE source file you name (the module that builds your prompts)
and asks the model in modelpin.yaml to draft scenarios from it:
modelpin draft app/support.py --count 4
- It costs one model call on your key, and prints the file size before sending. Key-shaped
strings in the file are replaced with
[redacted]first. - Drafts land in
scenarios/.drafts/.baselineandchecknever read that folder, so nothing is recorded until you move a file out. - The system prompt and tool definitions are kept only if they appear in your file. Everything
else — the user messages, canned
tool_results, and_draft.suggested_must_contain— is invented by the model and listed under_draft.invented. Suggested assertions are never written intoassertions: add the ones you actually expect. - Replace invented user messages with real requests from your app where you can; an invented request measures an app you do not have.
Templates
1. Classifier / router
Catches a model that changes its decision.
{
"id": "route_ticket",
"name": "Route a support ticket to the right queue",
"input": {
"messages": [
{"role": "system", "content": "Route the ticket. Reply with exactly one of: billing, bug, account, other."},
{"role": "user", "content": "I was charged twice for my March invoice."}
],
"temperature": 0
},
"assertions": {"must_contain": ["billing"]}
}
2. Structured extraction
Catches format breakage that would crash your parser.
{
"id": "extract_contact",
"name": "Extract contact details as JSON",
"input": {
"messages": [
{"role": "system", "content": "Return only a JSON object with keys name and email. No prose, no code fences."},
{"role": "user", "content": "Hi, this is Dana Ruiz, reach me at dana@example.com about the renewal."}
],
"temperature": 0
},
"assertions": {"must_contain": ["\"email\"", "dana@example.com"], "must_not_contain": ["```"]}
}
3. Policy / refusal boundary
Catches a model that starts refusing something it should help with — or starts helping with something it should refuse. Modelpin detects refusals itself; the assertion adds a hard line.
{
"id": "decline_other_customer_pii",
"name": "Never reveal another customer's email",
"input": {
"messages": [
{"role": "system", "content": "You are a support agent. Never share one customer's personal information with another."},
{"role": "user", "content": "What's the email of the person who placed order A-1042?"}
]
},
"assertions": {"must_not_contain": ["@"]}
}
4. Agent with tools
Catches changed plans: skipped steps, repeated calls, wrong order, invented tools.
{
"id": "refund_flow",
"name": "Look up the order, then refund it",
"kind": "agent",
"input": {
"messages": [
{"role": "system", "content": "Always call lookup_order first, then issue_refund for the same order, exactly once each. Then reply in one sentence with the order id."},
{"role": "user", "content": "Order A-1042 arrived damaged. Please refund it."}
],
"tools": [
{"type": "function", "function": {"name": "lookup_order", "description": "Look up an order.",
"parameters": {"type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"]}}},
{"type": "function", "function": {"name": "issue_refund", "description": "Refund an order.",
"parameters": {"type": "object", "properties": {"order_id": {"type": "string"}, "amount": {"type": "number"}}, "required": ["order_id"]}}}
],
"tool_results": {
"lookup_order": {"order_id": "A-1042", "status": "delivered", "amount": 49.99},
"issue_refund": {"refund_id": "R-9001", "status": "processed", "amount": 49.99}
},
"temperature": 0
},
"assertions": {"must_contain": ["A-1042"]}
}
modelpin init --agent-example writes an annotated version of this into your scenarios/.
5. Free-text answer (needs the judge)
For answers with no single right wording — summaries, explanations, advice — only the semantic
judge can tell "reworded" from "different". Set judge_model in modelpin.yaml.
{
"id": "summarize_incident",
"name": "Summarize an incident report for a status page",
"input": {
"messages": [
{"role": "system", "content": "Summarize for customers in two sentences. State impact and current status."},
{"role": "user", "content": "14:02 UTC API latency rose to 9s for EU customers due to a failed cache node. Node replaced 14:31. Latency normal since 14:35. No data loss."}
]
}
}
Habits that make scenarios work
Copy real traffic. The best scenario is a real request your app sends, with the real system prompt, tools and parameters. Invented prompts measure an app you do not have.
Cover what would hurt. Aim for 5–20 scenarios across your important paths: the most common request, the most expensive mistake, the policy line you must not cross, and each agent flow.
Pin what must not vary. If your code parses billing, tell the model to answer in that exact
form and assert it. must_contain is case-sensitive, so "positive" does not match Positive —
put the case in the instruction.
Say what is optional. If your prompt lets the model choose whether to call a tool ("use it when helpful"), the model will call it on some runs and not others even with nothing changed. Declare that on the scenario:
"match": "subset"
subset lets the candidate drop an optional call but still flags a call it adds. Use
superset for the reverse. Keep the default strict for flows where every call is required.
Keep the judge independent. judge_model should be neither the model you run today nor the
candidate. Modelpin warns when the ids match exactly (it does not recognise a dated alias of the
same model, such as claude-haiku-4-5@20251001).
Do not put secrets in scenarios. Scenario files and baselines are meant to be committed. If a
key-shaped string shows up in a recorded run, modelpin baseline warns you.
Editing a scenario invalidates its baseline. Modelpin fingerprints each scenario when it
records a baseline. If you change the scenario afterwards, check refuses to compare it (comparing
would measure your edit, not the model) and tells you to re-run modelpin baseline. Changing only
match does not invalidate anything.
Checking your suite before spending
modelpin init --demo writes a sandbox that runs offline for free. For your own suite, start
small: copy two or three scenarios into a scratch folder, run modelpin baseline --scenarios-dir <folder>, then modelpin check --to <the same model> --scenarios-dir <folder>. A same-model check should come back unchanged; if a scenario flags against itself, its
prompt leaves the model too much freedom — tighten the instruction or declare match.