Writing cases¶
Who this page is for: product managers and QA engineers who write the examples an eval runs, in a spreadsheet, a text editor or the web page. A short part at the end is for developers who want to check what a file reads as.
A case is one example job and what a good result looks like. The cases of an eval live in one cases file: a spreadsheet saved as CSV, one case per row, or a JSONL file, one case per line.
- You will be able to: write a cases file, nest fields, tag cases and run a part of them, give several acceptable answers, and add or change cases in the web page.
- Read first: Evals and Your first eval.
- Time: about 15 minutes.
How a case is used¶
flowchart LR
row[("A row of the cases file")]
brief["brief.*<br/>what the harness is given"]
expect["expect.*<br/>what a good result looks like"]
tags["tags<br/>to choose cases by"]
harness["The version<br/>under test"]
criteria["The criteria"]
row --> brief --> harness
row --> expect --> criteria
harness -- "what it did" --> criteria
row --> tags
A case has three parts:
- the brief: the job, exactly as the harness receives it at the start of a trial (the customer's name and question);
- the expect: reference data the criteria check the result against (where the case should go, the fact the reply must mention). The harness never sees it. A judge or a reviewer does: they are shown it under the heading Expected (reference data the harness did not see);
- the tags: words to choose cases by (
smoke,refunds,ambiguous).
Which brief fields a harness needs is up to the developers: they are the fields its start reads. Which expect fields mean what is up to the criteria that read them. Ask the developers for both once; the web page's Cases view shows the fields the existing cases already use.
A cases file in CSV¶
The file is named <name>.cases.csv. The first row names the columns; every other row is one
case. This is the start of the support desk's file:
case_id,tags,brief.customer,brief.question,expect.route,expect.mentions
password-reset,answer smoke,Ada,I forgot my password. How do I get back into my account?,answer,Forgot password
delivery-abroad,answer,Dana,I am ordering from abroad. How long does international delivery take?,answer,seven to ten|7 to 10|7-10
payment-cheque,answer,Jonas,Can I pay by cheque?,answer,
refund-damaged,human smoke,Mona,My blender arrived cracked. I want my money back.,human,
| Column | Required | What it holds |
|---|---|---|
case_id |
yes | The case's name: letters, digits, - and _, starting with a letter or a digit, different on every row. It appears in every report, so make it say what the case is about (refund-damaged). |
tags |
no | Tags separated by spaces: answer smoke. |
brief.<field> |
at least one | A field of the brief: brief.question. |
expect.<field> |
no | A field of the expect: expect.route. |
No other column is allowed: a misspelt column is refused with its position, so it is never silently ignored.
What a cell means¶
- An empty cell means the field is absent for that case.
payment-chequeabove has noexpect.mentions, so the criterion that checks the key fact has nothing to check there and passes it. - Text is text:
Forgot password,I forgot my password. How do I get back.... - A cell that reads as JSON is that value:
12and42.5are numbers,trueandfalseyes and no,["mug", "plate"]a list,{"id": "A-17"}an object. Soexpect.refundholdingtrueis a yes, not the word "true". - To keep something that looks like a number as text (a postcode, an order number such as
00123or12345), write it in double quotes in the cell:"12345".
Nested fields¶
A dot inside the field name nests: the columns brief.order.id and brief.order.total give
the brief {"order": {"id": "A-17", "total": 42.5}}. Fill in a field or the fields inside it
on one row, not both: brief.order and brief.order.id on the same row are refused.
Tags, and running a part of the cases¶
Tags choose cases. gvn eval run ... --only smoke runs the cases tagged smoke; --only
refunds,smoke those with either tag; --only password-reset,refund-damaged those two cases by
id. Tags and ids can be mixed. To make a choice permanent, put it in the eval file:
only = ["smoke"].
Useful tags: smoke for a handful of cases that check the wiring in seconds, one tag per area
of the product (refunds, delivery), ambiguous for cases where people disagree on the
right answer, and one tag per bug that a case was written for.
Several acceptable answers¶
A reply can say the same fact in different words: "seven to ten working days" or "7 to 10
working days". The support desk's criterion key_fact accepts every way listed in
expect.mentions, separated by |:
delivery-abroad,answer,Dana,I am ordering from abroad. How long does international delivery take?,answer,seven to ten|7 to 10|7-10
The reply passes when it contains any one of them, in any case of letters. What a cell means
is decided by the criterion that reads it, so | means "or" for this criterion because its
developers wrote it that way. When you need a convention like this for your own criteria, agree
it with the developers who write them.
Saving from a spreadsheet¶
Save or export as CSV UTF-8. gvn reads a file a spreadsheet program saved as it is (with the marker some programs put at the start, with either kind of line end), and ignores rows whose cells are all empty. A cell may hold several lines.
When a file cannot be used, gvn says where and what to change, and runs nothing:
support.cases.csv: row 1, column 6 ('expected.mentions') is not a column of a cases file; the columns are case_id, tags, brief.<field> and expect.<field>. Rename or delete this column.
support.cases.csv: row 14: the case_id 'tracking' is already used in row 6; every case needs its own id.
A cases file in JSONL¶
The file is named <name>.cases.jsonl: one case per line, written as a JSON object. Blank lines
are skipped. Use it when cases hold long or deeply nested data, or when another program writes
them:
{"case_id": "password-reset", "tags": ["answer", "smoke"], "brief": {"customer": "Ada", "question": "I forgot my password."}, "expect": {"route": "answer", "mentions": ["Forgot password"]}}
{"case_id": "refund-damaged", "tags": ["human"], "brief": {"customer": "Mona", "question": "My blender arrived cracked."}, "expect": {"route": "human"}}
case_id and brief are required; expect and tags may be left out. In JSONL, several
acceptable answers are naturally a list, and the support desk's key_fact accepts a list too.
Adding and editing cases in the web page¶
gvn eval serve opens a local page whose Cases view lists the cases files of the project.
Pick a file to see its cases in a table you can filter by name, tag or text. Add a case
opens a form:
- What the harness is given: one input per brief field the file already uses; Add another field adds one;
- Case name: the
case_id, filled in for you from the first text field until you change it; - What a good result looks like: one input per expect field;
- Tags: type a tag, then Enter.
A value typed in a field is read as a CSV cell is: text that reads as JSON is that value, the rest is text. A field that already holds text stays text. Saving writes the same file you would edit by hand, keeping its column order and adding a column for a new field; editing a case keeps its place in the file, and changing its name renames it. A case can be deleted, but not the last one of a file. The page is described in full in The web page.
Changing cases and earlier runs¶
An eval run remembers exactly which cases it ran. Two runs can be compared only when they ran the same cases, so after you add, change or remove a case:
- run every version you want to compare again, on the new cases;
- give those runs a new name with
--name, since the old name holds a run of the old cases.gvn eval run ... --version baseline --name support.baseline.2starts one; running under the old name is refused with a message that says the cases changed and suggests a free name (a run remembers its cases, criteria, version, number of trials and models); - the old runs stay readable with
showand comparable with each other.
For developers: what a file reads as¶
gvn.adapters.eval_files.read_cases reads a cases file the way gvn eval does. This example
writes a small CSV and prints what each row became:
import pathlib
from gvn.adapters.eval_files import read_cases
pathlib.Path("orders.cases.csv").write_text(
"case_id,tags,brief.customer,brief.order.id,brief.order.total,brief.items,expect.refund\n"
'late-parcel,refunds smoke,Ada,A-17,42.5,"[""mug"", ""plate""]",true\n'
'postcode,,Ben,"""12345""",12,,false\n'
)
for case in read_cases(pathlib.Path("orders.cases.csv")):
print(case.to_plain())
# {'case_id': 'late-parcel', 'brief': {'customer': 'Ada', 'order': {'id': 'A-17', 'total': 42.5}, 'items': ['mug', 'plate']}, 'expect': {'refund': True}, 'tags': ['refunds', 'smoke']}
# {'case_id': 'postcode', 'brief': {'customer': 'Ben', 'order': {'id': '12345', 'total': 12}}, 'expect': {'refund': False}, 'tags': []}
The doubled quotes are how CSV writes a quote inside a cell; in a spreadsheet you type
["mug", "plate"] and "12345". write_cases, add_case, replace_case and remove_case in
the same module are what the web page uses to change a file.
Recap¶
- One case per row:
case_id,tags,brief.<field>for what the harness is given,expect.<field>for what a good result looks like. - A cell that reads as JSON is that value, anything else is text, an empty cell is absent; a dot in a field name nests.
--onlyandonly = [...]run cases by tag or id. After changing cases, run again under a new--name.
Next: Writing criteria, to say what a good trial is.