Lesson 17.2 · 2 of 5 · 4 min read · Reviewed 24 Nov 2026
Building a golden set from real traffic
By the end, you can
- Build a golden set from real traffic.
- Label expected answers or criteria for each case.
Your first ten cases (16.3) come from judgement. A golden setGolden set: A curated set of test cases with known correct answers, used as the core of an eval. grows them into a trusted test that reflects real use.
Building one
- Sample real inputs. Stratify: take some from each topic, length and user type, not just the most common.
- RedactRedaction: Removing or masking sensitive data, such as PII or secrets, before it is stored, logged or sent.. Remove names, ids, card numbers and anything personal (67.3).
- Label. For each case, write the expected answer, or the criteria a correct answer must meet. Two people labelling the same case and comparing is a good check.
- Tag. Topic, difficulty, failure bucket (17.1), date added.
- Store and version. A file in the repo next to the prompt.
Size
| Stage | Typical size |
|---|---|
| First prototype | 10 to 30 |
| Before launch | 100 to 300 |
| Mature product | Several hundred, plus focused sub-sets |
Bigger isn’t automatically better. A set full of near-duplicates gives a precise score on the wrong thing.
Labels are the hard part
If the label says the refund window is 30 days and policy changed to 60, every run now punishes the right answer. Note the source of each label so it can be updated (17.4).
Key points
- A golden set is a curated set of real inputs with trusted expected answers or criteria.
- Pick cases from real traffic to match what users actually send, and redact personal data first.
- Label carefully: a wrong label teaches you the wrong lesson every time you run the eval.
Redact and sample a golden set
Turn raw logged messages into golden-set candidates: personal data redacted, sampled across topics, tagged and ready to label.
You will have: A redact function, a stratified sampler and a list of tagged golden-set cases printed as JSON lines.
Steps
- Read the 12 simulated log entries. All names, emails, phone numbers and card numbers are fake test data.
- Complete redact so emails, phone numbers, 16-digit card numbers and the listed names are replaced with placeholders.
- Complete sample so it takes up to two entries per topic, using random.Random(7) so the sample repeats.
- Tag each case with topic, length (short or long) and the date added, and leave the label empty for a person to fill.
Done when
- No email, phone or card number survives redaction.
- Every topic in the logs appears in the sample.
- The script prints 'redaction check: clean' and one JSON line per case.
Open in the Playground No API key needed.
Starter code (Python)
import json, random, re
rng = random.Random(7)
NAMES = ["Priya Shah", "Tom Reed", "Ana Silva"]
LOGS = [ # fake test data only
("returns", "Hi, I'm Priya Shah, can I return boots from order 1042? priya@example.com"),
("returns", "Return window for sale items?"),
("returns", "Tom Reed here, my parcel came damaged, call 07700 900123"),
("billing", "Charged twice on card 4111 1111 1111 1111 (test card), please fix"),
("billing", "Why is there a delivery fee on my invoice?"),
("billing", "Refund not received yet, ana@example.com"),
("delivery", "Where is my order? It was due Tuesday."),
("delivery", "Ana Silva, courier left it in the rain"),
("delivery", "Can I change my delivery address after ordering?"),
("account", "How do I reset my password?"),
("account", "Please delete my account and data, tom@example.com"),
("other", "Do you sell gift wrapping?"),
]
def redact(text):
# TODO: replace emails with [EMAIL], UK-style mobile numbers with [PHONE],
# 16-digit card numbers (with spaces) with [CARD], and each name in NAMES with [NAME].
return text
def sample(logs, per_topic=2):
# TODO: group by topic, shuffle each group with rng, keep up to per_topic from each.
return logs[:3]
cases = []
for i, (topic, text) in enumerate(sample(LOGS), 1):
clean = redact(text)
cases.append({"id": f"gold-{i:02}", "input": clean, "topic": topic,
"length": "long" if len(clean.split()) > 8 else "short",
"added": "2026-11-24", "label": None})
leaks = [c for c in cases if re.search(r"@|\d{4} \d{4}|07\d{3}", c["input"])]
print("redaction check:", "clean" if not leaks else f"{len(leaks)} leaks")
print("topics:", sorted({c["topic"] for c in cases}))
for c in cases:
print(json.dumps(c))
Show a solution
import json, random, re
rng = random.Random(7)
NAMES = ["Priya Shah", "Tom Reed", "Ana Silva"]
LOGS = [ # fake test data only
("returns", "Hi, I'm Priya Shah, can I return boots from order 1042? priya@example.com"),
("returns", "Return window for sale items?"),
("returns", "Tom Reed here, my parcel came damaged, call 07700 900123"),
("billing", "Charged twice on card 4111 1111 1111 1111 (test card), please fix"),
("billing", "Why is there a delivery fee on my invoice?"),
("billing", "Refund not received yet, ana@example.com"),
("delivery", "Where is my order? It was due Tuesday."),
("delivery", "Ana Silva, courier left it in the rain"),
("delivery", "Can I change my delivery address after ordering?"),
("account", "How do I reset my password?"),
("account", "Please delete my account and data, tom@example.com"),
("other", "Do you sell gift wrapping?"),
]
def redact(text):
text = re.sub(r"\S+@\S+", "[EMAIL]", text)
text = re.sub(r"\b(?:\d{4} ){3}\d{4}\b", "[CARD]", text)
text = re.sub(r"\b07\d{3} ?\d{6}\b", "[PHONE]", text)
for name in NAMES:
text = text.replace(name, "[NAME]")
return text
def sample(logs, per_topic=2):
groups = {}
for topic, text in logs:
groups.setdefault(topic, []).append((topic, text))
picked = []
for topic in sorted(groups):
items = groups[topic][:]
rng.shuffle(items)
picked += items[:per_topic]
return picked
cases = []
for i, (topic, text) in enumerate(sample(LOGS), 1):
clean = redact(text)
cases.append({"id": f"gold-{i:02}", "input": clean, "topic": topic,
"length": "long" if len(clean.split()) > 8 else "short",
"added": "2026-11-24", "label": None})
leaks = [c for c in cases if re.search(r"@|\d{4} \d{4}|07\d{3}", c["input"])]
print("redaction check:", "clean" if not leaks else f"{len(leaks)} leaks")
print("topics:", sorted({c["topic"] for c in cases}))
for c in cases:
print(json.dumps(c))