Can Artificial Intelligence Reliably Spot Data Leakage in Predictive Modeling Pipelines

Every data scientist is intimately familiar with a specific, uneasy sensation: a machine learning model is trained, evaluated, and returns a seemingly miraculous 99% accuracy rate. Instead of celebratory cheers, however, a wave of professional skepticism immediately takes hold. Nine times out of ten, the culprit behind these inflated metrics is data leakage—the inadvertent inclusion of information in the training dataset that would realistically remain inaccessible at the actual moment of prediction.

This pervasive issue compromises countless analytical systems across industries, leading to costly deployments of unreliable software. To investigate how artificial intelligence handles this systemic vulnerability, data strategist Nate Rosidi recently conducted an empirical experiment. By deliberately introducing classic data leakage patterns into four distinct real-world data projects, the research sought to answer two critical questions: How dramatically does data leakage distort predictive accuracy on practical datasets compared to theoretical toy examples, and can large language models successfully identify these flaws prior to model execution simply by analyzing plain-text pipeline descriptions?
Experimental Design and Methodology
To rigorously test AI capabilities without introducing external bias, the experiment utilized four distinct real-world data science projects sourced from StrataScratch. Each project was intentionally subverted with a well-documented leakage pattern: features that mechanically define the target label, features contaminated with future temporal information, cross-validation splits that blatantly ignore underlying relational structures, and improper ordering of data preprocessing steps.

The evaluation process leveraged a family of Anthropic Claude models spanning different speed and capability tiers: Claude Haiku 4.5, Claude Sonnet 5, Claude Opus 5, and Claude Fable 5.1. To maintain scientific integrity, each model was evaluated in a pristine, isolated session with zero cross-session memory. The models were provided exclusively with closed-book descriptions of the respective pipelines, features, or code snippets, completely devoid of execution capabilities or advance warnings regarding the presence of hidden leaks.
Case Studies in Contamination
1. The Direct Target Leak
The first test case examined stock price direction prediction utilizing datasets from Amazon (AMZN). The core objective was to determine whether a given day’s closing price would exceed its opening price. Under standard, flawed pipeline conditions, feeding the model the exact same day’s closing and adjusted closing values—alongside open, high, low, and volume metrics—yielded a validation accuracy of 97.0% and an Area Under the Curve (AUC) of 0.999.

However, restricting the feature set strictly to prior-day market data immediately plummeted the accuracy to a realistic 51.6% with an AUC of 0.476, effectively mirroring a random coin flip. When presented with the pipeline architecture, all four Claude models instantaneously flagged the vulnerability. Haiku labeled the setup "circular," Sonnet noted the model’s ability to "reconstruct the label with a single comparison," and Opus accurately anticipated that a properly calibrated, honest model should naturally hover in the low 50s for accuracy.
2. Temporal Violation and Aggregation Leaks
The second evaluation focused on delivery duration predictions using historical operational data from DoorDash. The objective was to predict total delivery time in seconds. Researchers intentionally engineered a store-average feature by grouping the entire dataset—combining both training and testing rows—prior to executing an 80/20 train-test split. Furthermore, the timestamped dataset was randomly shuffled, allowing training rows to chronologically succeed test rows.

This dual-leakage architecture produced an artificially optimistic Root Mean Squared Error (RMSE) of 862.7 seconds, compared to 949.9 seconds for the methodologically sound, chronological baseline. While every tested AI model caught the store-average aggregation leak, only the three more advanced models—Sonnet, Opus, and Fable—unprompted, identified the catastrophic error of randomly shuffling timestamped data. Fable provided the most succinct diagnostic: "the training set can contain orders that occurred after some of the test-set orders."
3. Entity-Level Overlap in Relational Schemas
Addressing relational data architectures, the third case study analyzed fraud detection pipelines from Revolut. The predictive task required identifying fraudulent users based on profile attributes and transaction histories. Because the underlying schema followed a one-to-many relationship—where a single user profile generated multiple transaction rows sharing an identical fraud label—performing a naive, row-level random split resulted in 1,950 out of 2,246 users having transactions distributed across both training and testing partitions.

A model trained under these leaky conditions achieved an AUC of 0.960. When properly partitioned by distinct user IDs to prevent data contamination, the honest AUC dropped to 0.898. All four AI models successfully deduced the core structural flaw, recognizing that row-level splits allowed the algorithm to memorize user characteristics rather than generalize fraud detection patterns. Opus offered the most comprehensive critique, correctly observing that the true sample size was dictated by the total count of unique users rather than transaction row counts.
4. Methodological Sequencing Flaws in Data Preprocessing
The final case study examined loan risk assessment datasets from Chime, characterized by an inherent class imbalance where roughly 10% of loans were classified as defaults. To rectify this imbalance, the flawed pipeline implemented oversampling techniques by duplicating minority-class rows prior to executing the train-test split.

Evaluating this improperly sequenced pipeline yielded a deceptively high AUC of 0.986. Conversely, reordering the pipeline to execute the train-test split before applying oversampling solely to the training partition yielded an honest, albeit modest, AUC of 0.637. When provided solely with the code snippet—free of any performance metrics—all four AI models successfully flagged the methodological error. Opus expanded the analysis by questioning the foundational necessity of oversampling altogether, suggesting alternative approaches such as class-weight adjustments or reviewing recall metrics against fixed operational budgets.
Implications and Industry Impact
The findings from this empirical evaluation carry profound implications for the broader software engineering and data science communities. As organizations increasingly integrate generative artificial intelligence into their development workflows, automated code review assistants are demonstrating a remarkable capacity to catch subtle, catastrophic data science anti-patterns before computational resources are wasted on training flawed architectures.

Nevertheless, the experiment highlighted crucial performance variations across model tiers. While smaller, faster models like Haiku are entirely adequate for catching glaring, single-point vulnerabilities, complex pipelines featuring overlapping methodological errors require the deeper reasoning capabilities exhibited by advanced models like Sonnet, Fable, and Opus.
Ultimately, leveraging large language models as automated code and pipeline reviewers offers a rapid, highly cost-effective safeguard against data leakage. However, human oversight remains indispensable; the efficacy of AI-driven code auditing depends heavily on providing comprehensive pipeline context and selecting models equipped to parse intricate, multi-layered logical flaws.







