Saltar al contenido principal

Primera lección gratuita

The Assistant Wrote the Pipeline

As a machine learning engineer, you review an AI-written feature pipeline for the mistakes that run cleanly: a feature from after the decision, a feature computed two ways, a random split where time matters and rows a join drops.

Lección 1 de 67 min de lectura

En esta lección vas aMostrar el texto completo

You leave with a checklist for the next change.

  1. Find a feature that is only known after the outcome, in code that trains and runs cleanly
  2. Check that each feature is computed the same way in training and serving, and that the split matches how the model is used
  3. Count rows through every join and filter, and decide what to ask the assistant for and what to read yourself

1 de 5Why is an eighteen-point jump the first thing to doubt?

Why is an eighteen-point jump the first thing to doubt?

Three engineers run the trust-and-safety models at an online marketplace for second-hand goods, and Lena Varga, a fictional one, has been among them for about four years. Their classifier scores every new listing and sends the riskiest 2% to human reviewers, who look for counterfeits, prohibited items and scams.

On Tuesday, October 6, Lena asks the team's AI coding assistant to add seller-history features to the retrain. In about an hour it writes the feature pipeline, the training job and the evaluation. Everything runs. The new model's recall at the 2% flag rate, the share of risky listings it catches when it flags its top 2%, is 88%. The model in production scores 70%.

The second ML engineer posts a rocket emoji in the team channel. Lena does not. A retrain with a few seller features rarely buys eighteen points on a problem the team has worked for years. When a result jumps that far, she treats it as a bug until she can show it is not.

That instinct matters more now than it did when she typed the code herself. In a 2025 randomized trial by METR, a research nonprofit, experienced open-source developers took 19% longer on real issues when AI tools were allowed. They had expected to be 24% faster, and afterwards believed they had been 20% faster. In February 2026 METR said developers were likely more sped up by AI tools in early 2026 than its 2025 estimate showed, but that selection effects made its new data only weak evidence of how much. The point Lena takes is narrower: how fast the work felt is not a measurement. The same goes for how right the code looks.

The assistant writes code that runs. What it cannot know is how her company's data arrives in time. So on Wednesday morning she reads the change line by line, looking for four mistakes that raise no error.

Which feature knew the answer before the model did?

The assistant added a feature called buyer_reports_count: how many buyers reported the listing. In training it is one of the strongest features in the model. Lena checks the query behind it. It counts reports over the listing's whole life.

That is the problem. Most buyer reports arrive after a listing is live, and many after a reviewer has already removed it. The model scores a listing the moment it is published, when the count is zero for every listing. In training, the feature tells the model the answer. At serving time, it tells it no more than a blank.

A feature whose value is only known after the outcome the model predicts is target leakage. It flatters the score in training and is missing, or different, when the model is used.

The scikit-learn chapter "Common pitfalls and recommended practices" calls the wider problem data leakage: using information at build time that will not be there at prediction time, which gives overly optimistic scores and worse results in production.

The test Lena applies is one question per feature: at the moment of scoring, could this value exist? For each feature she writes the timestamp it is computed from and compares it with the listing's publish time. Any feature built from events after publish is out, or it is rebuilt to count only what came before.

The assistant did not invent this mistake. The warehouse table had a column that predicted the label, and the code used it. Spotting that takes knowing when each event happens in the business, which is Lena's job.

Término clave

Target leakage

A feature only known after the outcome. For each feature, ask whether the value could exist at the moment of scoring.

Estás leyendo como invitado.Guarda tu avance

Is each feature computed the same way in training and serving?

The second problem hides in a feature that is honest about time. The feature seller_avg_price_30d is the seller's average asking price, a useful hint for counterfeits priced far below the usual resale price.

For training, the assistant wrote it in the warehouse's SQL: the mean over the past 30 calendar days. For serving, it wrote a Python function in the scoring service: the mean over the seller's last 30 listings. Both pass their unit tests. For a seller who lists five items a month, the two numbers can differ a lot.

Google's "Rules of Machine Learning" names this training-serving skew: a gap between how a model performs in training and in serving, from data handled differently in the two pipelines, data that changes between them or a feedback loop. Its Rule #37, "Measure Training/Serving Skew", asks teams to monitor it, and the guide advises reusing code between training and serving rather than writing the logic twice in two languages.

Lena's fix follows that advice. The feature is defined once, in one place, and both the training job and the scoring service read it from there. For every feature, her review asks where it is computed for training, where for serving, and whether that is the same code.

She can also test it. She takes a day of listings, computes each feature both ways and compares the two columns. Any feature whose values differ on more than a handful of rows goes back for a second look.

Término clave

Training-serving skew

The same feature computed two ways. Define it once and have training and serving read the same code, then compare both on the same rows.

Which rows did the split and the join quietly change?

Two more problems sit where rows move.

The split first. The assistant used a shuffled random split over listings from January 2025 to August 2026. That is a sensible default for data with no time order. Here it means the model trains on spring 2026 listings and is tested on autumn 2025 ones. Scammers change their tricks month to month, so a model that has seen the future does better on the past than it can on tomorrow's listings. In production the model scores listings newer than anything it trained on, so the test has to look like that: train on earlier months, test on later ones.

Then the join. To add seller features, the code does an inner join from listings to the seller_profile table. That table is written by a nightly job. A seller who signs up and lists on the same day has no profile row yet, so the inner join drops their listing with no error and no warning. Lena counts rows before and after: the join removes 6% of training rows. Those rows hold 19% of the risky listings. New sellers are where many scams start.

Rows that a join or filter removes from the training data with no error are a silent row drop. The model does not see the cases those rows held, and its test score does not count them either. The fix is a left join with a flag for "no profile yet". A row count is printed after every join and filter, split by the slices the team cares about.

Each mistake on its own raises the score or hides a weak spot. Together they explain most of the eighteen points.

Four mistakes that raise no error, and the fix for each
The AI-written retrain leaked a feature known only after the outcome, computed a feature two ways, split at random over time and dropped 6% of rows in a join; each has a fix.
Target leakage
What the code did
Counts buyer reports over the listing's whole life
The fix
Out, or rebuilt to count only what came before publish
Training-serving skew
What the code did
Past 30 calendar days in SQL, last 30 listings in Python
The fix
Defined once; training and scoring read it from there
Shuffled random split
What the code did
Trains on spring 2026, tests on autumn 2025
The fix
Train on earlier months, test on later ones
Silent row drop
What the code did
Inner join drops 6% of rows, holding 19% of risky listings
The fix
Left join with a flag for no profile yet

Término clave

Silent row drop

A join or filter that removes rows with no error. Print row counts after each one, split by the slices that matter.

What do you ask the assistant for, and what do you read yourself?

On Friday, October 9, with the four problems fixed, the retrain scores 71%: one point above the model in production. One point does not justify a release of its own. The fixed seller features go to the second ML engineer, whose next candidate builds on them, and nothing ships yet.

Lena does not stop using the assistant. A 2015 paper by Google engineers, "Hidden Technical Debt in Machine Learning Systems" (NIPS 2015), draws the ML code as a small box among much larger ones: configuration, data collection, feature extraction, data checks, serving and monitoring. Those larger boxes are what the assistant now writes fastest, and where these four mistakes live.

So she splits the work. She asks the assistant for the parts it does well and that make her review faster:

  1. A table of every feature with its source column and the timestamp it is computed from.
  2. A row count after every join and filter, split by new and returning sellers.
  3. A test that computes each feature in the training and serving paths on the same rows and compares them.
  4. The split code written to train on earlier months and test on later ones.

She reads four things herself, line by line: each feature's definition, each join, the split, and how the label is built. Those are where the assistant would need to know how the business runs.

The assistant is the company-approved one. Under the privacy rule it sees table schemas and synthetic sample rows only. Real seller and buyer records stay out of it. If a change needs real data to test, it runs inside the team's own environment.

Your own last AI-written pipeline change is the place to try it: read its features, joins and split against those four questions.

With the four mistakes fixed, 88% became 71%: one point above production
The production model scores 70% recall at the 2% flag rate, the AI-written retrain 88%, and the retrain with the four problems fixed 71%.
recall at 2% flag rate
  • Model in production70%
  • Retrain as the assistant wrote it88%
  • Retrain with the four problems fixed71%Not enough for a release of its own

This is general information about building and running machine learning models, not legal, privacy or security advice. Your company's policies, its privacy lead and its legal counsel come first.

Ideas clave

  • Target leakage: A feature only known after the outcome. For each feature, ask whether the value could exist at the moment of scoring.
  • Training-serving skew: The same feature computed two ways. Define it once and have training and serving read the same code, then compare both on the same rows.
  • Silent row drop: A join or filter that removes rows with no error. Print row counts after each one, split by the slices that matter.

Sigue adelante

Continúa el curso

Una cuenta gratuita guarda tu avance. Luego sigue gratis 14 días, sin tarjeta, o mira los planes de pago.

Continuar el cursoVer el curso completo