Inspiration

In a college project, my model's score looked great, and I still lost marks because of data leakage I had not noticed. The score gave me no warning. That is what makes leakage dangerous: the mistake looks like success.

AI coding agents are now asked to "get the score up", and a leak is the fastest way up. This is not rare: Kapoor and Narayanan (Patterns, 2023) found leakage errors in 294 published papers across 17 scientific fields.

What it does

Data leakage means a model saw the exam answers while it studied. It scores brilliantly in testing and then fails on real data. Nothing in the score warns you, because a leak makes the score go up.

Hexperiment is a Kiro power plus a Python kit. An AI agent's training result counts only when the kit's verdict says APPROVED.

  • The canary test. The kit runs the training script twice: once normally, and once with only the test rows scrambled. If anything training produced changes, training depended on the test rows. That is a leak, and the run is REJECTED. A third, unscrambled run rules out plain randomness. Because the canary watches behavior instead of reading code, it catches leaks hidden inside helper functions and libraries.
  • Five data checks, each named after a ghost: duplicate rows shared by train and test (The Doppelganger), a single column that gives the answer away (The Possession), training on the future (The Prophet), test rows reaching training (The Peeking Spirit), and results that change from run to run (The Shapeshifter).
  • Inside Kiro, the steering file asks the agent to load and split data through the kit. A save hook gives a fast check on every save. An MCP server exposes the audit as tools. The exorcise workflow runs a ghost-hunter agent with no shell access: it audits, reads the findings, fixes the code and audits again, until the verdict is APPROVED or five rounds have passed.
  • Two demo apps on real public data, each with planted leaks, both repaired by the workflow:
    • Hotel cancellations: the first run was REJECTED at ROC AUC 1.0000, a perfect score. reservation_status gave the answer away, and a per-country cancellation rate had been built from every row's label, test rows included. The ghost hunter fixed both in one round: APPROVED at 0.9090 (the reference fix in the repository scores 0.9096).
    • Flight delays: the first run was REJECTED at 0.7971. A random split on time-ordered flights let the model learn from the future. One round later it was APPROVED at an honest 0.6193. The score went down, and that is the point.
  • A public gallery shows both cases with the code diff, the findings and the model cards: https://jegadeesh17.github.io/hexperiment/

How I built it

Spec-first in Kiro. Five specs (core, Kiro layer, apps, gallery, benchmark) hold 45 requirements in EARS form and 98 tasks. Kiro built 91 of them; the other 7 were owner checks done live in Kiro and on GitHub.

Three custom build agents, each limited to its own files: a spec writer, a builder, and a read-only reviewer. I verified every task outside Kiro (full test suite and linter) before committing it. The suite has about 3,600 tests, including Hypothesis property-based tests.

Stack: Python 3.13, pandas, NumPy, scikit-learn, the MCP Python SDK, Kiro CLI and IDE, and GitHub Pages for the gallery.

How Kiro was used

  • Specs caught a bug before any code existed. The spec writer refused a requirement that was statistically wrong: shuffling test values keeps a column's mean, so a leak through a mean imputer could never be seen. The design switched to a "tilted resample". In the benchmark, the canary later caught all six scaler and imputer leaks.
  • Kiro is the product's engine, not just the tool that built it. Steering, a hook, an MCP server, a custom agent, a workflow and a power each have one job in the leak-checking loop.
  • Live probes checked Kiro where the docs were silent, and the design changed when they said so. Hook output did not reach the agent, so the nudge became a Stop hook. Shell rules were not a real boundary inside a headless workflow, so I removed the ghost hunter's shell and routed its audits through the MCP run_audit tool. Its file writes now pass a preToolUse guard: in a live test, 12 attempts to write outside the app's Python files were refused 12 times.

My favorite Kiro feature is hooks together with the workflow, because the loop runs itself. Once the exorcise workflow starts, the ghost hunter audits, reads the findings, fixes the code and audits again, until the verdict says APPROVED. I am not in the middle, copying error messages back and forth. Both demo repairs ran this way, and each needed only one round.

Working spec-first changed what my job is. Before Kiro, I prompted coding agents directly, then read their code and hoped it matched what I meant. Here, the specs turned the requirements into 98 ordered tasks, and Kiro wrote the code and the tests for 91 of them. My work moved to deciding and checking: I made the design calls, such as removing the ghost hunter's shell, I ran the full test suite myself before every commit, and I did the 7 owner checks by hand.

Challenges I ran into

  • Making the check trustworthy without false alarms. Each review round found a way for a script to slip past the canary: reading the CSV directly, copying it with shutil.copy2, or taking only some columns from load(). Kiro's builder closed them one at a time, each with tests: a per-column check, and an audit-hook watch for opens, copies, links and renames of the data file. The final review then found that the per-column check also blocked honest derived features, such as an hour taken from a timestamp column. The fix was to compare only raw data-file columns.
  • Kiro behavior that differed from the docs (hook output, shell rules), described above.

Accomplishments that I'm proud of

  • A leak benchmark built on the Kapoor and Narayanan taxonomy: 13 leak mechanisms, 3 models, 78 scripts on synthetic data. 30 of the 39 leaky scripts were rejected, exactly the 30 predicted before the run, with no false alarms on the 39 clean twins. One example of why the canary matters: a scaler fitted on all rows moved ROC AUC by less than 0.01, too little for any score comparison to notice, yet the canary caught all six such scripts.
  • Being honest about what it proves. The data is synthetic, and this project wrote both the checks and the test cases. So the benchmark shows the checks see the leaks they were built for. It does not show how often they find leaks in real projects. What the canary cannot see is listed in the README's "Known limits".

What I learned

I learned that an agent's work is only as trustworthy as the evidence behind it. The moment I trusted the agents more was when Kiro's read-only reviewer found a loophole in the leak check itself: a script could send its training-set predictions only in the normal run, so the check passed without comparing anything. The builder closed it, then proved the fix by breaking the code on purpose and watching the tests fail. I stopped writing the code, writing the tests, breaking down the tasks and reviewing every line myself. I never stopped running the tests myself.

What's next for Hexperiment

  • A group split, so all rows of one customer or patient stay on the same side. Today this is a known miss.
  • A subsampled canary for large models, where training twice is expensive.
  • Publishing the power so other Kiro users can install it.

Built With

Share this project:

Updates

Submission history