MedData Escrow: paying for research data only once it holds up
Amol and I built an escrow marketplace for medical research data for the PayPal AI Hackathon. PayPal holds the money until the delivered data matches what the vendor promised.
Contents · 10 sections

This fall my research stalled on data, and it made me wonder what happens when you pay for data that turns out to be wrong.
My ALS speech project in the Wang Lab needed recordings of slurred speech. The public dataset had full recordings for only two patients with slurred speech, and one file we had turned out to be features only, with no audio. That's annoying when the data is free. When you're buying it, it's worse, since you pay the vendor up front and only find out later whether the data is what they promised.
Escrow already solves this for physical goods, where a third party holds the money until the package shows up. So for the PayPal AI Hackathon, my partner Amol and I built the same thing for research data, with AI doing the shopping. The rule we built everything around is simple: the money moves last.
the short version#
- What it is: a marketplace where PayPal holds the buyer's money until the delivered dataset matches what the vendor promised.
- The key change: we started with only a sample check, then added a delivery audit, since a perfect sample can hide a bad delivery.
- The numbers: honest data got its money held in 0 of 200 runs, and a scripted hostile model was blocked on 26 of 26 attacks.
- The agent: an AI agent can shop with a budget, but every limit lives in code, not in the prompt.
- Honest limits: PayPal capture runs in mock mode, and all patient data is synthetic.
the demo#
Here's the 3 minute walkthrough. I play the researcher and Amol plays the vendor.
Figure 1. The MedData Escrow demo on YouTube.
Watch it on YouTube, or try the live site yourself. The guided demo plays the whole story through the real APIs with no account.
how does a purchase work?#
- Describe the study. A researcher writes what they need in plain English, and the app ranks every dataset in the catalog against it.
- Check a free sample. Before any money moves, a sample gets checked for quality and privacy.
- PayPal holds the money. Buying authorizes the payment instead of charging it, the same way a hotel puts a hold on your card. The vendor can see the money is real, but they don't have it yet.
- The vendor delivers, and we audit it. The delivered data gets checked against what the listing promised: how many patients, how complete each column is, and whether anything was recorded after the outcome it's supposed to predict.
- Release or hold. If it holds up, PayPal captures the payment and the vendor is paid out, minus a 10% fee. If it doesn't, the money stays held and a person decides. Software never settles a dispute on its own.
After buying, the researcher can ask questions in plain English, like "count of patients by sex". They get totals and averages back, never a single patient's record. Raw data never leaves the vendor.
what if the sample looks perfect?#
We started with only the sample check. Then we asked what happens when the sample looks perfect and the delivery doesn't. With only a sample check, that vendor gets paid. That was the moment the project changed, and we built the delivery audit.
Here's a delivery failing it. The listing promised breathing test results (baseline FVC) for 95% of patients, and the delivered file has them for 28.3%. It also has a column recorded after the index date, which leaks the outcome.
Take for example a practice test that comes with the answer key stapled to the back. Your score looks great, but it means nothing. That one column lifts a model's AUC from 0.68 to 0.81.
Figure 2. The delivery audit catches two broken claims, refuses the release with a 409, and keeps $54 held.
So the order goes to disputed, a release attempt gets refused, and the $54 stays held.
a result that disappears#
The survival chart is my favorite part, because it's the same trap I wrote about in my Wang Lab post. On the flagged dataset, the two arms look very different (log-rank p below 0.001). Hold age band fixed and the gap is gone (p = 0.886). The arms just had different age mixes.
Figure 3. Survival curves for two arms on synthetic data. Raw p is below 0.001, and the age-stratified p is 0.886.
The data here is synthetic, but this is exactly the kind of mistake that ends up in a paper.
can an agent spend money safely?#
A researcher can also give the whole job to an AI agent with a budget. It searches, checks samples, skips anything that fails, and opens an escrow order. In the demo, with $60:
- First pick: a COPD dataset. It fails the sample check on duplicate rows, so the agent moves on.
- Second pick: a hypertension registry for $39. It passes, and the agent opens an escrow order.
- Skipped: a $240 dataset, since it's over budget.
Figure 4. The procurement agent's steps: search, inspect, sample check, open an escrow order.
The important part is where the limits live. Early on, our own evals caught the agent buying a COPD dataset for an Alzheimer's study. So every guardrail moved out of the prompt and into code. It can't go over budget or a signed spending mandate, skip the sample check, or release any money. A prompt can't talk it past any of that.
The thing I keep relearning. If a rule matters, it can't live in the prompt. A prompt is a suggestion, and code is a wall.
the numbers#
| What we measured | Result |
|---|---|
| Honest data that got its money held | 0 of 200 runs |
| Scripted hostile model, attacks blocked | 26 of 26 |
| Dataset ranking (MRR on held-out studies) | 0.846, up from 0.664 with word overlap |
| False alarms from our imbalance check | 97% before the fix, about 2% after |
| Tests | 1,000+ |
The 97% row is my favorite. Our evals caught one of our own checks flagging almost every clean small dataset, since chance alone makes small groups look uneven. CI now fails if any of these numbers moves without us committing the change that moved it. The full tables are in docs/evals.md.
the bugs that changed the design#
A few bugs changed the design more than any plan did, in the order we hit them:
- Agent spending lived in memory, so a restart reset what it had spent. Now it's reserved in the database before PayPal is ever called, so two agents can't overspend at once.
- A hidden small group could be recovered by subtracting the other groups from the total. Now the next smallest group is hidden too.
- Our first live deploy rejected every purchase, because Render's proxy made our own site look like a different one. We only caught it by using the real site.
Honest caveat. PayPal runs in mock mode for the demo so it never waits on a login. We verified our sandbox credentials and created real sandbox orders, but approval, capture and payout are tested in mock mode only. Claude falls back to rule-based code because Bedrock access isn't on for our account yet. All patient data is synthetic, and the audit has only seen data from our own generator, not real messy data.
what i learned#
- Escrow: for data, the delivery is what matters, not the sample.
- Leakage: one column recorded after the outcome can make a weak model look strong.
- Agents: limits belong in code, where the model can't argue with them.
- Evals: our own evals caught our own bugs more than once, so they earned their place in CI.
what's next#
The audit has only seen data from our own generator. The next step is real, messy data, and running PayPal approval, capture and payout outside of mock mode.
The code is public at github.com/hammy229/meddata-escrow, and the live demo runs without an account.
Thus an AI agent that spends money needs the same controls as a human buyer: a budget, a look before you buy, and a record of what it did. Those controls have to live where the model can't talk its way around them. The money moves last. If you have any questions, feel free to reach out. Thanks for reading!