Pipeline Integrity Experimental Design Lens
Philosophical Mode: Integrity
Primary Question: "Could data handling create optimistic bias?"
Focus: Data Splits, Leakage Points, Preprocessing Order, Label Contamination, Pipeline Invariants
When to Use
- ML pipeline with train/test splits
- Preprocessing before or after splitting is ambiguous
- Feature engineering touching labels
- User invokes
/exp-lens-pipeline-integrity or /make-experiment-diag pipeline
Critical Constraints
NEVER:
- Modify any source code files
- Do not litter the codebase with useless comments, TODO markers, or explanatory annotations — the skill output and diagram speak for themselves
ALWAYS:
- Classify every pipeline stage as pre-split or post-split
- Trace whether transforms are fitted on full data or train-only
- Flag all label-touching feature engineering steps
- Document pipeline invariants that guard against leakage
- BEFORE creating any diagram, LOAD the
/mermaid skill using the Skill tool - this is MANDATORY
Analysis Workflow
Step 1: Launch Parallel Exploration Subagents
Spawn Explore subagents to investigate:
Data Loading & Sources
- Find data ingestion code, raw data paths
- Look for: load, read, fetch, dataset, csv, parquet, download
Preprocessing & Transforms
- Find normalization, encoding, imputation steps
- Look for: transform, normalize, scale, encode, impute, clean, preprocess
Split Logic
- Find train/test/validation split code
- Look for: split, train_test, fold, cross_val, stratify, group
Feature Engineering
- Find feature creation, selection, extraction
- Look for: feature, extract, select, engineer, embed, vectorize
Model Training & Evaluation
- Find training loops and evaluation metrics
- Look for: fit, train, predict, evaluate, score, metric, loss
Step 2: Map the Complete Pipeline
Map the full pipeline from raw data to reported metrics. For each stage, determine:
- What information flows in?
- What information flows out?
- Could any downstream information leak upstream?
- Classify each stage as pre-split or post-split.
Step 3: Identify Leakage Risks
CRITICAL — Analyze Leakage Direction:
For every data transformation:
- Does it use information from the full dataset (leakage risk) or only from the training partition?
- Is normalization fitted on train-only or all data?
- Are features derived from labels?
Assign a severity level (High/Medium/Low) to each leakage risk based on whether it would invalidate reported metrics.
Step 4: Create the Diagram
Use flowchart with:
Direction: LR (data flows left to right)
Subgraphs:
- RAW DATA
- PREPROCESSING
- SPLIT POINT
- TRAIN PATH
- TEST PATH
- EVALUATION
Node Styling:
cli class: Data sources
handler class: Transforms
detector class: Split point and validation gates
stateNode class: Data stores
gap class: Leakage risks
output class: Metrics and results
phase class: Model training
Edge Labels: full data, train only, test only, LEAKAGE RISK
Step 5: Write Output
Write the diagram to: temp/exp-lens-pipeline-integrity/exp_diag_pipeline_integrity_{YYYY-MM-DD_HHMMSS}.md
Output Template
# Pipeline Integrity Diagram: {Experiment Name}
**Lens:** Pipeline Integrity (Integrity)
**Question:** Could data handling create optimistic bias?
**Date:** {YYYY-MM-DD}
**Scope:** {What was analyzed}
## Pipeline Stages
| Stage | Input | Output | Pre/Post Split | Leakage Risk? |
|-------|-------|--------|----------------|---------------|
| {stage} | {input} | {output} | {Pre/Post} | {Yes/No} |
## Pipeline Diagram
```mermaid
%%{init: {'flowchart': {'nodeSpacing': 50, 'rankSpacing': 60, 'curve': 'basis'}}}%%
flowchart LR
%% CLASS DEFINITIONS %%
classDef cli fill:#1a237e,stroke:#7986cb,stroke-width:2px,color:#fff;
classDef stateNode fill:#004d40,stroke:#4db6ac,stroke-width:2px,color:#fff;
classDef handler fill:#e65100,stroke:#ffb74d,stroke-width:2px,color:#fff;
classDef phase fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff;
classDef newComponent fill:#2e7d32,stroke:#81c784,stroke-width:2px,color:#fff;
classDef output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;
classDef detector fill:#b71c1c,stroke:#ef5350,stroke-width:2px,color:#fff;
classDef gap fill:#ff6f00,stroke:#ffa726,stroke-width:2px,color:#000;
classDef integration fill:#c62828,stroke:#ef9a9a,stroke-width:2px,color:#fff;
subgraph Raw ["RAW DATA"]
SRC["Raw Dataset<br/>━━━━━━━━━━<br/>Source path<br/>N samples"]
end
subgraph Preprocessing ["PREPROCESSING"]
PREP["Normalization / Encoding<br/>━━━━━━━━━━<br/>Fitted on: full/train?"]
LEAK["Leaky Transform<br/>━━━━━━━━━━<br/>Uses full dataset"]
end
subgraph SplitPoint ["SPLIT POINT"]
SPLIT["Train/Test Split<br/>━━━━━━━━━━<br/>Stratified? Ratio?"]
end
subgraph TrainPath ["TRAIN PATH"]
TRAIN_DATA["Train Set<br/>━━━━━━━━━━<br/>N_train samples"]
MODEL["Model Training<br/>━━━━━━━━━━<br/>fit()"]
end
subgraph TestPath ["TEST PATH"]
TEST_DATA["Test Set<br/>━━━━━━━━━━<br/>N_test samples"]
end
subgraph Evaluation ["EVALUATION"]
METRIC["Reported Metric<br/>━━━━━━━━━━<br/>score / loss"]
end
%% PIPELINE FLOWS %%
SRC -->|"full data"| PREP
PREP -->|"full data"| LEAK
LEAK -.->|"LEAKAGE RISK"| METRIC
PREP -->|"full data"| SPLIT
SPLIT -->|"train only"| TRAIN_DATA
SPLIT -->|"test only"| TEST_DATA
TRAIN_DATA -->|"fit"| MODEL
MODEL -->|"predict"| TEST_DATA
TEST_DATA -->|"evaluate"| METRIC
%% CLASS ASSIGNMENTS %%
class SRC cli;
class PREP handler;
class LEAK gap;
class SPLIT detector;
class TRAIN_DATA,TEST_DATA stateNode;
class MODEL phase;
class METRIC output;
Color Legend:
| Color |
Category |
Description |
| Dark Blue |
Data Source |
Raw input datasets |
| Orange |
Transform |
Preprocessing and feature engineering steps |
| Red |
Split / Gate |
Split point and validation gates |
| Teal |
Data Store |
Partitioned data stores (train/test) |
| Purple |
Training |
Model training stages |
| Dark Teal |
Output |
Reported metrics and results |
| Amber |
Leakage Risk |
Transforms using full-dataset information |
Leakage Assessment
| Risk |
Stage |
Mechanism |
Severity |
| {risk name} |
{stage} |
{how leakage occurs} |
{High/Medium/Low} |
Pipeline Invariants
---
## Pre-Diagram Checklist
Before creating the diagram, verify:
- [ ] LOADED `/mermaid` skill using the Skill tool
- [ ] Using ONLY classDef styles from the mermaid skill (no invented colors)
- [ ] Diagram will include a color legend table
---
## Related Skills
- `/make-experiment-diag` - Parent skill for lens selection
- `/mermaid` - MUST BE LOADED before creating diagram
- `/exp-lens-reproducibility-artifacts` - For artifact completeness audit
- `/exp-lens-measurement-validity` - For outcome measurement validity
1---2name: exp-lens-pipeline-integrity3description: Create Pipeline Integrity experimental design diagram showing data splits, leakage points, preprocessing order, and label contamination. Integrity lens answering "Could data handling create optimistic bias?"4---56# Pipeline Integrity Experimental Design Lens78**Philosophical Mode:** Integrity9**Primary Question:** "Could data handling create optimistic bias?"10**Focus:** Data Splits, Leakage Points, Preprocessing Order, Label Contamination, Pipeline Invariants1112## When to Use1314- ML pipeline with train/test splits15- Preprocessing before or after splitting is ambiguous16- Feature engineering touching labels17- User invokes `/exp-lens-pipeline-integrity` or `/make-experiment-diag pipeline`1819## Critical Constraints2021**NEVER:**22- Modify any source code files23- Do not litter the codebase with useless comments, TODO markers, or explanatory annotations — the skill output and diagram speak for themselves2425**ALWAYS:**26- Classify every pipeline stage as pre-split or post-split27- Trace whether transforms are fitted on full data or train-only28- Flag all label-touching feature engineering steps29- Document pipeline invariants that guard against leakage30- BEFORE creating any diagram, LOAD the `/mermaid` skill using the Skill tool - this is MANDATORY3132---3334## Analysis Workflow3536### Step 1: Launch Parallel Exploration Subagents3738Spawn Explore subagents to investigate:3940**Data Loading & Sources**41- Find data ingestion code, raw data paths42- Look for: load, read, fetch, dataset, csv, parquet, download4344**Preprocessing & Transforms**45- Find normalization, encoding, imputation steps46- Look for: transform, normalize, scale, encode, impute, clean, preprocess4748**Split Logic**49- Find train/test/validation split code50- Look for: split, train_test, fold, cross_val, stratify, group5152**Feature Engineering**53- Find feature creation, selection, extraction54- Look for: feature, extract, select, engineer, embed, vectorize5556**Model Training & Evaluation**57- Find training loops and evaluation metrics58- Look for: fit, train, predict, evaluate, score, metric, loss5960### Step 2: Map the Complete Pipeline6162Map the full pipeline from raw data to reported metrics. For each stage, determine:63- What information flows in?64- What information flows out?65- Could any downstream information leak upstream?66- Classify each stage as pre-split or post-split.6768### Step 3: Identify Leakage Risks6970**CRITICAL — Analyze Leakage Direction:**71For every data transformation:72- Does it use information from the full dataset (leakage risk) or only from the training partition?73- Is normalization fitted on train-only or all data?74- Are features derived from labels?7576Assign a severity level (High/Medium/Low) to each leakage risk based on whether it would invalidate reported metrics.7778### Step 4: Create the Diagram7980Use flowchart with:8182**Direction:** `LR` (data flows left to right)8384**Subgraphs:**85- RAW DATA86- PREPROCESSING87- SPLIT POINT88- TRAIN PATH89- TEST PATH90- EVALUATION9192**Node Styling:**93- `cli` class: Data sources94- `handler` class: Transforms95- `detector` class: Split point and validation gates96- `stateNode` class: Data stores97- `gap` class: Leakage risks98- `output` class: Metrics and results99- `phase` class: Model training100101**Edge Labels:** full data, train only, test only, LEAKAGE RISK102103### Step 5: Write Output104105Write the diagram to: `temp/exp-lens-pipeline-integrity/exp_diag_pipeline_integrity_{YYYY-MM-DD_HHMMSS}.md`106107---108109## Output Template110111```markdown112# Pipeline Integrity Diagram: {Experiment Name}113114**Lens:** Pipeline Integrity (Integrity)115**Question:** Could data handling create optimistic bias?116**Date:** {YYYY-MM-DD}117**Scope:** {What was analyzed}118119## Pipeline Stages120121| Stage | Input | Output | Pre/Post Split | Leakage Risk? |122|-------|-------|--------|----------------|---------------|123| {stage} | {input} | {output} | {Pre/Post} | {Yes/No} |124125## Pipeline Diagram126127```mermaid128%%{init: {'flowchart': {'nodeSpacing': 50, 'rankSpacing': 60, 'curve': 'basis'}}}%%129flowchart LR130 %% CLASS DEFINITIONS %%131 classDef cli fill:#1a237e,stroke:#7986cb,stroke-width:2px,color:#fff;132 classDef stateNode fill:#004d40,stroke:#4db6ac,stroke-width:2px,color:#fff;133 classDef handler fill:#e65100,stroke:#ffb74d,stroke-width:2px,color:#fff;134 classDef phase fill:#6a1b9a,stroke:#ba68c8,stroke-width:2px,color:#fff;135 classDef newComponent fill:#2e7d32,stroke:#81c784,stroke-width:2px,color:#fff;136 classDef output fill:#00695c,stroke:#4db6ac,stroke-width:2px,color:#fff;137 classDef detector fill:#b71c1c,stroke:#ef5350,stroke-width:2px,color:#fff;138 classDef gap fill:#ff6f00,stroke:#ffa726,stroke-width:2px,color:#000;139 classDef integration fill:#c62828,stroke:#ef9a9a,stroke-width:2px,color:#fff;140141 subgraph Raw ["RAW DATA"]142 SRC["Raw Dataset<br/>━━━━━━━━━━<br/>Source path<br/>N samples"]143 end144145 subgraph Preprocessing ["PREPROCESSING"]146 PREP["Normalization / Encoding<br/>━━━━━━━━━━<br/>Fitted on: full/train?"]147 LEAK["Leaky Transform<br/>━━━━━━━━━━<br/>Uses full dataset"]148 end149150 subgraph SplitPoint ["SPLIT POINT"]151 SPLIT["Train/Test Split<br/>━━━━━━━━━━<br/>Stratified? Ratio?"]152 end153154 subgraph TrainPath ["TRAIN PATH"]155 TRAIN_DATA["Train Set<br/>━━━━━━━━━━<br/>N_train samples"]156 MODEL["Model Training<br/>━━━━━━━━━━<br/>fit()"]157 end158159 subgraph TestPath ["TEST PATH"]160 TEST_DATA["Test Set<br/>━━━━━━━━━━<br/>N_test samples"]161 end162163 subgraph Evaluation ["EVALUATION"]164 METRIC["Reported Metric<br/>━━━━━━━━━━<br/>score / loss"]165 end166167 %% PIPELINE FLOWS %%168 SRC -->|"full data"| PREP169 PREP -->|"full data"| LEAK170 LEAK -.->|"LEAKAGE RISK"| METRIC171 PREP -->|"full data"| SPLIT172 SPLIT -->|"train only"| TRAIN_DATA173 SPLIT -->|"test only"| TEST_DATA174 TRAIN_DATA -->|"fit"| MODEL175 MODEL -->|"predict"| TEST_DATA176 TEST_DATA -->|"evaluate"| METRIC177178 %% CLASS ASSIGNMENTS %%179 class SRC cli;180 class PREP handler;181 class LEAK gap;182 class SPLIT detector;183 class TRAIN_DATA,TEST_DATA stateNode;184 class MODEL phase;185 class METRIC output;186```187188**Color Legend:**189| Color | Category | Description |190|-------|----------|-------------|191| Dark Blue | Data Source | Raw input datasets |192| Orange | Transform | Preprocessing and feature engineering steps |193| Red | Split / Gate | Split point and validation gates |194| Teal | Data Store | Partitioned data stores (train/test) |195| Purple | Training | Model training stages |196| Dark Teal | Output | Reported metrics and results |197| Amber | Leakage Risk | Transforms using full-dataset information |198199## Leakage Assessment200201| Risk | Stage | Mechanism | Severity |202|------|-------|-----------|----------|203| {risk name} | {stage} | {how leakage occurs} | {High/Medium/Low} |204205## Pipeline Invariants206207- [ ] All scalers/encoders fitted on train partition only208- [ ] Feature selection criteria computed from train partition only209- [ ] No label information used in feature construction210- [ ] Test set never seen by any fitting step211```212213---214215## Pre-Diagram Checklist216217Before creating the diagram, verify:218219- [ ] LOADED `/mermaid` skill using the Skill tool220- [ ] Using ONLY classDef styles from the mermaid skill (no invented colors)221- [ ] Diagram will include a color legend table222223---224225## Related Skills226227- `/make-experiment-diag` - Parent skill for lens selection228- `/mermaid` - MUST BE LOADED before creating diagram229- `/exp-lens-reproducibility-artifacts` - For artifact completeness audit230- `/exp-lens-measurement-validity` - For outcome measurement validity