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

AI and LLM interview question Q387, Forward Deployed Engineering and applied AI. Intermediate, common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/how-do-you-deal-with-messy-customer-data

## Say it in 30 seconds

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.

## Say it in 2 minutes

Customer data is almost never clean. A bank's three branch systems store the same date in three ways, one balance has a comma in it, and one customer appears twice under two IDs. Before any AI touches the data, I want to know what is wrong and how much of it there is. So I copy the raw export, then profile it: counting blanks, duplicates and values that cannot be real.

Then I write the cleaning rules in code, not in a prompt. Once each branch's date order is agreed, one rule turns 03/04/2019 into one date format. Another rejects 31 February. Every row goes through the same checks, and the code records why a row failed. Rows that pass go to the clean table. Rows that fail go to a review queue, with the reason beside them, so a person can fix them or drop them.

I keep the raw export untouched, so every step can be run again. I also measure each run: how many rows passed, how many went to review, and whether that number falls over time. Where the data is free text, such as call notes, a model can pull out the fields, but I check its answers against the same rules and flag the low-confidence ones.

Agreeing what clean means is often the hardest part. A blank balance could be zero, unknown or a system error, and only the owner of the data can say which. I get that decision in writing before I run anything.

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

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

*Diagram, Fix with a rule, or ask a person: 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.*
1. A value that one rule can put right goes to that rule.
2. An impossible value cannot be guessed, so it goes to a person.
3. A missing value could mean several things, so a person decides.
4. A fixed value, in one agreed format, becomes a clean row.
5. The impossible value waits in the queue with its reason.
6. The missing value waits in the queue too, until someone decides.

> **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. **Copy the raw data first:** Keep the export unchanged. Every later step reads from the copy, so you can always go back.
2. **Profile before you touch it:** Count blanks, duplicates and impossible values for each source. Show the numbers to the owner.
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. **Split passes from fails:** Rows that pass go to the clean table. Rows that fail are kept, each with a reason.
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. **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.

*Diagram, How messy rows are cleaned: 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.*
1. Each export is read as it is, with no edits.
2. Rows that pass every rule carry on.
3. A gap, a repeat or a bad value is caught here.
4. Clean rows are loaded into the customer file.
5. Failed rows wait in the queue, with their reason.

> "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:

```text
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." Better: A 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." Better: Dropping them hides the loss. Queue them with a reason, so the owner sees what was lost.
- Trap: "Data is clean once the job runs." Better: Clean 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?

A. C301, Maria Gomez, 08/11/2022, 2150.00
B. C302, Omar Haddad, 2023-02-30, 870.00
C. C303, Priya Nair, 19/05/2021, 3300.00
D. C304, Tom Reid, 01/07/2020, 415.25

**Answer:** B. 2023-02-30 is not a real date. A rule cannot know whether the day or the month was typed wrong, so a person decides. The other three rows are valid dates.

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

A. Fill in zero and load the row
B. Delete the customer from the table
C. Flag the row with its reason and send it to review
D. Ask the model to guess the balance

**Answer:** C. A blank could mean zero, unknown or a system error, and only the owner can say which. Flagging keeps the row visible and leaves the decision with a person.

## Can you answer these from memory?

**Flash cards**

- **What is messy data?** Customer data that is wrong, missing, repeated or inconsistent.
- **What comes first before cleaning?** Copy the raw data, then profile it: count blanks, duplicates and odd values.
- **Where do the rules live?** In code, so the same checks run on every row and can be tested.
- **What happens to a failed row?** It goes to a review queue with its reason. It is never dropped quietly.
- **What does imputation mean?** Filling a missing value with a reasoned guess.
- **What do you measure on each run?** The share of rows that pass every rule. A falling rate often means a new source has a new problem.

## Likely follow-up questions

- Q149 How do you clean and deduplicate documents first? https://designervenkat.online/interview/ai/how-do-you-clean-and-deduplicate-documents-first
- Q248 What is a golden dataset, and how do you build one? https://designervenkat.online/interview/ai/what-is-a-golden-dataset
- Q384 How do you push back on the wrong request? https://designervenkat.online/interview/ai/how-do-you-push-back-on-the-wrong-request
- Q398 Take-home: messy data → records, with low-confidence flags. https://designervenkat.online/interview/ai/take-home-messy-data-records-with-low-confidence-flags
- Q399 Parse a messy CSV/JSON file with edge cases. https://designervenkat.online/interview/ai/parse-a-messy-csv-json-file-with-edge-cases

## Learn it in depth

- [Data cleaning: fixing a messy table](https://designervenkat.online/learn/machine-learning/data-cleaning)
- [Preprocessing: getting data ready for a model](https://designervenkat.online/learn/machine-learning/preprocessing)
