Data sources for a dataset: real logs, expert-written cases, synthetic data

Study time
≈ 1.5 h (estimate)
Needs
L2-M01-L05
Updated
2026-11-03

Progress is saved in this browser only. No account, nothing is sent to a server.

Draft · reviewed by AI, not yet by a person. Content may change. English translation: AI-assisted, not human-reviewed.
On this page

Module: L2-M02 · Duration: ~90 min (estimate, including the independent exercise) · Previous: L2-M01-L05 · Next: L02

1. Introduction

In L2-M01 you wrote an evaluation strategy: which criteria to measure, what thresholds, what "enough data" means. That strategy still has a gap: where the data comes from. This module fills the gap with a versioned, documented evaluation dataset that can withstand the question "why is this set representative of what you are about to release?".

The first lesson answers a question people often skip: where does a case come from, and in which direction does that source skew the measurement? There are three main sources: real production logs (actual user messages), cases written by hand by experts, and synthetic data (generated by a model or a script). No source is neutral. This lesson teaches you to name the bias of each source, to sample from a log without adding bias of your own, and to handle personal data. The product of the lesson is a source plan with a privacy note.

2. Learning objectives

  1. Distinguish the three dataset sources and state the characteristic bias of each.
  2. Take a subset (a sample) from a log in three ways and explain why only random sampling does not add bias of its own.
  3. Write a source plan with shares, sampling method, known biases and a privacy note, then check it with a validator.
  4. Run a PII (personally identifiable information) screen using a regex (character pattern matching) and point out what it misses.
  5. Choose among three ways of handling personal data: redact, replace with made-up data (pseudonymise), or exclude, and state the cost of each.

3. Prerequisites and tools

  • L2-M01-L05: the strategy and decision rules. This lesson supplies the data for them.
  • L2-M01-L04: sample size and confidence intervals. This lesson only asks whether the data is representative, before asking whether there is enough of it.
  • L1-M06-L03: the golden dataset from Level 1, extended here.
  • The code lab code-labs/l2-m02, installed following its README: it needs only pytest, no API key, costs nothing, and is independent of l2-m01.

4. Concepts

4.1 Three sources, three biases

A case in a dataset is an input (with its expectation) that you will run through the system. It comes from three places.

Source What it is Advantage Characteristic bias
Production Real messages from the product log Reflects how real users write: typos, no diacritics, mixed with English Only people who already use the product; missing situations nobody has tried; contains personal data
Expert-written Invented by teachers, QA, domain experts Targets hard cases, edge cases, adversarial cases; controls the expectation Invents situations harder than real users meet, in an expert's writing style
Synthetic Generated in bulk by a model or script Cheap, fast, covers many variants Uniform, often easier than real, may carry wrong labels (L04)

Public guidance recommends combining sources rather than picking one. OpenAI lists synthetic, domain-specific, purchased and production data as parallel options, and advises "Log as you develop so you can mine your logs for good eval cases" [R2]. Anthropic advises starting from "the manual checks you run during development" and says "Converting user-reported failures into test cases ensures your suite reflects actual usage" [R1]. Anthropic's eval documentation says "design evals that mirror your real-world task distribution" and not to forget edge cases [R3]. OpenAI names an anti-pattern: a dataset that does not faithfully reproduce production traffic [R2]. Each source answers a different question; a good dataset is a deliberate combination.

4.2 A source is not a distribution: how to sample from a log

Having a log does not mean having a representative sample. How you take from the log determines the bias you add. The lab has a fictional log of 600 messages over 30 days from HocVui Tutor (the tutor is a chatbot that helps students in grades 3-5 with math). Each message has an intent label: hint (asks for a hint on an exercise), check (asks to check their work), concept (asks about a concept), offtopic (off topic) and pii (the student sends personal information). The intent pii (24 messages, 4%) is different from "messages containing PII" (46 messages, 7.7%): a hint message can also contain Mom's phone number. Three common ways to sample:

  • Random: every message has the same probability of being chosen. Only this method adds no bias of its own.
  • The first messages (first): quick, but it reflects only the first few days. The lab's log simulates a new school term: the first week has more concept questions, and the "first" sample inherits exactly that skew (the first 100 messages: concept 0.24 versus 0.137 for the whole log, hint 0.38 versus 0.508, pii 0.11 versus 0.040; offtopic unchanged, 0.06).
  • Only thumbs-down messages: attractive because "this is where it fails", but it is a sample of the people who clicked. It measures "how bad failures are when someone complains", not "how often it fails".

The NIST AI RMF asks for accuracy to be measured with "clearly defined and realistic test sets – that are representative of conditions of expected use" [R4]. The word "representative" is where the thumbs-down sample fails.

4.3 Personal data is a risk of the dataset itself

Real logs contain phone numbers, emails, names and addresses that users typed in, often children. Copying a message into a dataset duplicates that data into a repo, a CSV file, a spreadsheet shared with colleagues, sometimes even a third party's eval tool.

NIST AI 600-1 describes the "Data Privacy" risk as the impact of "leakage and unauthorized use, disclosure, or de-anonymization of biometric, health, location, or other personally identifiable information or sensitive data" [R5]. Article 5(1) of the GDPR sets two related principles: collection for "specified, explicit and legitimate purposes", and data that is "adequate, relevant and limited to what is necessary" [R6]. This lesson is not legal advice, and it has not verified Vietnamese law texts; what applies to you depends on the law where you operate (see §6.1).

5. Technical deep dive

5.1 The source plan and what the validator checks

A source plan is a JSON file listing each source: name, kind (production, expert, synthetic), share (share), sampling method, known bias (known_bias) and, for a production source, a privacy block with handling, legal_basis and retention_days (how many days the data is kept).

lab.sources.validate_source_plan(plan) returns a list of problems. It checks: there is at least one source; the kind and sampling method are valid; share is a number in (0, 1] and the shares sum to 1; every source has a non-empty known_bias; a production source has all three privacy fields; and not every source is synthetic (otherwise nothing ties the dataset to real traffic).

It does not check what matters more: whether the legal basis is real, whether the retention period is enforced, whether the bias you wrote down is correct. It catches a plan that is missing or contradictory, not one that is wrong; say so, rather than letting the reader believe "validator passes means a good plan". The tests pin the boundaries: a share of 0, a negative share, True (Python treats True as the number 1) and a string are all rejected.

5.2 Screening PII with a regex, and what it misses

lab.pii looks for four things: Vietnamese mobile numbers (10 digits, starting 03, 05, 07, 08 or 09, accepting spaces, dots, dashes or a +84 prefix), emails, 12-digit national ID numbers, and names in an introduction such as "em tên là Nguyễn Văn An" (the words "tên" and "là" may lack diacritics, but the name must be capitalised). redact replaces each with a label such as [PHONE] and counts them; running it again on the result changes nothing.

More important is the list of things it does not find, each pinned by a "blind spot" test: home addresses; phone numbers spelled out in words; names without an introduction or with the order inverted ("Tên em là Nguyễn Văn An"); names written entirely in lowercase ("em ten la nguyen van an"); numbers split by other words; numbers written "84912345678" (missing the +), with two spaces, with parentheses "(091) 234 5678", or an ID number split into groups "0011 2233 4455"; landline numbers; anything inside an image. It also gives false alarms: a 12-digit quantity in a math problem gets labelled as an ID number. A regex screen reduces risk; it is not proof of "clean". The lab measures this on the log: 50 PII items were planted in 46 messages; the screen finds 42 items (38 messages) and misses 8 items (addresses and numbers spelled out in words), with no false alarm on any message in this log.

5.3 Redact, replace with made-up data, or exclude

Approach What it does What you gain What you lose
Redact Replace with a label [PHONE] Cheap, keeps the rest of the case The case changes meaning: the tutor cannot "repeat the phone number" when it is [PHONE], so that behavior can no longer be checked
Pseudonymise Replace with made-up data of the same shape (for example 0900000001) Keeps the behavior you need to check You must be sure the made-up data does not match a real person; the screen still flags it (needs a justified exception, L05)
Exclude Drop the message entirely Lowest risk Lose coverage: no case is left about a student sharing personal information

For the case "a student sends their mother's phone number", the reasonable choice is not to take it from the log but to rewrite it as an expert case with made-up data, exactly like cases E20-E23 in data/expert_cases.jsonl. The source is then expert, and the source plan should say so.

6. The QA perspective

6.1 Four questions QA asks about each source

  1. Whom does this source represent? People who signed up, or everyone? Only this month, or all year? Write it into known_bias.
  2. What is the sampling method, and who chooses? Random with a recorded seed can be verified; "I picked a few messages that looked good" cannot.
  3. What personal data could slip through? Including the kinds the screen does not look for. For a dataset with children, treat everything missed as a hazard until a person has checked by hand.
  4. Do you have the right to use this data for evaluation? The answer comes from the terms users agreed to and from the law; that is a matter for the legal team. This lesson has no Vietnamese law source that was read, so confirm the current text with someone qualified. The GDPR retention limit is an example of the kind of constraint you need to look for in your own law [R6].

6.2 Reporting the source, the bias and the limits

A good source report states the share of each source, the sampling method and seed, the known biases, what the screen catches and what it does not catch, and the handling decision. For example: "30% a random sample from the 30-day log with PII redacted by a four-kind screen (does not catch addresses or numbers spelled out in words; checked by hand), 50% cases written by teachers (skewed toward hard cases), 20% synthetic cases that were filtered."

Flow diagram: the production log (random sample) goes through PII screening and a manual look, then into the dataset with a source plan; expert-written cases go straight into the dataset; filtered synthetic cases (L04) also go into the dataset; from the dataset, the bias of each source is recorded.
Diagram: Reporting the source, the bias and the limits

7. Real-world scenarios

Scenario 1 (fictional): "Only take the failing cases". The HocVui Tutor team picked 30 thumbs-down messages as the dataset because "that is where the product is wrong". On this sample the simulated system has a true pass rate of 0.793, while the whole log is 0.876, and the pii group makes up 0.23 of the sample (versus 0.040 in the log). The team reported "the system is only right 79% of the time" to leadership: true for the sample, but misread as a rate for all users.

Scenario 2 (fictional): A "clean" dataset that is not clean. A team filtered PII with a regex, saw "no phone numbers left", and shared the dataset with a vendor. The dataset still contained home addresses and a phone number spelled out in words. "PII filtered" is not "no PII left", and sharing data externally is an action that needs its own approval.

8. Hands-on tutorial

8.1 Setup

cd academy-content/code-labs/l2-m02
python3 -m venv .venv && source .venv/bin/activate     # Windows: .venv\Scripts\activate
python -m pip install -r requirements.txt
python -m pytest            # 73 passed

8.2 Run the demo

python -m lab.demo l01

Output (copied from a real run on Python 3.14.6 and 3.12.14, 2026-11-03; the two versions give identical output):

A. the production log (fictional): 600 messages, 30 days
   check    0.255
   concept  0.137
   hint     0.508
   offtopic 0.060
   pii      0.040
B. PII screening of the whole log
   texts with a finding: 38/600  by kind: {'email': 3, 'id': 7, 'name': 6, 'phone': 26}
   known PII planted in the log, and how much the detector finds:
   address        0/6
   email          3/3
   id             7/7
   name           6/6
   phone          26/26
   spelled_phone  0/2
C. three ways to take messages from the log, and the pass rate the system truly has on each sample
   whole log      0.876
   random       n=100  true pass rate 0.875  concept 0.18 pii 0.07
   first        n=100  true pass rate 0.868  concept 0.24 pii 0.11
   thumbs_down  n=30  true pass rate 0.793  concept 0.07 pii 0.23
D. source plans
   source_plan_example.json: 0 problem(s)
   source_plan_draft.json: 5 problem(s)
     - Nhật ký hội thoại 30 ngày: privacy.handling must be one of ('redact', 'pseudonymise', 'exclude')
     - Nhật ký hội thoại 30 ngày: privacy.legal_basis is empty
     - Nhật ký hội thoại 30 ngày: privacy.retention_days must be a positive integer
     - Ca viết tay bởi giáo viên: known_bias is empty (every source has one)
     - shares sum to 1.100, not 1
E. a message before and after redaction
   Em tên là Đặng Quốc Bảo, số của mẹ em là 0518914718. Mỗi hộp có 22 quyển vở. 6 hộp có bao nhiêu quyển vở?
   Em tên là [NAME], số của mẹ em là [PHONE]. Mỗi hộp có 22 quyển vở. 6 hộp có bao nhiêu quyển vở?

Reading the output:

  • A. The fictional log: 600 messages, hint makes up half, pii only 4%. A small group but high risk; L02 explains why small groups are easily overlooked.
  • B. The screen finds 42 of the 50 planted PII items; addresses (0/6) and numbers spelled out in words (0/2) are never seen. This is the result of a four-kind screen, not of every screen.
  • C. The simulation knows the failure probability, so it can compute the true pass rate: 0.876 on the whole log; 0.875 on a random sample of 100 messages; 0.868 on the first 100 messages (concept group 0.24, versus 0.137 for the log); 0.793 on the thumbs-down sample. With a real system you do not know the true rate, which is why you need a representative sample.
  • D. The example source plan has no problems; the draft has 5.
  • E. One message before and after redaction.

8.3 Screen three messages of your own

Save this file as try_l01.py inside the lab folder:

from lab import pii, sources

texts = ["Em tên là Lê Minh Khang, số của bố em là 0933 111 222.",
         "Nhà em ở số 9 đường Trần Phú.",
         "Mỗi hộp có 12 cái bánh. 5 hộp có bao nhiêu cái bánh?"]
for t in texts:
    out, counts = pii.redact(t)
    print(counts, "|", out)

plan = sources.load_json("source_plan_example.json")
print(sources.validate_source_plan(plan))
plan["sources"][2]["share"] = 0.3
print(sources.validate_source_plan(plan))

Run python try_l01.py. Output:

{'name': 1, 'phone': 1} | Em tên là [NAME], số của bố em là [PHONE].
{} | Nhà em ở số 9 đường Trần Phú.
{} | Mỗi hộp có 12 cái bánh. 5 hộp có bao nhiêu cái bánh?
[]
['shares sum to 1.100, not 1']

The second message contains an address but is not flagged: that is a blind spot.

8.4 Run the lesson's tests

python -m pytest tests/test_l01_sources.py -v

Result: 24 passed. Read test_known_blind_spots_are_not_detected: it pins the limits above, so that whoever changes the regex later notices when a limit changes.

8.5 Troubleshooting

Symptom Cause Fix
ModuleNotFoundError: No module named 'lab' Ran the script outside the lab folder Put try_l01.py in code-labs/l2-m02 and run it from there
A valid phone number is not found The prefix is not 03, 05, 07, 08, 09, or the number of digits is not 10 This is the screen's intended scope; landline numbers are not searched
validate_source_plan reports shares sum to ... The shares do not sum to 1 Adjust the share of the last source

9. Independent exercise

Problem: Build a source plan for a 3-source pilot and measure the PII screen on a set of lines labelled by a person.

Requirements: complete exercises/test_l01_sources.py and exercises/my_source_plan.json:

  1. TODO 1: write my_source_plan.json so that validate_source_plan returns an empty list, the production sources have a total share ≥ 0.5, expert ≥ 0.2 and synthetic ≤ 0.2.
  2. TODO 2: fill in RECALL: for each PII kind in the labels of pii_lines.json, record (the number of lines where the screen finds that kind, the number of lines that have that kind). Use lab.pii.find, do not guess.
  3. TODO 3: fill in BLIND_KINDS: the set of kinds the screen finds on no line.

Test data: exercises/pii_lines.json (10 fictional lines with "truth" labels assigned by a person).

Deliverable: the corrected my_source_plan.json, plus the filled-in RECALL and BLIND_KINDS.

Acceptance criteria: python -m pytest exercises/test_l01_sources.py passes (3 tests); no TODO text is left in my_source_plan.json.

Hint: each production source needs all three privacy fields; do not "fix" the screen to make it pass, because some kinds in the labels are kinds it was designed not to find.

10. Knowledge check

0/16 done · Results are kept in this browser only.

P02 · True or false

Taking only the thumbs-down messages from the log tells us how often the system fails.

P04 · Select all that apply

With the lesson's four-kind lab.pii screener, which cases are not found? Select all that apply.

P05 · Put in order

Put the steps in order to bring a log sample into the dataset without adding bias yourself and without carrying personal data along.

  1. A person looks at a sample by hand to find what the screener missed
  2. Write into the source plan the proportion, the sampling method, the bias and the screener's limits
  3. Run the PII screener and redact the entries it finds
  4. Draw a random sample from the 30-day log, record the seed
  5. Run validate_source_plan on the plan

P06 · Match

Match each dataset source to its characteristic bias.

P07 · Spot the bug

The production source block below is taken from source_plan_example.json but with one spot changed. With this plan, validate_source_plan reports one problem. Find the bug.

{
  "name": "Nhật ký hội thoại 30 ngày",
  "kind": "production",
  "share": 0.3,
  "sampling": "stratified",
  "known_bias": "Chỉ gồm học sinh đã dùng sản phẩm; phản ánh cách viết hiện tại.",
  "privacy": {
    "handling": "redact",
    "retention_days": 90
  }
}

P08 · Short answer

Write one source line in the report for HocVui Tutor's 3-source dataset so that the reader also knows what the screener does not catch.

P09 · Essay

A student sends "số của mẹ em là 0518914718" (Vietnamese: "my mom's number is" followed by a phone number) and you want to keep this case to check that the tutor does not repeat the phone number. Write 5-8 sentences: choose between redact, pseudonymise and exclude, state what the choice gains and loses, and the source of the case after processing.

P10 · Multiple choice

In the demo, the first 100 messages of the log have concept at 0.24 versus 0.137 for the whole log. Why is the "first messages" sample skewed?

P11 · True or false

If validate_source_plan returns an empty list, the source plan is good.

P12 · Select all that apply

Which of the following does validate_source_plan check? Select all that apply.

P13 · Fill in the blank

On the fictional log, the simulated system has a true pass rate of ___ on the whole log, ___ on the random sample of 100 messages and ___ on the sample of 30 thumbs-down messages.

P14 · Recall

Lesson: L2-M01-L04

This lesson asks whether the sample is representative before asking whether it is enough. L2-M01-L04 §4.3 has already answered "enough": to conclude "the failure rate is below 5%" just by seeing every case pass, what is the minimum number of cases?

P15 · Recall

Lesson: L1-M06-L03

A case in the golden dataset of L1-M06-L03 has a source field. What is that field for, and what is the equivalent in this lesson's source plan?

11. Summary

  • Concepts: three sources, each with its own bias; the way you sample from a log adds bias; personal data is a risk of the dataset itself; redacting, replacing with made-up data and excluding all have a cost.
  • Skills: write and check a source plan; sample a log randomly; screen PII and state what it misses.
  • Traps: treating a thumbs-down sample or "the first messages" as representative; treating "PII filtered" as "no PII left"; treating a passing validator as a good plan.
  • You can now: ask of every case: where does it come from, who chose it, what bias comes with it, what personal data could slip through.

12. References

ID Title Publisher URL Accessed Relevance
R1 Demystifying evals for AI agents Anthropic https://www.anthropic.com/engineering/demystifying-evals-for-ai-agents 2026-11-03 Start from manual checks and user-reported failures
R2 Evaluation best practices OpenAI https://developers.openai.com/api/docs/guides/evaluation-best-practices 2026-11-03 Eval data sources; logging; anti-patterns
R3 Define success criteria and build evaluations (Develop tests) Anthropic https://platform.claude.com/docs/en/test-and-evaluate/develop-tests 2026-11-03 Evals that mirror the real distribution; edge cases (read the first 100,000 characters)
R4 NIST AI 100-1: Artificial Intelligence Risk Management Framework (AI RMF 1.0) (January 2023) NIST https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.100-1.pdf 2026-11-03 Test sets representative of conditions of use
R5 NIST AI 600-1: Artificial Intelligence Risk Management Framework: Generative Artificial Intelligence Profile (July 2024) NIST https://nvlpubs.nist.gov/nistpubs/ai/NIST.AI.600-1.pdf 2026-11-03 Definition of the Data Privacy risk
R6 Art. 5 GDPR: Principles relating to processing of personal data gdpr-info.eu (unofficial reproduction) https://gdpr-info.eu/art-5-gdpr/ 2026-11-03 Article 5(1)(b), (c), (e): an example of constraints, not legal advice

Key terms (English ↔ Vietnamese)

English Tiếng Việt
Evaluation dataset Bộ dữ liệu đánh giá
Case Một đơn vị kiểm tra: input kèm kỳ vọng
Source plan Kế hoạch nguồn dữ liệu
Production log Log từ môi trường thật
Synthetic data Dữ liệu tổng hợp
Intent Ý định của người dùng (loại câu hỏi)
Representative sample Mẫu đại diện
PII Thông tin định danh cá nhân
Redact / Pseudonymise / Exclude Ẩn / thay bằng dữ liệu bịa / loại khỏi dataset
Blind spot Điểm mù của công cụ