← All articles
Guide · 2026-11-16

AI-Assisted SQL and Data Cleaning in Practice: From a Messy Table to Results You Can Trust

Published 2026-11-16 ·Mentions: ChatGPT, Claude
AI-Assisted SQL and Data Cleaning in Practice: From a Messy Table to Results You Can Trust
Before handing a CSV or Excel file to ChatGPT or Claude, do three things: tidy the table structure, prepare a small sample you can check by hand, and ask the AI to explain its plan first. Then run the full file and verify every result.

Conclusion: get it working on a small sample, then run the full file

This guide is for people who hold the tables and own the numbers: data product managers, operations analysts, and anyone who files a weekly report. The conclusion: let the AI run the process on a small sample first and explain each step, verify it, and only then run the full file. Dropping the whole raw table in and waiting for an answer is the fastest way to get a wrong one.

OpenAI's help center puts it well enough to quote: upload structured data with clear column names and one record per row, then tell ChatGPT what you want to learn from the file, which columns, calculations, groupings, or chart types to use. Do the preparation first and the AI's work becomes verifiable.

What you need

One raw data file: a CSV or Excel spreadsheet. ChatGPT's officially supported files include .xls, .xlsx, and .csv, plus PDFs and text files such as .json and .txt; Claude also accepts files uploaded into a chat for analysis. Also prepare a data dictionary: what each column means, its unit, and which values are valid. If you cannot write one, ask the AI to infer it from the headers first, then confirm it yourself.

Then prepare a small sample of 20 to 50 rows, taken from the first 50 rows of the original table and saved separately. Validate all cleaning logic on the sample first — with so few rows you can check each one by eye — and only then run the full file. If the data contains real user privacy, ID numbers, or phone numbers, remove or mask the sensitive fields before uploading; never hand raw sensitive data to a chat assistant.

Steps: diagnose, set the rules, then execute

Step 1: diagnose before cleaning. After uploading the file, do not rush into instructions. Ask the AI to report a health check of the table: how many rows and columns, how many empty values per column, whether there are duplicate rows, and whether date and number formats are consistent. OpenAI's guidance: put descriptive headers in the first row, one record per row, no unrelated tables in one sheet, and no empty rows or columns splitting the data.

Step 2: ask the AI to write the cleaning plan instead of acting on it directly. Have it list the rule for each kind of messy data first: what to fill empty values with or whether to delete the row, which columns define a duplicate, which format dates should use, and how to handle thousand separators and currency symbols in amounts. Review the rules yourself and only then let it execute; the rules double as documentation you can reuse.

Step 3: generate the SQL and cleaning code, and check it section by section. Ask the AI to write the cleaning logic as SQL or Python code and return the intermediate result of each step: how many rows were processed, how many duplicates removed, how many formats changed. The official help center is explicit: when Python is used for analysis, review the generated code, outputs, and assumptions before relying on the result, and ask the AI to show or adjust the method if anything is unclear.

Step 4: run the full file only after the sample passes. After the full run, do three checks: the row counts add up — original rows minus deleted rows equals result rows; spot-check 10 rows field by field against the original values; and recompute the key metrics a different way. Save and download the result only when all three pass. If any check fails, go back to step 2 and fix the rule; never edit the result numbers directly.

Common problems and fixes

If the analysis looks incomplete, look at the file itself first. OpenAI notes that a file can be too large, too complex, or too formula-heavy for complete analysis. The fix is to ask the AI to inspect specific sheets, rows, or columns, or to split the file into smaller pieces.

If a chart or number does not match your expectation, ask about the method first. ChatGPT may pick an analysis method or chart type that differs from your intent on the first try; the official guidance is to specify the method, chart type, grouping, or column directly. Asking "which definition did you use" usually locates the disagreement on the spot.

Do not calculate directly from tables inside scanned files or images. The official documentation says ChatGPT may not reliably extract exact values from image-based tables or scanned files. When exact values matter, upload a spreadsheet or text-based file instead.

Things to watch

Do not treat the AI's output as the final answer. Check every number against the source table before it goes into a report; amounts, dates, and deduplication rules are where errors hide most often, and they deserve the most review time.

Pricing is described by model only: both ChatGPT and Claude offer free and paid subscription tiers, with exact tiers and prices as listed on their official sites; this guide does not cover them. The steps in this article were checked against the official pages on 2026-11-16. If platform rules change, the official pages apply.

Tools mentioned

Chat & Search · Free tier + paid — OpenAI flagship all-in-one AI assistant combining deep reasoning, web research, data analysis, voice chat, and image generation.
Chat & Search · Free tier + paid — Anthropic AI assistant renowned for natural long-form writing, deep coding, and interactive Artifacts.

Sources

  1. Data analysis with ChatGPT
  2. Working with files in ChatGPT — OpenAI

This article is compiled from the public sources above and does not reproduce the originals in full; see the official sources for details.

Sign in to Lumo

Sign in with a one-time code sent to your email — no password. Your saved tools will sync across your devices.

The code is only used to sign you in. We store just your email and saved list (privacy policy, in Chinese).

—

Signed in. Your saved tools sync across all your devices.

0saved
View saved tools

Send feedback

Found a mistake, missing something, or have a suggestion? Tell us.