esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • AI papersPages
  • Interview KitPages
  • Book a callContact
Letโ€™s talk

Iโ€™ll build the agent for it.

How Do You Deal With Messy Customer Data?

How to find the mess in customer records, clean it with rules in code, and handle what a rule can't fix, explained for your AI interview.

In short

Messy customer data has wrong, missing or repeated values. Write the cleaning rules in code, keep the raw copy, and send any row that fails a rule to a person with its reason, instead of guessing.

11 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.

Messy customer data has dates in two formats, blank values and the same customer twice. I write the cleaning rules in code, so every row gets the same checks. Rows that pass go on. Rows that fail go to a person with the reason attached. I keep the raw copy, so I can always go back, and I measure the pass rate on every run.

What is messy customer data, in plain words?

Messy data is customer information that is wrong, incomplete or inconsistent. The same fact is written in different ways, or a field is empty when it should be filled. An AI tool that reads this data gives wrong answers, so cleaning comes before the AI.

Think of a bank teller who inherits a pile of forms from three branches. One form writes the date day first, one writes it year first, and one leaves the balance blank. A good teller doesn't guess. They sort out the clear forms, and set the unclear ones aside with a note of what is missing.

A made-up but typical case: a support bot reads two records for one customer, one with an old balance, and quotes the old one. The bot is only as right as the rows it reads.

Key words

Profiling
Counting blanks, duplicates and odd values, to see the size of the mess first.
Duplicate
The same real customer stored more than once.
Imputation
Filling a missing value with a reasoned guess.
Review queue
Rows the rules cannot fix, held for a person to decide.

What kinds of mess do you find?

Most customer data has the same few problems. Knowing the list tells you where to look first.

  • Missing values

    An empty balance, a blank postcode, a date of birth left out.

  • Duplicates

    One customer under two IDs, or one row copied twice in an export.

  • Mixed formats

    Dates as 03/04/2019 and as 2019-04-03 in the same column.

  • Impossible values

    A date of 31 February, or an age of 212.

  • Free text

    Call notes with typos, shorthand and two names for one product.

Fix with a rule, or ask a person

A messy value

a date, amount or ID that is off

A rule can fix it

Standardise the format

one date style, one number style

A person must decide

Impossible value

31 February cannot exist

Missing value

could be zero, unknown or an error

Clean row

loads into the clean table

Review queue

a person's decision is logged

  1. 1A value that one rule can put right goes to that rule.
  2. 2An impossible value cannot be guessed, so it goes to a person.
  3. 3A missing value could mean several things, so a person decides.
  4. 4A fixed value, in one agreed format, becomes a clean row.
  5. 5The impossible value waits in the queue with its reason.
  6. 6The missing value waits in the queue too, until someone decides.
Each kind of mess takes one of two paths. A rule fixes what has one agreed right answer, such as a date format. A person decides what has no single right answer, such as an impossible date or a blank balance that could be zero.

Tip

Ask the owner which fields matter most before you start. A typo in a postcode is annoying. A wrong balance can cost real money.

How do you clean it without losing track?

Each step is small, and each one leaves a trail. The raw export stays as it was, so anyone can check what changed and why.

  1. 1

    Copy the raw data first

    Keep the export unchanged. Every later step reads from the copy, so you can always go back.

  2. 2

    Profile before you touch it

    Count blanks, duplicates and impossible values for each source. Show the numbers to the owner.

  3. 3

    Write the rules in code

    Each rule is one named check. The same rules run on every row, every time, so they can be tested.

  4. 4

    Split passes from fails

    Rows that pass go to the clean table. Rows that fail are kept, each with a reason.

  5. 5

    Send the rest to a person

    The review queue lists each row and its reason. A person fixes it or confirms it can go.

  6. 6

    Measure and repeat

    Track the pass rate, the share of rows that pass every rule, on every run. A falling rate often means a new source has a new problem.

How messy rows are cleaned

Branch exports

dates, amounts and IDs disagree

Rules in code

the same checks for every row

Each row

Passes every rule

goes on to the table

Fails a rule

a reason is attached

Clean table

ready for the customer file

Review queue

a person fixes or drops it

  1. 1Each export is read as it is, with no edits.
  2. 2Rows that pass every rule carry on.
  3. 3A gap, a repeat or a bad value is caught here.
  4. 4Clean rows are loaded into the customer file.
  5. 5Failed rows wait in the queue, with their reason.
Raw rows enter once and pass through the same rules. Passing rows reach the clean table. Failing rows wait in the queue with a reason, so nothing disappears quietly.
  • โ€œCommon data problems include omitted values, duplicate examples, out-of-range values, and incorrect labels, which can negatively impact model performance.โ€

    Google, Machine Learning Crash Course

  • โ€œmeasure and monitor the quality of your data so that you can make good business decisions.โ€

    AWS, on its data quality service

  • โ€œFor various reasons, many real world datasets contain missing values, often encoded as blanks, NaNs or other placeholders.โ€

    scikit-learn, the Python machine learning library

For a missing value in model training data, the Google course lists two choices. You can delete the row, which loses data that may still be useful. Or you can impute it, which means filling a reasoned guess. For customer records, a third path is often right: send the row to a person. Google's course also suggests adding a yes or no column that says a value was guessed, so nobody later mistakes the guess for a fact.

What does a cleaning script look like?

Here is a small, made-up export from a mid-size bank, run through the step that checks each row. It uses only Python's standard library, so nothing needs installing. A CSV is a plain text table where each value is separated by a comma. The csv.DictReader class reads each row as a dictionary, so the code can look up a balance by its column name. Read the marked lines first.

Python
import csv, io
from datetime import datetime
from decimal import Decimal
RAW = """customer_id,name,joined,balance
C101,Asha Rao,03/04/2019,"1,250.50"
C102,Ben Ortiz,2020-11-15,
C101,Asha Rao,03/04/2019,"1,250.50"
C104,Dana Pike,31/02/2022,400"""

def parse_date(text):
    for fmt in ("%d/%m/%Y", "%Y-%m-%d"):
        try:
            return datetime.strptime(text, fmt).date().isoformat()
        except ValueError:
            pass
    return None
kept, review, seen = [], [], set()
for row in csv.DictReader(io.StringIO(RAW)):
    issues = []
    if row["customer_id"] in seen: issues.append("duplicate")
    if parse_date(row["joined"]) is None: issues.append("bad date")
    if not row["balance"]: issues.append("no balance")
    if issues:
        review.append((row["name"], "; ".join(issues)))
    else:
        seen.add(row["customer_id"])
        kept.append((row["customer_id"], parse_date(row["joined"]), Decimal(row["balance"].replace(",", ""))))
print("kept:", kept)
for name, why in review:
    print("review:", name, "-", why)

Output

kept: [('C101', '2019-04-03', Decimal('1250.50'))]
review: Ben Ortiz - no balance
review: Asha Rao - duplicate
review: Dana Pike - bad date

The first Asha row passes and is kept. Ben's row has no balance, so it goes to the queue. The second Asha row repeats the first, so it is queued as a duplicate. Dana's date does not exist, so the date check rejects it. Nothing was guessed, and every skipped row says why.

A real project has many more rules, and the owner signs off on each one. The script catches a repeated ID. A customer under two IDs needs a matching step, such as name and date of birth, and a person must confirm each match. The shape stays the same: check every row, pass or queue it, and log the reason.

How would you clean 400,000 rows in a week?

Start with the biggest problems, not all of them. Profile the data in the first afternoon, and agree the rules with the owner the next morning. Run the rules on a copy and count the queue. These numbers are my own rough rule of thumb, not a source. At 400,000 rows, 3 in 100 is about 12,000 rows for a person to check, which a small team can clear in days. At 30 in 100, it is about 120,000 rows, so the source systems need fixing first, and that conversation with the bank comes before any more code.

Tip

Tell the owner the expected queue size before you promise a date. The queue sets the timeline, more than the code does.

What does the interviewer want to hear?

A strong answer covers

  • Profile first: count the blanks, duplicates and impossible values.
  • Rules in code, so every row gets the same checks.
  • Nothing dropped quietly: failed rows keep a reason and go to a queue.
  • A raw copy kept, and the pass rate measured on every run.
  • What clean means agreed with the owner before anything runs.

Common traps

  • Trap"I will just clean it with a prompt."

    BetterA model can help with messy free text, but the rules that decide must be code you can test and explain.

  • Trap"Drop the bad rows and move on."

    BetterDropping them hides the loss. Queue them with a reason, so the owner sees what was lost.

  • Trap"Data is clean once the job runs."

    BetterClean is agreed with the owner. New data brings new mess, so measure the pass rate on every run.

Can you spot the problem in these rows?

Spot the problem

A bank's export has four rows. Which one should go to the review queue, not the clean table?

Quick check

A customer's balance is blank in one branch export. What should the cleaning step do?

Can you answer these from memory?

Flash cards ยท tap a card to flip it

1 / 6

What will they ask next?

  1. Q149How do you clean and deduplicate documents first?11 min
  2. Q248What is a golden dataset, and how do you build one?11 min
  3. Q384How do you push back on the wrong request?9 min
  4. Q398Take-home: messy data โ†’ records, with low-confidence flags.12 min
  5. Q399Parse a messy CSV/JSON file with edge cases.12 min

Learn it in depth

Last updated on 27 November 2026

Taking over messy data for an AI project?

I design and build AI products and agents, including the data steps behind them: the rules, the review queue and the checks. Book a short call and tell me what your data looks like.