codebaobab
Python workspace

FDE interview labData & Systems

Conversation Export Cleaner

Add email masking to a working export pipeline.

Python45 minutesData & Systems

Challenge brief

Read before you begin

Your mission · Extend a codebase

Add email masking to the weekly export without moving any conversation between the training and evaluation sets.

Marlow Desk's EU customers signed a data addendum that bans customer email addresses in model training data from December 1. The weekly export still copies them into the training set, so the December 8 retrain cannot start. The model team also needs the split unchanged, or this month's quality scores cannot be compared with last month's.

  • New option · mask_emails
  • Split · unchanged
Skip to round setup

Your assignment

  1. Read how the pipeline splits the work across modules.
  2. Run the checks: they all pass. The masking checks join when you press Check the feature.
  3. Add mask_emails to the kept rows and count replacements.
  4. Handle the new requirement when it arrives.
  5. Explain where masking lives and what you checked in NOTES.md.

The problem

Customer emails reach training data

Kept rows go to the datasets with every address as written.

Impact: Legal will not sign off on the December 8 retrain.

No count for the audit

The report always says masked_emails 0.

Impact: The data audit cannot prove addresses were removed.

Context

Addendum takes effect
Dec 1
Retrain
Dec 8
Addresses a week
~41,000

Requirements

  • Existing deduplication, timestamps and split keep working.
  • mask_emails is a Boolean, default false.
  • Replace every address in kept rows with [EMAIL].
  • Count each replacement in masked_emails.
  • Groups and buckets use the unmasked text.
  • Invalid and discarded rows are not counted.
  • rows and options are never changed.

System overview

Edit the components marked “Your work”. The other components show where your changes fit.

US helpdesk DBUS support conversations
EU helpdesk DBEU support conversations
Export cleaner(Your work)Cleans, masks and splits exports
Dataset bucketWeekly training files
Model trainingFine-tunes the reply model
Data auditChecks counts and masking
Read the connections
  • US helpdesk DB → Export cleaner: weekly rows
  • EU helpdesk DB → Export cleaner: weekly rows
  • Export cleaner → Dataset bucket: train, eval
  • Dataset bucket → Model training: fine-tune, score
  • Export cleaner → Data audit: report
  • US helpdesk DB: Timestamps as MM/DD/YYYY HH:MM, no time zone (UTC).
  • EU helpdesk DB: ISO 8601 timestamps with Z or an offset.
  • Export cleaner: clean_export(rows, options) in clean/dedupe.py; conversation_key and parse_timestamp in clean/services; masking goes in clean/services/redaction.py.
  • Dataset bucket: train.jsonl, eval.jsonl and report.json per weekly export.
  • Model training: Fine-tunes the reply model on train, scores it on eval.
  • Data audit: Reads report.json; every input row must be accounted for, and masked_emails must be reported.

Details

Full requirements

Functional

  1. clean_export(rows, options) returns {train, eval, report}. Each row has a unique nonempty string id, a string text and a timestamp; other fields (store_id, region) are kept as they are. Neither rows nor options may change. A malformed id or a text that is not a string raises ValueError mentioning id or text. (Works today; keep it.)
  2. Two rows are the same conversation when their keys match: the text after Unicode NFKC, casefolding and collapsing whitespace. Of each group keep the latest valid instant, and on equal instants the smallest id. A row whose timestamp cannot be parsed is listed in report.invalid_timestamps, sorted, and never kept. (Works today; keep it.)
  3. Deduplicate first, then split by the SHA-256 bucket of the key: a bucket below eval_percent (whole number 0 to 100, default 20) goes to eval, the rest to train. Both lists are sorted by id. (Works today; keep it.)
  4. New: mask_emails is a Boolean option, default false; anything else raises ValueError mentioning mask_emails. When it is true, every email address in a kept row's text becomes [EMAIL]. An address matches [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+ followed by a dot and at least two letters, plus tags and repeats included. This is what the data addendum requires.
  5. New: groups and buckets are decided from the unmasked text, before masking. Two conversations that differ only by address stay separate, and no conversation moves between train and eval because it was masked, so this month's scores still compare with last month's.
  6. report is {input, unique, duplicates, invalid_timestamps, masked_emails}. input always equals unique + duplicates + the number of invalid ids. New: masked_emails counts the addresses replaced in kept rows; invalid and discarded rows are not counted.

Non-functional

  • Scale: a weekly export is about 1.4 million rows, of which 9% to 12% are duplicates, about 0.3% have unparseable dates and about 3% contain an address. The job runs in a 30-minute slot on one 8 GB worker, so it must stay close to linear in the number of rows.
  • Determinism: the same export must give the same train and eval sets, row for row, across runs and machines, with or without masking.
  • Accounting: the data audit rejects an export whose report does not reconcile to the input count, or that was masked without a masked_emails count.
  • Privacy: rows contain customer messages. The cleaner keeps everything in memory and writes nothing but the three outputs.

Out of scope

  • Pulling rows from the helpdesk databases and writing the JSONL files; the job runner does both.
  • Masking names, phone numbers or order numbers. Email addresses only, by the pattern in the contract.
  • Changing the duplicate key, the timestamp rules or the split. They work and the model team depends on them.
  • Training and scoring the model.
Data model

Export row

FieldTypeNotes
idstringUnique. US rows start with c-, EU rows with e-.
textstringThe customer's message as written. Masked in the output when mask_emails is true.
timestampstring"11/14/2026 08:12" (US, UTC) or "2026-11-14T11:05:00+01:00" (EU).
store_id, regionstringExtra fields. Kept unchanged on the kept row.

Options

FieldTypeNotes
eval_percentinteger 0 to 100Default 20.
mask_emailsbooleanNew. Default false.

Report

FieldTypeNotes
inputintegerEvery row given.
uniqueintegerRows kept, in train or eval.
duplicatesintegerValid rows discarded as duplicates.
invalid_timestampsstring[]Ids with a timestamp that does not parse, sorted.
masked_emailsintegerAddresses replaced in kept rows. Always 0 today.
Files you are given · 4
  • samples/export-2026-11-14.json Nine rows from both regions: one message exported three ways with the same address, a full-width letter, an impossible date (November 31), and rows with one, two or no addresses.
    [
      {"id": "c-10482", "text": "Where is my order #55120? It said 3 days. Email me at dana.k@shopmail.com", "timestamp": "11/14/2026 08:12", "store_id": "st-311", "region": "us"},
      {"id": "c-10517", "text": "where is my order #55120?  it said 3 days. email me at dana.k@shopmail.com", "timestamp": "2026-11-14T09:40:00-05:00", "store_id": "st-311", "region": "us"},
      {"id": "e-20031", "text": "WHERE IS MY ORDER #55120? IT SAID 3 DAYS. EMAIL ME AT DANA.K@SHOPMAIL.COM", "timestamp": "2026-11-14T14:40:00Z", "store_id": "st-311", "region": "eu"},
      {"id": "c-10533", "text": "Can I change the size on my exchange?", "timestamp": "11/14/2026 10:05", "store_id": "st-042", "region": "us"},
      {"id": "e-20044", "text": "Can I change the size on my exchange?", "timestamp": "2026-11-14T11:05:00+01:00", "store_id": "st-042", "region": "eu"},
      {"id": "c-10540", "text": "The discount code SAVE15 does not work. Reach me at lee@north-trail.com", "timestamp": "11/31/2026 12:30", "store_id": "st-118", "region": "us"},
      {"id": "e-20052", "text": "Do you ship to Norway? Write to ola+orders@post.no", "timestamp": "2026-11-14T16:20:00+01:00", "store_id": "st-207", "region": "eu"},
      {"id": "e-20058", "text": "Do you ship to Sweden?", "timestamp": "2026-11-14T16:45:00+01:00", "store_id": "st-207", "region": "eu"},
      {"id": "c-10561", "text": "I was charged twice for one order. Contact sam@example.com or sam.b@example.com", "timestamp": "2026-11-14T17:02:00Z", "store_id": "st-118", "region": "us"}
    ]
  • samples/export-2026-11-14-expected.json What the contract says those rows produce with eval_percent 20 and mask_emails true. The same rows land in train and eval as without masking.
    {
      "train": [
        {"id": "c-10517", "text": "where is my order #55120?  it said 3 days. email me at [EMAIL]", "timestamp": "2026-11-14T09:40:00-05:00", "store_id": "st-311", "region": "us"},
        {"id": "c-10533", "text": "Can I change the size on my exchange?", "timestamp": "11/14/2026 10:05", "store_id": "st-042", "region": "us"},
        {"id": "c-10561", "text": "I was charged twice for one order. Contact [EMAIL] or [EMAIL]", "timestamp": "2026-11-14T17:02:00Z", "store_id": "st-118", "region": "us"},
        {"id": "e-20052", "text": "Do you ship to Norway? Write to [EMAIL]", "timestamp": "2026-11-14T16:20:00+01:00", "store_id": "st-207", "region": "eu"}
      ],
      "eval": [
        {"id": "e-20058", "text": "Do you ship to Sweden?", "timestamp": "2026-11-14T16:45:00+01:00", "store_id": "st-207", "region": "eu"}
      ],
      "report": {"input": 9, "unique": 5, "duplicates": 3, "invalid_timestamps": ["c-10540"], "masked_emails": 4}
    }
  • config/weekly-export.yaml The two sources, the split percentage, the new mask_emails option, and the job's memory and time limits.
    # Suggested Replies weekly export (runs Sundays 02:00 UTC).
    sources:
      - name: us-helpdesk
        timestamp_format: "MM/DD/YYYY HH:MM (UTC, no zone)"
      - name: eu-helpdesk
        timestamp_format: "ISO 8601 with Z or offset"
    options:
      eval_percent: 20
      mask_emails: true   # required from 2026-12-01 (data addendum)
    limits:
      worker_memory_gb: 8
      slot_minutes: 30
  • metrics/email-exposure-2026-11.csv Three weekly exports: kept rows that contain an address, how many addresses they hold, and the masked_emails the report gave (always 0).
    export_week,input_rows,kept_rows,kept_rows_with_email,email_addresses_in_kept_rows,masked_emails_reported
    2026-10-25,1386204,1229911,36120,39874,0
    2026-11-01,1402877,1244420,36988,40812,0
    2026-11-08,1419530,1259386,37540,41377,0
Tickets · 3
  • TASK-201 Mask email addresses in the kept rows Reported by Ines (ML data)

    Expected c-10517 reads "...email me at [EMAIL]", c-10561 reads "Contact [EMAIL] or [EMAIL]", e-20052 reads "Write to [EMAIL]", and the report says masked_emails 4.

    Actual mask_emails is ignored: every address is still in the output and the report says masked_emails 0.

  • TASK-202 Keep duplicate groups and the split as they are Reported by Tomas (model quality)

    Expected The same ids in the same sets both times: train c-10517, c-10533, c-10561, e-20052 and eval e-20058. Masking before bucketing would send c-10561 to eval (its masked key falls in bucket 2), which this must not do.

    Actual Both runs give the same ids today only because nothing is masked.

  • TASK-203 Validate the option and count only kept rows Reported by Ines (ML data)

    Expected mask_emails 1 raises ValueError mentioning mask_emails. The addresses in c-10540, c-10482 and e-20031 are not counted, so masked_emails is 4, not 7.

    Actual mask_emails 1 is accepted without an error, and masked_emails is always 0.

What you hand in
  • Every public check passing: the deduplication checks that pass now and the new masking checks, including the new requirement when it arrives.
  • NOTES.md: where masking lives and why, the check that proves the split did not change, and how the report counts masked addresses, one line each.
  • Your answer to the interviewer's follow-up and the debrief questions.
How the work is judged
Breaking down the work
Reads the pipeline and its modules before coding, puts the pattern and replacement in the redaction module, and changes ExportCleaner to validate the option and add up the count.
Directing the assistant
Tells the assistant exactly where masking happens (on kept copies, after the bucket) and which working modules it must not touch.
Checking the work
Runs the checks on the starter and sees them all pass, compares train and eval ids with and without masking, and keeps every existing check green.
Judging the assistant
Rejects masking before grouping or bucketing, masking the input row in place, or changes to deduplication rules that already work.
Correct result
All checks pass, old and new, including the follow-up, with the same groups and splits as before masking.
Explaining the work
Explains with a sample row why masking comes after the split and how the report lets the audit trust the masked count.
Trade-offs to discuss
  • Masking at export time versus at ingestion, and who else would then never see the raw address.
  • A regular expression for addresses versus a parser: what each misses and what each over-masks.
  • Replacing every address with one token versus a per-address placeholder, and what the model can still learn.
  • Keeping the split stable for comparable scores versus rebalancing once the data changes.
How you are graded
  • Decomposition 20%
  • Prompting the assistant 15%
  • Verification 25%
  • Judgment about AI output 15%
  • Correctness 15%
  • Communication 10%

Scores use evidence from your session. A short or incomplete session may not provide enough evidence for every skill. See a sample scorecard

Interview guidance

This export pipeline already deduplicates and splits support conversations, and its checks pass. Your job is to add email masking without moving a single row between train and eval. Use the AI assistant, but first show me how the pipeline is split into modules and run the checks: they should all pass. I will ask how you know the existing behavior still holds.

  • AI is allowed and expected: your own Claude, OpenAI or Gemini key, or the free in-browser model.
  • You are graded on how you drive and check the AI, not on how much you prompt.
  • Run the checks; read what fails.
  • A new requirement will arrive partway through.
  • Too little AI use is reported as “not enough to grade”, never as a fail.
Debrief · 7 questions
  • What did you delegate to the AI, and why?
  • Name one AI suggestion you rejected or changed, and why.
  • Choose one block the AI helped write. Explain what each line does and which test verifies it.
  • What is still risky, and what would you test or ship next?
  • How do you know masking did not move any conversation between train and eval?
  • Which module did you put the masking in, and what would change if the email pattern changed?
  • What would you check before running this on the 1.4 million row weekly export?