Topic 4 of 5 · 4 min read
Explaining a result you did not write
Goal: Explain the filters, grain and exclusions behind an AI-produced number and name one question it cannot answer.
If you put your name on a number, you must be able to say what rows it counts, what it leaves out and what question it does not answer, even when an assistant wrote the code. "The AI computed it" is not a defence when a manager asks why the figure differs from last quarter's.
Check yourself · 1 of 3
A manager asks why a generated number differs from last quarter's. What do you need to know first?
Why it matters
Generated pandas and SQL are often dense: chained filters, a groupby, a merge and a rename in six lines. The number at the end hides a set of decisions the agent made for you. Some match your intent. Some do not. The meeting is the wrong place to discover which is which.
How to do it
Read the code and write a short note with five parts:
- Population. Which rows go in? List every filter: date range, status values,
dropna,query,WHERE,HAVING, joins that remove rows. - Grain. What does one row of the result represent: an order, a customer-month, a product? State the grouping keys.
- Metric. Exactly how is the number computed: sum of which column, count of what, distinct or not, mean of means or mean of rows?
- Exclusions. What is not counted that a listener might assume is counted: refunds, test accounts, rows with null region, the current partial month.
- Limits. One question this number cannot answer, for example "this counts orders placed, not revenue collected."
To read faster, run the code in pieces: print the frame after each step, or ask the assistant to explain it line by line and then check its explanation against the printed shapes. Do not rely on the explanation alone: models describe what the code was meant to do.
Before and after
The agent's answer: "Churn last quarter was 3.1%."
Weak defence: "That is what the notebook says."
Strong defence: "A customer counts as churned if they had an active subscription on 1 July and none on 30 September. Trial accounts and customers who left and came back are excluded. The denominator is the 4,200 customers active on 1 July. It measures subscription churn, not revenue churn, so a downgrade is not counted."
What goes wrong
- Explaining the intent, not the code. You describe what you asked for, but the query filtered
status = 'paid'and dropped pending orders. - Unstated denominators. A rate with no base cannot be compared to last quarter.
- Mean of means. Averaging group averages gives a different number from the average of all rows when groups differ in size.
- Overclaiming. A number about orders gets presented as a number about customers.
Examples
Reading a generated query
SELECT date_trunc('month', created_at) AS month,
COUNT(DISTINCT user_id) AS buyers
FROM orders
WHERE status = 'paid' AND is_test = false
GROUP BY 1;
Population: paid, non-test orders. Grain: one row per month. Metric: distinct users with at least one paid order. Exclusions: pending, refunded-before-paid and test orders. Limit: it says nothing about how many orders each buyer placed.
A defensible one-paragraph note
"Average order value was 62.40 in October. It is total paid order amount divided by the number of paid orders, excluding test accounts, over 1-31 October in UTC. Refunds are not netted out. It does not tell us how much of that value came from first-time versus returning customers."
Key points
- You must be able to state the population, grain, metric, exclusions and limits of any number you present.
- List every filter and join that removes rows, because each one is a decision the agent made.
- Run the code in pieces and print each intermediate frame to confirm what the line does.
- Use the assistant's line-by-line explanation as a draft and check it against the actual output.
- Always state the denominator of a rate and one question the number cannot answer.
Common mistakes
- Presenting a number without having read the filters, so a changed status list goes unnoticed.
- Quoting a rate without saying what the denominator is.
- Taking the assistant's summary of its own code as proof of what the code does.
- Describing an order-level figure as if it described customers.
Check yourself · 2 of 3
A query computes average order value as the mean of each customer's average order. Why can this mislead?
Check yourself · 3 of 3
The code says WHERE status = 'paid'. What should your explanation of the number include?
Practice items, not counted towards your mastery.
Start here
- Jupyter AI documentation (opens in a new tab)DocsFree
How the chat and magic-command assistants work in JupyterLab, and how to point them at different model providers.
- marimo reactive Python notebooks (opens in a new tab)ToolFree
A notebook that stores plain .py files and re-runs dependent cells, which removes hidden state by design.
- Ten simple rules for reproducible research in Jupyter notebooks (opens in a new tab)PaperFree
Concrete rules for ordering cells, recording dependencies and sharing notebooks that others can re-run.
More for this topic
- Merge, join, concatenate and compare (pandas) (opens in a new tab)DocsFree
Join types, the validate argument and the indicator column used to catch dropped and duplicated rows.