Messy Data Into Records With Low-Confidence Flags
How to turn a messy take-home data file into clean records, with flags on every value you are not sure of, explained for your AI interview.
In short
Read the messy export with rules wherever a rule can check the value, and use a model only for free-text notes. Each value that cannot be confirmed gets a flag with its reason and goes to a person, never a quiet guess.
12 min readIntermediateCommon · estimateFacts checked 27 November 2026
Say it out loud
Read it once, then say it without looking. Start with the short one; use the long one when they ask you to go deeper.
A take-home like this gives you a messy file and asks for clean records. I'd write a schema first, so every field has a type. Rules in code read the dates, numbers and ids, because a rule can check them. A model only reads the free-text notes. Anything I can't confirm gets a flag with a reason and goes to a person. I never fill a gap quietly. Then I'd measure the flags on a small hand-checked sample, so I can say how often they're right.
A take-home like this gives you a messy export and asks for clean records back. A record is one row per thing, with every field in the right type. Before writing any code, I'd write the schema: the fields, their types, which ones can be empty, and the allowed values. I'd keep the raw text beside each parsed value, so anyone can see what was actually typed.
Then I'd split the work by what can be checked. Dates, numbers and ids go through rules in code. A rule can tell that a date like 30 February is impossible, or that an id appears twice. A model only reads the free-text notes, where rules can't help. Each row gets a list of flags, and each flag gives its reason, such as a weight that isn't a number. I never write a guess as if it were a reading. A guessed value gets its own flag.
Flagged rows go to a review queue with the raw line beside them, so a person can decide in seconds. I wouldn't trust a model's confidence number on its own. Those scores only mean something if they're calibrated, and you can only check that against labelled examples.
So I'd hand-label a small sample, count the flags that were right, and count the errors that slipped through. Then I'd report both numbers in the README, with the limits, so the reviewer sees where the work is uncertain.
What is a take-home like this, in plain words?
A take-home like this gives you a messy file and asks for clean records back. A record is one row per thing, with each field in the right type: an id is text, a weight is a number, a date is a real date. Messy means typos, mixed date formats, repeated rows and blank cells.
Think of a claims clerk at an insurer who types handwritten forms into a system. The clerk enters what they can read and check. For anything unclear, they stick a note on the row saying what is wrong, and a senior clerk looks at it. They do not guess quietly.
The made-up case here is a freight company with 12,000 delivery notes from three depot systems. Drivers typed the notes, and each depot exports them in its own format. The reporting team needs one clean record per shipment.
Key words
- Schema
- The list of fields for each record, with their types, allowed values and whether they can be empty.
- Flag
- A note on one value saying why it is not trusted, such as an impossible date.
- Provenance
- Where a value came from: the file, the line and the raw text as it was typed.
- Review queue
- The flagged rows a person checks, with the reason shown beside each one.
- Free text
- Words typed by people, like a driver's note, which rules cannot check well.
What should the records look like?
Write the schema first. Every field has a type, a rule for empty values, and a list of allowed values where one applies. Keep the raw text beside each parsed value. Without it, a reviewer cannot see what was typed, and cannot tell a parsing mistake from a real error.
- Loose
Store whatever came in
Keep every field as text and clean it later. Nobody can say which rows were checked.
- Schema first
Typed fields, raw copy kept
Each field has a type and a rule. Each value keeps its raw text, so a flag can point at it.
Use rules wherever a rule can check the value. OpenAI says its structured outputs constrain the model's output to a JSON schema you supply, and that your application still has to validate the business rules the schema does not express. The take-home works the same way: the schema fixes the shape, and code checks the rules.
“Your application still needs to handle refusals, incomplete responses, and API errors, and validate any business rules that the schema does not express.”
OpenAI
“When imputing missing values, use reliable methods like mean/median imputation and consider adding an indicator column to signal imputed values to the model.”
Google
From a messy export to records
Messy export
three depot files, made-up
Two readers
Rules read each field
dates, numbers and ids
Model reads the notes
free text only
Checks in code
Run every check
ids, dates, weights, duplicates
Result
Flagged for a person
with the reason shown
Clean record
every check passed
- 1Each line is read by fixed rules.
- 2The free-text notes also go to a model.
- 3Parsed fields go on to the checks.
- 4The model's reading goes to the same checks.
- 5A failed check sends the row to a person, with the reason.
- 6A row that passes every check becomes a clean record.
Google's ML course lists the usual problems in a dataset: omitted values, duplicate examples, out-of-range values and incorrect labels, which can hurt model performance. In a take-home, omitted values, duplicates and out-of-range values show up as flags. Incorrect labels only show up when someone checks a sample by hand.
How do you decide what gets flagged?
Flags come from evidence you can check. These are the checks I'd run, in order. Each one either passes or adds a flag with its reason.
Parse each field by rule
Read dates, numbers and ids with a fixed rule. If the rule fails, keep the raw text and flag the field. The date rule flags every slash date, even 13/03/2026, because the text alone does not say which part is the day.
Check inside the row
A date can have the right shape and still be impossible. 30 February fails the calendar, so the rule flags it.
Check across rows
A repeated id is a duplicate, even when every value in the repeat looks fine.
Mark every guess
If you fill a gap, store the guess with a flag saying it was filled. Google's crash course suggests the same idea for training data: an extra column that marks imputed values.
Send flags to a person
The review queue shows the row, its flags and the raw text together, so the fix takes seconds.
Passing checks mean the rules held. They do not prove the record is true. That is why the sample check later matters. Here is the rule-based part in plain Python. Five made-up rows go in, and each one gets flags or passes.
import re
from datetime import date
# Made-up delivery notes from three depot exports, before any cleaning.
RAW = """SH-1041 | 12.5 kg | 2026-03-04 | Leeds
SH-1042 | 1,2O0 kg | 2026-03-05 | Leeds
SH-1043 | 8 kg | 05/03/2026 | Bristol
SH-1041 | 12.5 kg | 2026-03-04 | Leeds
SH-1044 | 40 kg | 2026-02-30 | Leeds"""
records, seen = [], set()
for line in RAW.splitlines():
sid, weight, day, depot = [part.strip() for part in line.split("|")]
flags = []
if sid in seen:
flags.append("duplicate id")
seen.add(sid)
kg = weight.replace(" kg", "").replace(",", "")
if not re.fullmatch(r"\d+(\.\d+)?", kg):
flags.append("weight is not a number")
if re.fullmatch(r"\d{2}/\d{2}/\d{4}", day):
flags.append("ambiguous date")
else:
try:
date.fromisoformat(day)
except ValueError:
flags.append("impossible date")
records.append((sid, kg, day, depot, flags or ["ok"]))
for sid, kg, day, depot, flags in records:
print(sid, "|", "; ".join(flags))Output
SH-1041 | ok SH-1042 | weight is not a number SH-1043 | ambiguous date SH-1041 | duplicate id SH-1044 | impossible date
Notice the second SH-1041 row. Its values look fine on their own. Only the check across rows catches it.
Why not trust the model's own confidence number?
Some models give a score next to each answer. Treat it with care. A score is only worth something if the model is calibrated, and scikit-learn's guide says a well calibrated classifier's output can be read directly as a confidence level. You can only check calibration against labelled examples.
“For scenarios where accuracy is critical, confidence can be used to determine whether to automatically accept the prediction or flag it for human review.”
Microsoft Azure
“Well calibrated classifiers are probabilistic classifiers for which the output of the predict_proba method can be directly interpreted as a confidence level.”
scikit-learn
Azure's own guide adds a warning: its accuracy can be inconsistent when your documents differ from the ones it was trained on. So a flag cannot lean only on a score the model gives. Anthropic's guide takes a similar line for language models: it says to give the model permission to admit uncertainty, and in its press-release example the model must retract any claim it cannot back with a quote from the source documents.
So I'd measure the flags myself. Here is a made-up result for 200 hand-checked rows. 40 rows were flagged, and 31 of those were really wrong, so 9 flags were false alarms. Six wrong rows were never flagged at all.
Checking the flags on a sample
200 rows hand-checked
a person, made-up sample
Compare
Rows the system flagged
40 flagged, made-up
Errors not flagged
6 missed, made-up
Tune rules and checks
then measure again
Two numbers to report
flags right, and errors missed
- 1Compare every flag with the hand label.
- 2Look for errors that nobody flagged.
- 3Fix rules that flag too much.
- 4Fix checks that let errors through.
- 5The measured results become the two numbers in the report.
Report both numbers. Tuning the rules usually moves one against the other: stricter rules flag more and miss less, but they add work for the reviewer. Say which way you chose and why.
How would you present this to the reviewer?
Send a short README with the code. A reviewer wants to see where the work is uncertain more than how clever it is.
Counts
Rows in, rows clean, rows flagged, and flags by reason. Reviewers check the numbers first.
Trade-offs
What the rules read, what the model read, and why you split them that way.
Limits
What the sample did not cover, such as a depot format you never saw, and what you would check with the team next.
What does the interviewer want to hear?
A strong answer covers
- A schema first: fields, types, empty rules, and the raw text kept beside each value.
- Rules for anything a rule can check. A model only for free text.
- Flags with reasons, never a guess written as a fact.
- Checks across rows as well as inside one row.
- A small hand-labelled sample to measure the flags.
- A README with counts, trade-offs and limits.
Common traps
Trap"The model cleans the whole file."
BetterUse code for what a rule can check. Send only the free-text notes to the model.
Trap"If it looks fine, it is correct."
BetterA passing check means the rule held. Only a labelled sample shows the error rate.
Trap"I filled the gaps with the most likely value."
BetterMark each guess with a flag and keep the raw text, so nobody mistakes it for a reading.
Can you spot the problem?
Spot the best call
A driver typed 05/03/2026 on a delivery note. Which handling is the best call?
Quick check
Your checks pass for 98 per cent of rows. What does that prove?
Can you answer these from memory?
Flash cards · tap a card to flip it
What will they ask next?
- Q373Design invoice extraction.13 min
- Q387How do you deal with messy customer data?11 min
- Q399Parse a messy CSV/JSON file with edge cases.12 min
- Q448How do you extract structured data from documents and images?12 min
- Q478Parse and validate LLM JSON, retrying on failure.11 min
- Q172When and how do you add a human in the loop?12 min
Learn it in depth
Last updated on 27 November 2026
Need messy records turned into something you can trust?
I design and build AI products and agents, including the checks around them: a fixed schema, rules in code, flags for people and a measured error rate. Book a short call and tell me your files and what the records feed.