From Notebook to Production: An Extraction Model You Could Trust
The client is anonymised, and these figures are not independently audited.
At a glance#
- Wrapping the notebook code in an API as it was
- A rules-based extractor
The problem
A mid-market healthtech had built a model to pull structured fields out of clinical intake documents. The fields were patient demographics, referring provider, diagnosis codes and insurance details. The source was whatever a referring office sent: PDFs, faxes and scanned referral forms. In a data scientist’s notebook, on a clean sample of well-formatted documents, the model looked ready to ship. Accuracy on that sample was high. Clinical operations was already planning to retire the manual re-keying process the model would replace.
Real intake traffic looked different from the notebook sample. Faxes came in skewed and at low resolution. Referral forms varied by sending office, and some used field labels the model had never seen. On that long tail, the model did not fail loudly. It filled in a plausible value where the real one was unclear or missing. A wrong diagnosis code or a swapped date of birth throws no error. It enters the clinical record and looks as confident as a correct value. Nobody had measured how often this happened, because there was no eval harness. There was only the one notebook sample that everyone had already seen. The documents also carried protected health information (PHI). The team could not send them to an external extraction API to buy time. Whatever they built had to keep PHI inside their own infrastructure.
What we ruled out, and what we built
The fastest option was to wrap the existing notebook code in an API and ship it as it was. We ruled it out. There was no eval harness, so nobody measured or managed the hallucinationA hallucination is a confident, fluent output that is factually wrong or unsupported. rate on real traffic. With no regression safety net, a later model or prompt change could make the long tail worse. Nobody would know until a clinician found a wrong value.
The other option was a rules-based extractor. It is deterministic and easy to audit, which appeals to a compliance-minded team. We ruled that out too. The fax-format long tail was too varied for hand-written rules. Each new referring office’s layout would need another round of rule-writing, and the rules would never catch up.
We built a production extraction pipeline with three parts.
First, an eval harness built from a labeled sample of real intake documents. The sample came from actual traffic: faxes, scans and edge-case layouts. Clinical operations labeled each document by hand with the correct field values. This sample became the yardstick for every later change. A prompt tweak, a model swap or a preprocessing fix was measured against the same held-out set before it touched production.
Second, confidence gating on every extracted field. When the model’s confidence on a field fell below a calibrated threshold, that field went to a human reviewer. The whole document did not.
Third, we kept every document and every model call inside the healthtech’s own VPC. No PHI left their infrastructure to reach an external API. The extraction model ran on infrastructure they controlled. This mattered to their security team as much as the accuracy numbers did.
The eval harness ran in CI on every change, the same way a test suite gates a code change. The question “is this update better or worse” used to get an eyeball check after deployment. Now it got a number that the team saw before merging.
The outcome
The field-level hallucination rate on the held-out real-document sample dropped from 12% to 3%. Most of the gain came from seeing where the model was wrong and gating on that. The underlying model mattered less. The confidence threshold caught the fields the model was unsure about. The eval harness caught the changes that would have made things worse, before they shipped. The system went from notebook to production traffic in eight weeks. Only low-confidence fields went to a human, so the manual review queue shrank 60% against the fully manual re-keying process it replaced. A human still reviewed the cases where the model’s own confidence said a review was needed. Clinical operations put the saved re-keying work at roughly 1,200 engineer-hours a year, which they freed up for other intake work.
For the CFO, the math is simple. Set the engineer-hours saved against the manual re-keying baseline, then set that against the eight-week build cost. Payback falls inside a single quarter. The number comes from a documented, repeatable eval process. It does not rest on a black-box accuracy claim. The finance team could walk through it with clinical operations.
For IT and security, PHI staying inside the VPC mattered as much as the accuracy gain. The pipeline fit into the existing EHR intake flow. It needed no new external data-sharing agreement and no new HIPAA risk assessment, because no new external party touched the data.
For operations, confidence gating plus an eval suiteAn eval suite is a versioned set of test cases that measures whether outputs are good. in CI means a failure degrades in steps and stays visible. The eval harness catches a bad model update before it reaches production. A human reviewer catches the residual 3% of uncertain extractions before they enter the clinical record. Nobody has to find a wrong code downstream.
The Head of Clinical Operations said the win was a model that the team could finally measure. For the first time, they could see when the model was wrong, at the field level, on real documents. That turned a notebook demo into something the clinical intake process could depend on.
“The difference wasn't a better model. It was finally being able to measure when the model was wrong.”
Head of Clinical Operations