Skip to main content

Data pipeline testing

Why This Matters

The data a model sees passes through a pipeline: ingestion, cleaning, joining, feature calculation. Usually two of them: one that built the training data, and one that feeds the model in production. If they disagree by a single unit, a single join or a single default value, the model receives inputs it was never trained on, and fails without an error message. Data pipelines are software, and they deserve the same testing as any other software, plus some tests specific to data.

What you will learn

  • The layered approach to testing a data pipeline, from design review to production
  • The difference between testing a training pipeline and an operational pipeline
  • Typical pipeline defects, and how to find them

Syllabus: AI-5.1.3.

The layers

LayerWhat is tested
Design reviewDuring design: does the pipeline do what the model needs? Are training and production pipelines designed to produce the same features?
Component testingIngestion, transformation and sensor interfaces. Code review and static analysis; tests of the hardware where sensors are involved; validation rules (constraints, lesson 38), error handling (what happens with a corrupt record?), and checks for vulnerabilities: malware in uploaded files, poisoned data.
Component integration testingData flows correctly between the internal interfaces, and each component interprets it correctly: units, formats, encodings, time zones.
System testingSmoke testing: does data flow end to end at all? Functional testing of transformations and routing. Non-functional testing: load, scalability, security. Fault injection: feed it corrupted inputs on purpose. Back-to-back testing of the operational pipeline against the training pipeline: same raw input, same features out?
System integration testingThe connections to data sources, storage, monitoring tools, and downstream consumers such as the model.
Production testingBack-to-back testing, A/B testing of a new pipeline version against the current one, and real-time monitoring.
Configuration management reviewsThe right code, configuration and dataset versions are used in training, testing and production. “Which version of the data was this model trained on?” must have an answer.

Purpose-driven testing

Pipelines have different purposes, and the testing follows the purpose:

  • Training pipelines run occasionally, on large historical datasets. The focus is data integrity: nothing lost, nothing duplicated, nothing leaked between training and test data (lesson 16), the same result when rerun.
  • Operational pipelines run continuously and feed live predictions. The focus is reliability, performance and maintainability: they must keep working under load, handle bad input gracefully, and be easy to change without breaking.

Typical defects

Three classics, each found at a different layer:

A schema change upstream. The CRM team renames income to annual_income. The pipeline’s join still runs, but the column is now empty, and the default for missing values (the median) is filled in for everyone. Every applicant now has the same income. No error, no crash. Found by: a count constraint on non-missing values (lesson 38) and monitoring the distribution of each feature in production.

A silent drop. A join between applications and customers uses an inner join; applicants without an existing customer record disappear. The training data then contains only existing customers, and the model has never seen a new one. Found by: row counts at each step (in = out + rejected), and comparing the distribution before and after the join.

Training-serving skew. In training, “number of payments in the last 30 days” was calculated in a batch job from the full history; in production a streaming job counts the last 30 days from the start of the stream, which is far fewer after a restart. Found by: back-to-back testing: run the same raw records through both pipelines and compare the features.

Exercise

Review this pipeline step, which turns raw loan applications into model features. Find at least three defects or risks, and say which test would find each.

def build_features(applications, customers):
    df = applications.merge(customers, on="customer_id", how="inner")
    df["income"] = df["income"].fillna(0)
    df["age"] = (pd.Timestamp.now() - pd.to_datetime(df["birth_date"])).dt.days // 365
    df["city"] = df["city"].str.lower()
    df = df.drop_duplicates()
    return df[["age", "income", "credit_score", "city"]]
Show suggested answer
  1. Inner join drops new applicants without a customer record. Test: row counts in and out; a component test with an application that has no customer.
  2. Missing income becomes 0, which the model reads as “no income”: a strong reason to reject. Test: a constraint on the share of incomes equal to 0; a component test with a missing income; a design review decision on how to impute.
  3. Age depends on the moment the pipeline runs (Timestamp.now()): rerunning the training pipeline next year changes every age, so training is not reproducible, and training and production use different reference dates. Test: rerun the pipeline and compare the output (data integrity); back-to-back test against production.
  4. City is lower-cased here, while the model may have been trained on title case (“New York”), so one-hot encoding in production produces a column the model has never seen. Test: back-to-back testing of training and operational features; component integration test of the interpretation of city.
  5. drop_duplicates() on all columns keeps duplicates that differ only in an ID or timestamp. Test: a duplicate constraint on the business key.
  6. No validation or error handling for an invalid birth_date: to_datetime raises an error and the whole batch fails. Test: fault injection with a corrupted record.

Exam-style questions

Quiz

1. A team runs the same raw records through the training pipeline and the operational pipeline and compares the resulting features. What is this?

  • A. A/B testing
  • B. Back-to-back testing
  • C. Smoke testing
  • D. Label correctness testing
Show answer
B.
Quiz

2. What is the main focus when testing an operational data pipeline, compared with a training pipeline?

  • A. Data integrity only
  • B. Reliability, performance and maintainability
  • C. Label correctness
  • D. Model accuracy
Show answer
B. Training pipelines focus on data integrity.
Quiz

3. Which activity confirms that the correct code, configuration and dataset versions are used across training, testing and production?

  • A. Fault injection
  • B. Configuration management review
  • C. Load testing
  • D. Disparate impact analysis
Show answer
B.