Ninety seconds to an answer
Wanjiru is the only analyst at a fruit-and-vegetable cooperative with six collection depots across Kenya. At 16:40 on a Friday her manager asks which region brought in the most revenue last quarter, because the board meets on Monday and wants to know where to put a new cold store. She uploads three exports to an AI assistant that can run Python, types the question, and ninety seconds later has a tidy table, a bar chart and a confident paragraph: Eastern leads with KES 11.2 million, almost double Nyanza and nearly three times Rift Valley.
Every line of the code ran without an error. The table looks professional. And, as this lesson will show, the answer is wrong in almost every way that matters: the total is more than twice the real figure, the region it ranks third is really first, and one of the four regions in the table does not exist.
This is the new shape of a very old problem. Writing analysis code used to be slow, and checking happened along the way. In 2026 writing the code is nearly free; checking it is not, and it has become the main part of the job. The skills of this course matter more, not less: knowing what a join does to row counts, distrusting a number until it has been reconciled, asking what the decision really needs. This lesson is about using AI assistants and agents well: what they are good at, how their work goes wrong, how to verify it, and how to keep a person accountable for the result.
What assistants and agents do in 2026
By late 2026, language models are part of most data teams' daily tools, in three main forms.
- Chat assistants with a code sandbox. You upload files and ask questions; the model writes Python, runs it in an isolated environment, reads the output and writes an answer. Most large AI labs offer one.
- Assistants inside notebooks and editors. They complete code as you type, explain unfamiliar code, and write cells on request. Commercial notebook and editor products have their own; the open-source Jupyter AI extension is one that lets you choose the model behind it.
- Agents. A model given tools (run code, query a database, read files) and a goal, which works in a loop for many steps: write code, run it, read the result, decide what to do next. Some work in a terminal or a code repository; some are built into data platforms. How such loops work is covered in reasoning models, tools and agents in Lumenary CS.
Behind any of them may be a hosted model or an open-weight model (labs in China, Europe and the United States publish strong ones) running on your own hardware, which matters when data may not leave your organisation.
What they do well. Given a clear request, current models write correct pandas for common operations (filtering, grouping, reshaping, dates, plotting) far faster than anyone types. They translate between SQL and pandas, explain unfamiliar code, write regular expressions, draft tests and documentation, and suggest checks you had not thought of. Benchmarks of short, well-specified data-science coding problems, such as DS-1000, measure this kind of skill, and scores on them have risen quickly with each generation of models.
Where they struggle. Realistic analysis is different from a well-specified coding problem. When DSBench gave agents tasks drawn from modelling competitions and spreadsheet-based analysis challenges, the best agent of 2024 solved about a third of the analysis tasks. BLADE compared agents' analytic decisions (which variables to adjust for, how to transform them, which model to fit) with those of expert analysts, and found agents often stopped at basic analyses. Such numbers improve with each model generation, so treat them as snapshots. The durable finding is where the errors sit: in the parts of the work that depend on knowing what the data mean (what one row represents, which table is authoritative, what a missing value signifies) and what the person asking actually needs.
What the evidence says about people using them. In a randomised field experiment with management consultants (Dell'Acqua and colleagues, 2023), AI help made work faster and better on tasks inside the model's abilities, and made answers less correct on a task designed to fall just outside them, while making them more persuasive. The authors called the boundary a "jagged frontier": tasks that look equally hard to a person can fall on opposite sides of it. In a randomised trial with experienced open-source developers working in their own repositories (Becker and colleagues, 2025), allowing early-2025 AI tools made tasks take 19% longer, while the developers believed the tools had sped them up. Both used tools that have since improved, but together they say something that has held up: the gains are real but uneven, and people are poor judges of where they fall.
How generated analyses fail
Definition— silent failure
A silent failure is an analysis that runs to completion and produces a plausible result that is wrong. A loud failure stops with an error. In generated code, loud failures are the cheap ones: the agent sees the error and tries again. Silent failures pass straight through to the summary.
The agent's loop is very good at removing loud failures, which is exactly why what survives it is mostly silent. The common ones:
- Wrong joins. A key that is not unique in the lookup table multiplies rows and inflates every sum; an inner join quietly drops rows that do not match; a price list joined without regard to dates applies today's price to last year's sales (see wrangling data with pandas).
- Silent assumptions. Missing values filled with zero or dropped; a filter "to clean the data" that removes the interesting cases; a default aggregation (mean for median, sum for distinct count); units, currencies or time zones mixed; the wrong grain.
- Invented columns and values. A model that expects a column such as
discount_ratewrites code that uses it. If it does not exist the code fails loudly, and an agent trying to make the error go away may create the column with a "reasonable" constant. The KeyError is gone; a fabricated number is now in the result. - Leakage. Scaling or selecting features before splitting into training and test sets, or putting rows of the same customer on both sides, which flatters a model (see machine learning for tabular data).
- Unsupported summaries. The prose says "significant growth" when no test was run, or quotes a number that appears in no output. The summary is generated text too, trained to sound like a good analysis.
- Hidden forking paths. An agent that tries many analyses and reports the one that "worked" finds patterns that are not there (its own section below).
Auditing an analysis that runs
Here is Wanjiru's problem, recreated with synthetic data. There are three tables: deliveries (one row per delivery: date, depot, product, kilograms), prices (a price per kilogram for each product, with the date it took effect) and depots (which region each depot belongs to). The data contain three traps of the kind real exports contain: prices change during the quarter, an old row in the depot table puts Machakos in a second region, and Nakuru's scale was broken for August, so those weights are missing. The first block runs the analysis exactly as an assistant might write it.
import numpy as np
import pandas as pd
# A synthetic quarter at a fruit-and-vegetable cooperative (money in KES).
rng = np.random.default_rng(7)
depots = pd.DataFrame({"depot": ["Nakuru", "Eldoret", "Meru", "Embu", "Kisii", "Machakos", "Machakos"],
"region": ["Rift Valley", "Rift Valley", "Eastern", "Eastern", "Nyanza",
"Eastern", "Nairobi Metro"]}) # the last row is stale
prices = pd.DataFrame({
"product": ["mango", "mango", "mango", "avocado", "avocado", "tomato", "kale"],
"valid_from": pd.to_datetime(["2026-07-01", "2026-08-01", "2026-09-01", "2026-07-01",
"2026-08-15", "2026-07-01", "2026-07-01"]),
"price_per_kg": [55.0, 48.0, 40.0, 90.0, 110.0, 70.0, 35.0]}) # a price history
rows = []
for depot, product, size in [("Nakuru", "tomato", 900), ("Eldoret", "kale", 1100),
("Meru", "mango", 600), ("Embu", "mango", 500),
("Kisii", "avocado", 500), ("Machakos", "mango", 350)]:
for day in pd.date_range("2026-07-01", "2026-09-30", freq="D"):
if rng.random() < 0.6:
rows.append((day, depot, product, round(rng.gamma(9, size / 9), 1)))
deliveries = pd.DataFrame(rows, columns=["date", "depot", "product", "kg"])
broken = (deliveries["depot"] == "Nakuru") & (deliveries["date"].dt.month == 8)
deliveries.loc[broken, "kg"] = np.nan # Nakuru's scale was broken in August
# ---- The analysis as an assistant wrote it (it runs without a single error) ----
df = deliveries.merge(prices, on="product")
df = df.merge(depots, on="depot")
df["kg"] = df["kg"].fillna(0)
df["discount_rate"] = 0.05 # first draft used a column that does not exist; this was the "fix"
df["revenue"] = df["kg"] * df["price_per_kg"] * (1 - df["discount_rate"])
by_region = df.groupby("region")["revenue"].sum().sort_values(ascending=False)
print(f"{len(deliveries)} deliveries in, {len(df)} rows analysed")
print("Q3 revenue by region, KES million:")
print((by_region / 1e6).round(2).to_string())
print(f"Total: KES {by_region.sum() / 1e6:.1f} million")Every line is reasonable-looking pandas, and nothing in the output looks alarming unless you know to look. Only the first printed line hints at trouble: 345 deliveries went in and 916 rows came out.
The second block does what a careful reviewer does, in order. It checks the inputs against the assumptions the code makes. It checks invariants of the result (a join of deliveries to a lookup table must keep one row per delivery; the revenue per kilogram must lie within the price list). It rebuilds the pipeline with the assumptions made explicit. It recomputes the total by an independent route. And it reports what it cannot know as a range rather than hiding it.
import numpy as np
import pandas as pd
# The same synthetic quarter as above.
rng = np.random.default_rng(7)
depots = pd.DataFrame({"depot": ["Nakuru", "Eldoret", "Meru", "Embu", "Kisii", "Machakos", "Machakos"],
"region": ["Rift Valley", "Rift Valley", "Eastern", "Eastern", "Nyanza",
"Eastern", "Nairobi Metro"]})
prices = pd.DataFrame({
"product": ["mango", "mango", "mango", "avocado", "avocado", "tomato", "kale"],
"valid_from": pd.to_datetime(["2026-07-01", "2026-08-01", "2026-09-01", "2026-07-01",
"2026-08-15", "2026-07-01", "2026-07-01"]),
"price_per_kg": [55.0, 48.0, 40.0, 90.0, 110.0, 70.0, 35.0]})
rows = []
for depot, product, size in [("Nakuru", "tomato", 900), ("Eldoret", "kale", 1100),
("Meru", "mango", 600), ("Embu", "mango", 500),
("Kisii", "avocado", 500), ("Machakos", "mango", 350)]:
for day in pd.date_range("2026-07-01", "2026-09-30", freq="D"):
if rng.random() < 0.6:
rows.append((day, depot, product, round(rng.gamma(9, size / 9), 1)))
deliveries = pd.DataFrame(rows, columns=["date", "depot", "product", "kg"])
broken = (deliveries["depot"] == "Nakuru") & (deliveries["date"].dt.month == 8)
deliveries.loc[broken, "kg"] = np.nan
def check(name, ok, detail):
print(f"[{'pass' if ok else 'FAIL'}] {name}: {detail}")
# 1. Check the inputs before joining anything.
check("one price row per product", prices["product"].is_unique,
f"{prices['product'].duplicated().sum()} extra rows: it is a price history, not a price list")
dup = depots[depots["depot"].duplicated(keep=False)]
check("one region per depot", depots["depot"].is_unique, f"{dup.values.tolist()}")
missing = deliveries["kg"].isna()
check("every delivery weighed", not missing.any(),
f"{missing.sum()} missing, at {sorted(deliveries.loc[missing, 'depot'].unique())}")
# 2. The assistant's join, checked: row counts and an implied unit price.
naive = deliveries.merge(prices, on="product").merge(depots, on="depot")
check("join keeps one row per delivery", len(naive) == len(deliveries),
f"{len(deliveries)} deliveries became {len(naive)} rows")
implied = (naive["kg"] * naive["price_per_kg"]).groupby(naive["region"]).sum() / \
deliveries.merge(depots.drop_duplicates("depot"), on="depot").groupby("region")["kg"].sum()
check("implied price per kg within the price list", implied.max() <= prices["price_per_kg"].max(),
f"Eastern works out at KES {implied['Eastern']:.0f}/kg; the dearest product costs "
f"{prices['price_per_kg'].max():.0f}")
try:
deliveries.merge(depots, on="depot", validate="many_to_one")
except pd.errors.MergeError as err:
print(" pandas can enforce the expectation itself -> MergeError:", err)
# 3. The corrected pipeline: the price in force on the day, one region per depot (confirmed
# with the cooperative: Machakos is in Eastern), missing weights kept missing.
regions = depots.drop_duplicates("depot", keep="first")
fixed = pd.merge_asof(deliveries.sort_values("date"), prices.sort_values("valid_from"),
left_on="date", right_on="valid_from", by="product")
fixed = fixed.merge(regions, on="depot", validate="many_to_one")
fixed["revenue"] = fixed["kg"] * fixed["price_per_kg"]
assert len(fixed) == len(deliveries) and np.isclose(fixed["kg"].sum(), deliveries["kg"].sum())
# 4. An independent recomputation in plain Python must agree with pandas.
total = 0.0
for r in deliveries.itertuples():
if r.kg == r.kg: # skip NaN
in_force = prices[(prices["product"] == r.product) & (prices["valid_from"] <= r.date)]
total += r.kg * in_force.sort_values("valid_from")["price_per_kg"].iloc[-1]
check("pandas total equals a plain-Python loop", np.isclose(total, fixed["revenue"].sum()),
f"KES {total / 1e6:.3f} million both ways")
# 5. Missing weights: report a range instead of a silent zero.
low = fixed.groupby("region")["revenue"].sum() / 1e6 # missing left out
fill = fixed.loc[fixed["depot"] == "Nakuru", "kg"].median() # or: a typical delivery
high = (fixed["kg"].fillna(fill) * fixed["price_per_kg"]).groupby(fixed["region"]).sum() / 1e6
ai = pd.Series({"Eastern": 11.21, "Nyanza": 5.70, "Rift Valley": 3.95, "Nairobi Metro": 2.54})
table = pd.DataFrame({"assistant": ai, "checked, missing left out": low, "checked, missing filled": high})
print()
print(table.sort_values("checked, missing filled", ascending=False).round(2).to_string(na_rep="-"))Read the failures one at a time, because each corresponds to an error class from the list above.
- The price join. Mango has three price rows and avocado two, so joining on
productalone copied every mango delivery three times and every avocado delivery twice. The fix is not to drop duplicate prices (which would you keep?) but to join each delivery to the price in force on its date, which is whatpd.merge_asofdoes. - The depot join. A stale row put Machakos in two regions, doubling its deliveries and creating a region, Nairobi Metro, that the cooperative does not have. Passing
validate="many_to_one"tomergeturns this silent duplication into a loud error; it costs one argument and belongs on every lookup join. Which row is right is a question for the cooperative, not the code. - The missing weights.
fillna(0)claimed that Nakuru delivered nothing in August. Leaving them out gives a lower bound; filling them with a typical Nakuru delivery gives an estimate. Rift Valley comes first either way, and saying so is more useful than either number alone. - The invented discount. There is no discount anywhere in the data; the 5% is fiction. The corrected figures are gross revenue, and the report should say so.
The implied unit price check found the join problem without knowing anything about joins: Eastern's revenue per kilogram came out at KES 143, more than the dearest product costs. Checks that compare a result with something you know must be true are the most valuable kind, because they catch errors you did not anticipate. The independent recomputation is the other powerful habit: a slow, obvious loop and the fast pandas pipeline agree to the shilling, which would be unlikely if either had a bug the other lacked.
The corrected answer reverses the assistant's ranking: Rift Valley first (KES 4.16 to 5.41 million), then Eastern (3.94) and Nyanza (2.97). The assistant's total was 2.1 times the real one. None of the five checks needed cleverness. They needed someone who knew to ask.
Messy text: extraction with validation
Some of the best uses of language models in data work involve no code at all. Much valuable data is trapped in free text: field notes, complaint forms, inspection reports, text messages from people with better things to do than fill in a form. A language model asked to return structured fields (often with structured output, where the reply is constrained to match a JSON schema) can turn them into a table at scale, in many languages and spellings.
Structured output guarantees the shape of the answer, not its truth. So treat the model as a measuring instrument: validate every record, and measure the error rate of what you accept.
Suppose market agents text the cooperative the day's wholesale prices however they like, in English mixed with Swahili and Sheng. The block shows ten messages and the records a model returned (written out, so the block runs without a model), then validates each record: the schema (types, required fields), a controlled vocabulary (known products and units), grounding (the extracted number must appear in the message) and plausible ranges.
import re
# Free-text price reports from market agents, and what a language model returned when asked
# for JSON with the fields market, product, price, unit. (The model outputs are written out
# here, so that the block runs without one.)
messages = [
"Wakulima market: tomatoes 80 per kg today",
"Kongowea - mango 1,200/= per crate",
"Avocado prices same as last week at Kisii",
"sukuma wiki 30 bob a kilo, Kangemi",
"Nakuru: onions KSh 2,400 for a 20 kg bag",
"Eldoret maize 50 kg bag 3,500",
"Embu: bananas 25 each",
"Meru mango 45 per kg, up from 40",
"Kisumu tomatoes 90/kg",
"Marikiti closed today (rain)",
]
extracted = [
{"market": "Wakulima", "product": "tomato", "price": 80, "unit": "kg"},
{"market": "Kongowea", "product": "mango", "price": 1200, "unit": "kg"},
{"market": "Kisii", "product": "avocado", "price": 100, "unit": "kg"},
{"market": "Kangemi", "product": "collard greens", "price": 30, "unit": "kg"},
{"market": "Nakuru", "product": "onion", "price": 120, "unit": "kg"},
{"market": "Eldoret", "product": "maize", "price": 3500, "unit": "bag"},
{"market": "Embu", "product": "banana", "price": 25, "unit": "piece"},
{"market": "Meru", "product": "mango", "price": 40, "unit": "kg"},
{"market": "Kisumu", "product": "tomato", "price": 90, "unit": "kg"},
{"market": "Marikiti", "product": None, "price": None, "unit": None},
]
# What a careful person read in each message (used only to score the validator).
truth_ok = [True, False, False, False, True, True, True, False, True, True]
PRODUCTS = {"tomato", "mango", "avocado", "kale", "onion", "maize", "banana"}
UNITS = {"kg", "bag", "crate", "piece"}
PER_KG = {"tomato": (20, 200), "mango": (20, 200), "avocado": (30, 300), "kale": (10, 100),
"onion": (30, 250)} # plausible KES per kg
def problems(text, rec):
if rec["product"] is None and rec["price"] is None:
return ["no price reported"]
found = []
if not isinstance(rec["price"], (int, float)) or rec["price"] <= 0:
found.append("price is not a positive number")
if rec["product"] not in PRODUCTS:
found.append(f"unknown product {rec['product']!r}")
if rec["unit"] not in UNITS:
found.append(f"unknown unit {rec['unit']!r}")
numbers = {int(n.replace(",", "")) for n in re.findall(r"\d[\d,]*", text)}
if rec["price"] not in numbers:
found.append(f"{rec['price']} does not appear in the message")
if rec["market"].lower() not in text.lower():
found.append("market not in the message")
lo, hi = PER_KG.get(rec["product"], (0, float("inf")))
if rec["unit"] == "kg" and not lo <= rec["price"] <= hi:
found.append(f"{rec['price']} per kg is outside {lo}-{hi}")
return found
accepted = []
for text, rec, ok in zip(messages, extracted, truth_ok):
p = problems(text, rec)
status = "accept" if not p else ("skip" if p == ["no price reported"] else "REVIEW")
if status == "accept":
accepted.append(ok)
print(f"{status:6} | {text[:38]:38} | {'; '.join(p)}")
print(f"\naccepted automatically: {len(accepted)}, of which actually wrong: {accepted.count(False)}")The checks caught four kinds of problem. The avocado price of 100 was invented: the message gives no price, and 100 appears nowhere in it. The Kongowea mango was priced per crate but recorded per kilogram, and the range check caught a mango at KES 1,200 a kilogram. Sukuma wiki became "collard greens", a fair translation that is not in the product list, so a person maps it to kale once and the mapping goes into the instructions. And the Nakuru onions were flagged although the model was right: it divided 2,400 by 20 to get 120 a kilogram, a number not in the message. That false alarm suggests a better design: ask the model only to extract what is written (2,400, a 20 kg bag) and do the arithmetic in code, where it can be tested.
Then the uncomfortable line: of five records accepted automatically, one is wrong. The Meru message has two prices, today's 45 and last week's 40, and the model took the wrong one. Both are in the text and both are plausible, so no rule can catch it. Hence the professional practice: measure. Have a person check a random sample of accepted records, estimate the error rate with a confidence interval (see estimation and confidence intervals), and decide whether that rate is acceptable for the use.
Two practical notes. Record the model: its name and version, the exact prompt, the date and the raw outputs, because the model behind a name can change and a re-run months later may differ. And measure again whenever the model, the prompt or the kind of message changes: an extractor validated in July is not validated on the new message format the agents adopted in October.
Agents that explore data
An agent given a data set and a vague goal ("find what drives late deliveries") does what a diligent junior analyst does, much faster: look at distributions, try groupings, fit models, follow whatever looks interesting. That speed helps with the routine parts of exploration (profiling every column, drafting charts). It is dangerous for the interesting part: an agent that tries a hundred comparisons and reports the best has run a hundred tests and told you about one.
Statisticians call this the garden of forking paths: every choice of subgroup, outcome, filter or model is a path, and following many paths to a "significant" result makes the significance meaningless (see multiple testing and reproducibility). People did this long before AI; in the many-analysts study, 29 expert teams given one data set and one question produced odds ratios from 0.89 to 2.93. An agent can walk more paths in an afternoon than a team could in a year, and unless it was told to, it will not mention the paths that led nowhere.
The block simulates it. Each data set has 400 rows, an outcome and eight attributes with five levels each, and no real relationship between them. The "agent" compares every level of every attribute with the rest (40 tests) and reports the smallest p-value. Then two defences: a Bonferroni threshold that accounts for the 40 tests, and confirmation on held-out data, where the agent explores on one half and its best finding is re-tested once on the other.
import math
import numpy as np
def p_value(y, mask):
"""Two-sided p-value for 'mean inside the subgroup differs from mean outside' (z-test)."""
a, b = y[mask], y[~mask]
se = math.sqrt(a.var(ddof=1) / len(a) + b.var(ddof=1) / len(b))
return math.erfc(abs(a.mean() - b.mean()) / se / math.sqrt(2))
def explore(y, X):
"""An eager 'agent': test every level of every attribute against the rest; keep the best."""
best = (1.0, None)
for j in range(X.shape[1]):
for level in range(5):
best = min(best, (p_value(y, X[:, j] == level), (j, level)))
return best
rng = np.random.default_rng(42)
trials, n = 1000, 400
found = confirmed = bonferroni = 0
for _ in range(trials):
X = rng.integers(0, 5, size=(n, 8)) # 8 attributes with 5 levels each: 40 subgroups
y = rng.normal(size=n) # an outcome unrelated to every attribute
p, _ = explore(y, X)
found += p < 0.05
bonferroni += p < 0.05 / 40
half = n // 2 # explore on one half, confirm on the other
p_explore, (j, level) = explore(y[:half], X[:half])
if p_explore < 0.05:
confirmed += p_value(y[half:], X[half:, j] == level) < 0.05
print(f"datasets with no real effect: {trials}")
print(f"agent reports a 'significant' subgroup: {found / trials:.1%}")
print(f"... with a Bonferroni threshold of 0.05 / 40: {bonferroni / trials:.1%}")
print(f"... after confirming on held-out data: {confirmed / trials:.1%}")The practical rules for exploring agents follow directly.
- Keep a log of every analysis the agent ran, not just the ones it reported. The number of paths tried is part of the result; a finding that was one of 40 tries must be reported as such.
- Hold data back. Let the agent explore on one part of the data and confirm its best ideas on a part it has never seen, once. Splitting by time (explore on last year, confirm on this year) is often even better, because it also tests whether the pattern lasts.
- Treat findings as hypotheses. An exploring agent is an excellent generator of questions. A causal claim still needs a design that supports it (causal inference), often an experiment (experiments in products).
Safety and data protection. An agent that runs code deserves the controls you would give a new contractor on day one. Run it in a sandbox without network access unless it needs it; give it read-only access to a copy or view of the data, never write access to production systems; review any package it wants to install, because models sometimes suggest package names that do not exist, which someone malicious could later register (Spracklen and colleagues). Text inside the data can contain instructions aimed at the model, so an agent that reads untrusted text should not also hold powerful tools (Greshake and colleagues; see also security in Lumenary CS). And before personal data go to a hosted model, check what your organisation's agreement with the provider says about retention, training on inputs and where data are processed, and whether the law and the people's consent allow it at all. When in doubt, use synthetic or aggregated data, or a model you host yourself (more in responsible data science).
Keeping a human accountable
A model cannot be accountable. It cannot explain itself to the board on Monday, be asked in six months why the number changed, or bear the consequences of a wrong cold-store decision. So the rule is simple: a named person owns each result, whoever or whatever wrote the code. The practices that make that ownership real are the ones this course teaches throughout, applied with more discipline because the code now arrives faster than it can be read.
- Review the code, not the prose. The summary is the least reliable part. Read the code behind each number, and check every claim against a printed output.
- Make the result reproducible without the model: a script with a lock file, a seed and a data fingerprint (as in the data science workflow), with this lesson's checks written as tests. If it can only be reproduced by asking the assistant again, it cannot be reproduced.
- Check before trusting: row counts and key uniqueness around every join, totals reconciled with an independent source (finance's figure, last quarter's report), ranges that must hold, and a second route to the headline number.
- Beware automation bias. People tend to accept a system's output and look less hard for its errors, and neither expertise nor training prevents it (Parasuraman and Manzey, 2010). Fluent prose makes it worse. Say what you expect the answer to be before reading the assistant's.
- Disclose which AI tools were used, for what, and how the work was checked. Many journals require this and do not allow AI tools as authors (see the ICMJE recommendations).
- Match the care to the stakes. A chart for a discussion needs less checking than a number that decides who gets a loan. Where models feed decisions about people, regulation may require documented human oversight (the EU's AI Act does for "high-risk" uses such as credit scoring and recruitment).
The question beneath all of this is not "is the AI good enough?" but "what would have to be true for this number to be wrong, and have I looked?" That was always the heart of data science. AI makes asking it cheaper (an assistant asked "what could make this join wrong?" would have suggested most of Wanjiru's checks) and makes skipping it more tempting. The time saved on typing is best spent where the work needs someone who knows what the data mean and will answer for the result.
Common misconceptions
Misconception
"The code ran, so the analysis is right." Running is the weakest test there is. The cooperative's analysis ran perfectly and was wrong by a factor of two.
Misconception
"I asked the model to check its work, and it said it was correct." Self-review catches some slips, but the reviewer shares the assumptions of the writer. Verification means checks that do not depend on them: invariants, reconciliation with independent figures, a second implementation, a person who knows the data.
Misconception
"Temperature zero makes an AI analysis reproducible." It reduces variation, but outputs can still change between runs and model versions. Reproducibility comes from saving the code, environment, data fingerprint and the model's raw outputs, so the analysis reruns without the model.
Misconception
"An agent that explores more finds more." It finds more apparent patterns, mostly noise. Without a log of what was tried and held-out confirmation, its findings will not replicate.
Exercises
1. Data science with AI assistants and agents
Warm-upHumanAn agent writes and runs an analysis for you. Which outcome is the most dangerous?
2. Data science with AI assistants and agents
CoreHumanA deliveries table has 6 rows for mango, 4 for tomato and 2 for kale. The price table is a price history with 3 rows for mango, 1 for tomato and 2 for kale. An assistant writes deliveries.merge(prices, on="product"). How many rows does the result have?
3. Data science with AI assistants and agents
CoreComputationalWrite checked_lookup(left, right, key), a lookup join that cannot fail silently. It returns left with the columns of right added, matched on key, with exactly one row per row of left, in the same order. It must raise ValueError if a key is repeated in right, or if some key of left does not appear in right. It must not modify its inputs.
4. Data science with AI assistants and agents
CoreComputationalA language model extracts a price from each market message. Write the grounding check grounded(text, value): it returns True if value appears in text as a complete number, and False otherwise. Thousands commas are allowed in the text (1,200 is 1200), and decimals may appear (80.5). Part of a longer number does not count: 120 does not appear in "1200 per crate".
5. Data science with AI assistants and agents
CoreHumanAn agent runs 20 independent tests, each at the 0.05 level, on data in which nothing real is going on. What is the probability, as a percentage rounded to the nearest whole number, that at least one test comes out 'significant'?
6. Data science with AI assistants and agents
CoreHumanAn agent explored last year's delivery data and found that deliveries from one depot on Mondays are unusually late (p = 0.003). It tried about 60 groupings before finding this one. What is the best next step?
7. Data science with AI assistants and agents
CoreHumanWhich of these practices help make an AI-assisted analysis one that a named person can answer for? Select all that apply.
Further reading and resources
- DS-1000: A Natural and Reliable Benchmark for Data Science Code Generation · Yuhang Lai et al. · 2022A thousand data-science coding problems drawn from real questions about NumPy, pandas, scikit-learn and other libraries.
- DSBench: How Far Are Data Science Agents from Becoming Data Science Experts? · Liqiang Jing et al. · 2024Realistic analysis and modelling tasks; the best agents of 2024 solved about a third of the analysis tasks.
- BLADE: Benchmarking Language Model Agents for Data-Driven Science · Ken Gu et al. · 2024Compares the analytic decisions agents make with those of expert analysts on the same research questions.
- Navigating the Jagged Technological Frontier: Field Experimental Evidence of the Effects of AI on Knowledge Worker Productivity and Quality · Fabrizio Dell'Acqua et al. · 2023A randomised experiment in which AI help raised quality on some tasks and lowered correctness on one designed to fall outside its abilities.
- Measuring the Impact of Early-2025 AI on Experienced Open-Source Developer Productivity · Joel Becker, Nate Rush, Elizabeth Barnes and David Rein · 2025A randomised trial in which experienced developers took longer with AI tools while believing they were faster.
- Many analysts, one data set: making transparent how variations in analytic choices affect results · Raphael Silberzahn et al. · 2018Twenty-nine teams, one data set and one question, and a wide spread of answers.
- Complacency and bias in human use of automation: an attentional integration · Raja Parasuraman and Dietrich Manzey · 2010The review behind the term automation bias.
- We Have a Package for You! A Comprehensive Analysis of Package Hallucinations by Code Generating LLMs · Joseph Spracklen et al. · 2024
- Not what you've signed up for: compromising real-world LLM-integrated applications with indirect prompt injection · Kai Greshake et al. · 2023
- pandas documentation — merge, including the validate argument
- Jupyter AI, an open-source assistant extension for JupyterLab