Design an LLM-Assisted CSV Cleaning and Import Pipeline
Design a batch pipeline that turns messy customer CSV files of any layout into rows of one fixed 40-column table and imports them, keeping cost per file low, data accurate and exceptions manageable.
Problem statement
You are advising a client that runs a demographic and payroll analytics product. A six-person operations team cleans CSV files by hand and then imports them into the client's database. For this exercise, assume the files come from the client's customers and hold their employee and payroll data.
Files have 100 to 50,000 rows and no shared schema: headers may be real names or just A, B, C, and some fields need restructuring, such as splitting a full name into first and last name. Every file must end up as rows of one fixed output table of about 40 columns.
Volume is growing to more than 10,000 files a month, and handling a file costs about $17 today. Batch processing is fine: a file may take anywhere from hours to a few days to finish. The client cares about three things: cost per file, accuracy, and how exceptions are handled.
Design the system that takes in a customer's file, works out how its columns map to the output table, cleans and checks every row, sends problems to the operations team, and imports the result. You may use a hosted large language model.
For this exercise, assume each file is one customer account's data for one pay period. Each output column has a type and a validation rule (for example, a required employee ID, dates, currency amounts, or a fixed set of allowed values), and a few columns are required.
Assume customers usually send each new file in the same layout as their last one, but a layout can change without notice. Assume the client's data agreement allows a small sample of a file to go to the model provider, but the client wants as little personal data as possible to leave its systems.
A wrong value imported without anyone noticing is worse than a row held for review. A file is imported as one unit: its rows become visible together, after its exceptions are fixed or deliberately skipped, and importing the same file again must never create duplicate rows.
The customer-facing upload page, analytics on the imported data, and correcting errors inside customers' own source systems are out of scope.
What to build
- Accept a customer's CSV file for its account, record the same file only once even if it is uploaded again, and report the file's processing status.
- Get each file's data into the fixed output table's columns, restructuring fields such as full names where needed, and handle a returning customer's usual layout without repeating the work done for it before.
- Apply the mapping to every row, check every output value against its column's rule, and import the file's rows as one unit, each linked to its source file, row number and mapping version.
- Send rows that fail their checks, and files whose mapping looks wrong, to the operations team with the reason, and let a mapping fix apply to later files with the same layout.
At scale
- Files have 100 to 50,000 rows, volume is growing past 10,000 files a month, and a file may take anywhere from hours to a few days to finish.
- Handling a file costs about $17 today. For this exercise, assume the goal is to cut the average cost per file, counting model usage and operations time together, by about ten times without lowering accuracy.
- For this exercise, assume model usage is billed per token and one model request can hold at most a few thousand rows of a typical file.
- For this exercise, assume the operations team stays at six people, so its review time is part of the cost per file and cannot grow with file volume.