The safe way to clean AI-extracted CSV data is to produce three artifacts: accepted rows, rejected rows containing the original values and reason, and an audit summary whose counts reconcile exactly to the input row count. ChatGPT can help with this workflow, but the rules must be explicit, and the generated code, outputs, and assumptions must be checked. For related background, see data analysis with AI, AI spreadsheet tools and AI data preprocessing.
Prerequisites and Intended Result
Use ChatGPT with file uploads and data analysis available. ChatGPT can analyze CSV files, run Python-based transformations, and sometimes use a stateful Jupyter notebook environment. Users should review the generated code, outputs, and assumptions. CSV files are supported for ChatGPT data analysis, but available file types and capabilities can vary by model, plan, workspace settings, and account capabilities. Its documentation also recommends clear headers and one record per row. See Data analysis with ChatGPT.
For a sensitive file, open a new chat, select Temporary, choose the personalization setting, attach the CSV with the composer’s file control, and send the prompt. Temporary chats stay out of chat history unless saved, but they may still be retained for up to 30 days for safety. Do not treat Temporary chat as a promise of immediate deletion.
This example uses these deterministic rules:
- Keep the first occurrence of an ID and reject later duplicates.
- Reject blank IDs.
- Accept four date formats and normalize them to
YYYY-MM-DD. - Accept non-negative numeric amounts and format them to two decimals.
- Reject blank or non-numeric amounts.
- Reject blank or unrecognized dates.
- Preserve every rejected row exactly, adding only
source_rowandreject_reason.
For larger files, check the current upload limits first. OpenAI documents that CSV and spreadsheet files are limited to approximately 50 MB, depending on row size. Uploaded files also have a 512 MB per-file limit, and the relevant plan may impose separate rolling upload quotas or storage caps.
Complete Worked Example: Input, Prompt, and Output
Example input: The following invented fixture contains duplicate IDs, blank fields, a valid zero amount, mixed date formats, and invalid amounts. The output below is illustrative; it does not claim that this article ran the file.
id,customer,date,amount
1001,Ada,2026-01-05,12.50
1002,Bo,01/06/2026,8.00
1002,Bo,2026-01-07,9.50
1003,Cia,09-Jan-2026,0
,Dee,2026-01-09,4.25
1004,Eli,2026-01-10,
1005,Fay,2026-01-11,not_available
1006,Gus,2026/01/12,3.20
1007,Hana,,5.00
Paste this prompt after attaching the CSV:
Clean the attached CSV deterministically with Python and show the complete code.
Rules:
1. Add source_row using the original CSV line number, with the header as row 1.
2. Keep the first occurrence of each nonblank id. Reject later occurrences as duplicate_id.
3. Reject blank ids as missing_id.
4. Parse dates in these formats only: YYYY-MM-DD, MM/DD/YYYY, DD-Mon-YYYY, and YYYY/MM/DD. Normalize accepted dates to YYYY-MM-DD. Reject other or blank dates as invalid_date.
5. Accept only non-negative numeric amounts. Preserve decimal precision and format accepted amounts to two decimal places. Reject blank or non-numeric amounts as invalid_amount.
6. Do not silently delete any input row.
7. Create:
- accepted.csv with source_row, id, customer, date, amount
- rejected.csv with every original field plus source_row and reject_reason
- audit_summary.csv containing input_rows, accepted_rows, rejected_rows, reconciliation_rows, reconciliation_status, and counts by reject_reason
8. Show the generated Python code, the first complete contents of each output, and assertions proving:
input_rows = accepted_rows + rejected_rows
accepted IDs are unique
every rejected row has a reason
the rejected source rows are 4, 6, 7, 8, and 10.
If a method or assumption is uncertain, stop and report it instead of guessing.
Expected output: The illustrative result should contain four accepted rows and five rejected rows. Rows 4, 6, 7, 8, and 10 should be rejected for duplicate ID, missing ID, invalid amount, invalid amount, and invalid date, respectively. The accepted dates should be normalized to YYYY-MM-DD, the valid zero amount should become 0.00, and every rejected record should retain its original field values.
An illustrative accepted file would be:
source_row,id,customer,date,amount
2,1001,Ada,2026-01-05,12.50
3,1002,Bo,2026-01-06,8.00
5,1003,Cia,2026-01-09,0.00
9,1006,Gus,2026-01-12,3.20
The rejected file would preserve the original values:
source_row,id,customer,date,amount,reject_reason
4,1002,Bo,2026-01-07,9.50,duplicate_id
6,,Dee,2026-01-09,4.25,missing_id
7,1004,Eli,2026-01-10,,invalid_amount
8,1005,Fay,2026-01-11,not_available,invalid_amount
10,1007,Hana,,5.00,invalid_date
The audit summary would contain:
input_rows: 9
accepted_rows: 4
rejected_rows: 5
reconciliation_rows: 9
reconciliation_status: PASS
duplicate_id: 1
missing_id: 1
invalid_amount: 2
invalid_date: 1
Acceptance Checks: Reconcile Every Row
Verify the result: Ask ChatGPT to display the assertions and their results, then check the four conditions below. The reconciliation count must be 9, not merely “approximately all rows.”
assert input_rows == 9
assert accepted_rows == 4
assert rejected_rows == 5
assert accepted_rows + rejected_rows == input_rows
assert accepted_ids_are_unique is True
assert rejected_source_rows == {4, 6, 7, 8, 10}
assert reject_reason_counts == {
"duplicate_id": 1,
"missing_id": 1,
"invalid_amount": 2,
"invalid_date": 1,
}
Also inspect the generated code. Confirm that the duplicate rule uses input order, that 0 is retained rather than treated as blank, and that rejected records are copied before normalization changes their values.
ChatGPT’s data-analysis environment may choose an unsuitable method on its first attempt. Its documentation recommends asking for a specific method or column when the intended calculation matters. Ask it to revise the code rather than accepting a plausible-looking table.
Specific Failures and Recovery
A common failure is that the model drops invalid rows before producing the rejected file. Recover by asking: “Reprocess the original attachment, preserve every rejected row verbatim, and add only reject_reason; show the row-count reconciliation before presenting cleaned data.” If the original file is no longer available in the conversation, attach it again.
Another failure is ambiguous date interpretation, such as treating 01/06/2026 as June 1 instead of January 6. The recovery is to provide an explicit allowed-format list and require a normalized date column plus a rejected row for every other format.
If the file uploads successfully but the analysis appears incomplete, ask ChatGPT to inspect specific row ranges or split the file into smaller parts. This is especially important for large, complex, or poorly structured files. The method is unsuitable for irreversible financial posting, regulated reporting, or business rules that are not documented; use a deterministic production pipeline and human approval for those cases.
Frequently Asked Questions (FAQ)
Q1) Should every row with a duplicate ID be rejected?
This example keeps the first occurrence and rejects only later occurrences. That policy is appropriate when file order defines which record is authoritative. If duplicates require comparison, do not choose automatically; preserve all duplicates and send them to manual review instead.
Q2) Is a zero amount an invalid blank?
No. A numeric zero is a valid value under the rules used here. The cleaner must distinguish the string 0 from an empty field, whitespace, or a non-numeric value. Add a separate business rule if zero is not allowed for your dataset.
Q3) Does Temporary chat guarantee that the CSV is immediately deleted?
No. Temporary chat prevents the chat from appearing in history and avoids model improvement while it remains temporary, but OpenAI may retain a copy for safety for up to 30 days. Saving the chat converts it into a regular chat, and eligible uploaded files may then be saved to Library. Delete saved Library files separately when retention matters.