Skip to content
mentoor

A notebook investigation with an AI pair

For engineers

An agent-driven notebook analysis, debugged, made reproducible and error-analysed.

An AI pair can speed up a notebook investigation, but only if you review each cell before it runs, clean the data with logged counts, reconcile every total, debug from evidence, and read the agent's own traces for repeat failures. The agent writes code fast. You still own the number.

The case

Larkspur Outdoor is an online shop with about 50,000 orders a year. It is 2 December 2026. Priya, a data engineer, has been asked one question: why did the repeat-purchase rate look lower in November? She works in a Jupyter notebook with an AI agent (Jupyter AI, Colab, Hex or marimo all work the same way) and a folder of Parquet files that DuckDB can query. Finance will read the answer on Friday.

Five jobs, five skills

  1. Drive the notebook, do not hand it over. The agent proposes cells. Priya reads each one before it runs and asks three things: what does it read, what does it write, and what does it assume? A cell that overwrites a source file is rejected. Because the notebook assistant is hosted, she also decides what data it may see, and gives it a small synthetic sample instead of real customers.
  2. Clean with a count for every change. The exports come from a US and a UK store. One writes 03/12/2026 for 12 March and the other for 3 December, and a German file writes 1.299,00 for a little under thirteen hundred. The agent's first pass parses all of it with one rule and says "cleaned". Priya parses each source with its own format and requires a log line with a row count for every rule.
  3. Query and reconcile. DuckDB reads the Parquet files in place. A join of orders to order items repeats each order total once per item, so revenue comes out 2.3 times too high. A query that runs is not a query that is right. Priya compares each month with finance's ledger and investigates the one month that disagrees.
  4. Debug from evidence. A merge fails with duplicate labels, daily counts miss orders near midnight, and a number moved between two tags. In each case she tests a specific hypothesis: count the duplicates, look at the timestamps, run a scripted bisect. She rejects fixes that hide the error, such as a bare try and except.
  5. Study the agent's failures. Priya reads 40 traces of the agent's own runs, writes a specific note for each, groups the notes into failure modes and counts them. Silent row drops and join fan-out lead. Both are cheap to test in code, so she adds code checks and does not rely on a longer prompt.

Before and after

Before: the agent reports "18,420 repeat customers, ran cleanly" while its tool output is a KeyError. The cleaning log says "complete" and 1,255 rows are gone. The notebook runs only because a deleted cell left a variable in memory.

After: every cell is read before it runs. The cleaning log ties 52,310 rows in to the rows out. A final check restarts the kernel and runs the notebook from the top on a pinned input snapshot with a fixed random seed. The same numbers appear, and a colleague gets them too. The answer to finance carries its filters: repeat rate means customers with a shipped order in 2026 who have two or more.

What goes wrong

  • Confident reports without output. An agent will describe a result it never produced. Match every number to the output of a real run.
  • Silent loss and silent duplication. Joins, filters and parsing change row counts without an error. Row counts and totals are the cheapest checks you have.
  • Fixes that hide the cause. A try and except, a plug figure or a library upgrade can make the symptom vanish. The cause is still in the data.
  • A reviewer who reads one trace. One failure is an anecdote. Forty, counted, show you what to fix first.

What Priya's team gets

An answer that holds up when someone asks how it was made. The agent does the typing, and Priya supplies the checks: a reconciled total, a log of every row dropped, a notebook that runs from a clean start, and a short list of the agent's known failure modes with a code check for each.

Steps

  1. Read every cell before it runs

    Skill: dataeng-ai-notebooks

    Priya asks the agent for one cell at a time. Before running, she reads what it reads, what it writes and what it assumes. She rejects any cell that overwrites an input, and she gives a hosted assistant a synthetic sample, not real customers. Outputs go to a new file in an output folder.

    A cell Priya rejects

    cell 2

    orders = pd.read_csv('orders.csv')orders.to_csv('orders.csv', index=False)  # rejected: overwrites the source
  2. Clean each source with its own rules and a count

    Skill: data-clean

    The US store writes dates month first and the UK store day first, and the German file uses a decimal comma. She parses each source with its own settings, dedupes on order id keeping the latest export, and requires a row count for every rule so the numbers tie from file to table.

    Cleaning log she asks for
    Every rule has a count
    RuleRows changedRows dropped
    Parse UK dates day first182040
    Parse German amounts31200
    Drop duplicate order ids, keep latest0412
    Drop rows with no order id038
  3. Query in DuckDB and reconcile with the ledger

    Skill: dataeng-analytics

    She lets DuckDB read the Parquet files in place. Because an order joined to its items repeats the order total on each item row, she sums item amounts and compares each month with finance's ledger. A month that disagrees gets an order-id comparison, not a plug figure.

  4. Debug from evidence, not from a plausible story

    Skill: code-debugging

    For each failure she states a hypothesis and tests it: duplicated emails for a failed merge, orders within an hour of midnight for a day-count gap, a scripted git bisect for a number that moved. She rejects a fix that skips the error, for example a try and except that continues.

    Bisect plan

    Goal: Find the commit that changed October revenue

    1. Write run_check.py to exit 1 unless October revenue is 1,239,800
    2. git bisect start HEAD v1
    3. git bisect run python run_check.py
    4. Read the first bad commit and decide whether the change was intended
  5. Make the analysis reproducible

    Skill: dataeng-ai-notebooks

    She moves the notebook into a script with a dated input snapshot, a fixed random seed and no dependence on cell order. A final restart-and-run-all, on a clean machine if possible, must print the same numbers. The result is shared with its filters, grain and exclusions stated in a sentence.

  6. Read the agent's traces and count its failures

    Skill: evals-error-analysis

    She reads 40 traces, writes a specific note for each, groups the notes into modes and counts them. The top modes get code checks, such as a total that must match the source. She stops when new batches add no new mode and starts again after a prompt or tool change.

    Failure modes after 40 traces
    Counts
    ModeTraces
    Silent row drop11
    Join fan-out9
    Date parsed in the wrong order7
    Unverified claim6
    Other7

Skills this scenario uses

Where to study