Using AI as an analyst, and checking its work
AI can write SQL, explain results and draft summaries in seconds, but it can also be confidently wrong. Learn a safe workflow: give it context, ask for method not just answers, and verify every number with your own check.
AI tools such as ChatGPT, Gemini and Claude can write SQL and Python, suggest charts, clean text columns and draft the summary of a report. Used well, they make an analyst faster. Used blindly, they produce neat-looking answers that are wrong, and the person who sends the report is the one who gets blamed, not the AI.
What you will do: run a real analysis of a sales file with an AI assistant, then check its numbers independently with a short Python script. You will leave with a repeatable checking routine.
Prerequisites: basic SQL or pandas, and the idea of metrics from *Business metrics and KPIs*. You need a free AI tool (ChatGPT, Gemini or Claude all have free plans, with limits) and Python with pandas (Google Colab has both). You will use the sales.csv file generated in *Project: sales dashboard for a coffee chain*; a small file with the same columns also works.
What AI is good and bad at in analysis
Where to trust and where to check
| Task | AI helps | Risk |
|---|---|---|
| Writing a SQL query or pandas code | Fast first draft, explains each part | Wrong joins, double counting, wrong column names |
| Explaining an error or a formula | Usually clear and quick | May invent a function that does not exist |
| Suggesting charts and KPIs | Good brainstorming | Generic; may ignore your business |
| Doing arithmetic or aggregating a pasted table in its head | Looks plausible | Often miscalculates; numbers may be invented |
| Summarising findings | Fluent first draft | Overstates certainty; claims causes the data cannot show |
| Cleaning text (city names, categories) | Handles messy spelling well | May silently change values that were correct |
A key rule: let the AI write code, and let the code compute the numbers. A language model predicts text. When it computes a total itself, it is guessing what a total would look like. When it writes a query that you run, the database does the arithmetic exactly. Some AI tools can run code themselves in a sandbox; even then, ask to see the code so you can check the logic.
Be careful with private data
Do not paste real customer names, phone numbers, salaries or confidential company data into a public AI tool unless your organisation allows it. Share only column names and a few anonymised or made-up rows, then run the generated code on the real data yourself. In India, personal data is also covered by the DPDP Act, so treat customer information with care.
Step 1: give the AI the context it lacks
AI cannot see your table. If you only say "analyse my sales", it guesses column names and invents a structure. Give it the schema, one example row, the business question and what each column means. Tell it the traps, such as one order spanning several rows.
You are helping me, a data analyst, analyse sales data. I will run all code myself and send you results.
Table: sales (one row per item in an order)
Columns: order_id (int, an order can have several rows), order_date (date), store (text), item_id (text), item_name (text), category (text: coffee, tea, bakery, food), unit_price (int, rupees), qty (int), revenue (int, = unit_price * qty)
Example row: 1001, 2026-01-03, Indiranagar, cappuccino, Cappuccino, coffee, 180, 2, 360
Question: [for example: which store has the lowest average order value, and why might that be?]
First, tell me how you will define each metric and any assumptions. Then write the pandas code (assume the file is sales.csv). Do not state any numbers until I give you the output.What to expect: A good answer defines average order value as total revenue divided by distinct orders (not the mean of the revenue column), uses the exact column names, and does not invent figures.
Step 2: run the code yourself
Run and look
- 1Copy the AI's code into a notebook (Colab) or a .py file next to
sales.csv. - 2Run it. If it errors, paste the exact error message back and ask what caused it. Do not just ask it to 'fix it'; ask it to explain the cause first.
- 3Read the code line by line. Ask yourself: what does each line filter, group or join? Does the number of rows make sense after each step?
- 4Send the output back and ask for an interpretation, then ask what else could explain the pattern.
Step 3: verify with an independent check
Checking means getting the same answer a different way or testing it against something you know. The script below is a basic sanity pass you can run on any sales table: it checks row counts, missing values, that revenue equals price times quantity, and recomputes headline totals by two different methods.
import pandas as pd
df = pd.read_csv("sales.csv", parse_dates=["order_date"])
print("Rows:", len(df))
print("Total revenue:", df["revenue"].sum())
print("Distinct orders:", df["order_id"].nunique())
print("Average order value:", round(df["revenue"].sum() / df["order_id"].nunique(), 2))
print()
print(df.groupby("store")["revenue"].sum().sort_values(ascending=False))
monthly = df.groupby(df["order_date"].dt.to_period("M"))["revenue"].sum()
print()
print(monthly)
# data quality checks
print()
print("Rows where revenue != unit_price * qty:", (df["revenue"] != df["unit_price"] * df["qty"]).sum())
print("Missing values:", df.isna().sum().sum())
# a second way to get total revenue: add up the per-store totals
by_store_total = df.groupby("store")["revenue"].sum().sum()
print("Total from store totals matches overall total:", by_store_total == df["revenue"].sum())Save it next to sales.csv and run python check.py. Requires pandas (pip install pandas).
Now compare these numbers with what the AI's code or text claimed. If AI wrote a number that its own code does not produce, trust the code. If code and your check disagree, find out why before sharing anything. The usual causes are below.
Why numbers disagree
| Symptom | Likely cause | How to check |
|---|---|---|
| Orders count too high | Counted rows instead of distinct order_id | Compare len(df) with df['order_id'].nunique() |
| Revenue too high after a join | Join duplicated rows (one-to-many) | Count rows before and after the join |
| Average is odd | Averaged averages, or included zero or test rows | Recompute from totals; look at min and max |
| Month totals do not match the total | Dates parsed wrongly or some dates missing | Check the date range and null dates |
| A percentage above 100% | Wrong denominator | Write the formula out in words |
| A cause is claimed with confidence | Data only shows association | Ask what else could explain it; consider an experiment |
Step 4: use AI to challenge your own work
AI is also a useful reviewer. Show it your finished query and result, and ask it to find holes. It may raise false alarms, so judge each point yourself, but it often spots a missing filter or an unclear definition.
Act as a sceptical senior analyst. Review my analysis below. Do not rewrite it; list problems.
Question: [question]
Metric definitions: [definitions]
Code: [paste code]
Result: [paste output]
My conclusion: [your conclusion]
Check for: double counting, wrong denominators, missing filters, unclear time periods, outliers, claims of cause the data cannot support, and anything that would make this result different on a longer time range. Rank the issues by how much they could change the conclusion.What to expect: Look for concrete, specific issues. Ignore vague advice. Test each real issue with code before changing your conclusion.
Explain this SQL to a beginner, line by line, and then tell me what could go wrong with it (for example duplicate rows after a join or NULL handling):
[paste query]What to expect: Useful for learning and for checking that the AI's query really does what the question needs.
A verification routine you can reuse
Before you share an AI-assisted result
- I ran the code myself on the real data; no number came only from the AI's text.
- I can explain each line of the query or script in my own words.
- Row counts make sense at each step (especially after joins and filters).
- I recomputed the headline number a second way, or by hand for a small slice.
- I looked at min, max, nulls and duplicates.
- Metric definitions and the time period are written in the report.
- My conclusions say 'associated with' unless I ran an experiment.
- I did not paste confidential or personal data into a tool that is not approved.
Test on a tiny case you can do by hand
Take 5 or 10 rows, work out the answer on paper or in a spreadsheet, then run the AI's query on just those rows. If they agree, scale up. This catches logic mistakes quickly.
How this comes up in interviews
Companies now ask how you use AI at work. A strong answer is: "I use it to draft queries and explain errors, I always run the code myself and check the totals with an independent method, and I do not share confidential data with unapproved tools." Some interviews give a task with AI allowed; they are judging whether you verify, not whether you can copy.
Try it: Catch the AI in a mistake
Ask an AI tool this without giving it any code: "Here are 6 order lines: (1001, 360), (1001, 150), (1002, 90), (1003, 220), (1004, 160), (1004, 120), where each pair is order_id and revenue. What is the average order value?" Then work it out yourself.
Then ask it to write pandas code for the same question and run that.
Key takeaways
- Let AI write code; let code compute the numbers. Do not trust totals the AI works out in text.
- Give the AI your schema, definitions and traps, and tell it not to state numbers before it sees output.
- Check results with an independent method: row counts, null and duplicate checks, recomputation, a hand-checked small slice.
- Most wrong numbers come from double counting, bad joins, wrong denominators and wrong dates.
- AI is a good sceptical reviewer, but you must judge its feedback.
- Protect confidential and personal data; you are responsible for what you send.
Check yourself
Finishing the quiz marks the lesson as done.
1. Why should the numbers in your report come from code you ran rather than from the AI's own text?
2. An AI-written query reports 20,000 orders, but df['order_id'].nunique() gives 12,000. What is the likely mistake?
3. What is the best way to verify an important total?
4. Which is the safest way to give an AI tool context about private customer data?
5. The AI says 'cold brew discounts caused a 15% sales rise.' From observational sales data alone, what is the correct stance?
Saved on this device. Create a free account to keep it on every device.
Practise this with Sam
A real mock interview, out loud, with an honest scorecard. Free to start.