Healthcare · Pharmacy Network

Automating document intake for 700+ pharmacies.

National pharmacy network, 700+ locations

A hybrid LLM + machine-learning system that classifies and extracts data from roughly 1.6 million faxed pharmacy forms a month at 94% accuracy, feeding clean structured data straight into order creation.

LLM + ML HybridDocument AutomationHealthcare

Challenge

What was the challenge?

More than 700 pharmacy sites received a combined ~1.6 million faxed documents every month — prescriptions, enrollment forms, clinical paperwork — in an enormous variety of layouts from thousands of senders. Staff sorted, categorized, and re-keyed them by hand before an order could even be created.

The variety was the killer. Nobody actually knew how many distinct form types flowed through the network, which made building a classifier feel like aiming at a moving target. And because these documents drive medication orders, an automation system couldn't just be fast — it had to know when it wasn't sure and hand those cases to a human.

Approach

How did we approach it?

We started with evidence, not assumptions: a full month of real volume — about 1.6 million forms — was OCR'd, embedded, and clustered to discover what actually flows through the network. The clustering surfaced 50+ distinct form categories, and that data-driven taxonomy became the backbone of the whole system.

For the pipeline itself we used a cost-tiered hybrid: cheap deterministic checks first, AI only where it earns its keep. Keyword rules classify the easy majority instantly; GPT with few-shot examples handles what the rules can't. The same philosophy applies to extraction — regex for structured fields, GPT for complex ones — and everything the system extracts is regex-validated and localized with a bounding box so human reviewers can verify at a glance.

Confidence thresholds are the safety net: any page scoring below 90% on classification or extraction routes to a manual queue instead of flowing through automatically. The system automates the confident cases and escalates the doubtful ones — exactly the division of labor pharmacy operations needed.

Delivered

What did we deliver?

  • A data-driven taxonomy of 50+ form categories, discovered by clustering one month (~1.6M) of real production forms rather than guessing from samples.
  • A page-level classification engine layering keyword rules with GPT few-shot fallback, covering the entire discovered taxonomy.
  • Field-level extraction of operationally critical data: signature present or absent, signature dates, account information, class codes — each value validated and wrapped in a bounding box for reviewer verification.
  • Barcode capture via a form-recognizer API and fax-metadata extraction via regex, enriching every document with routing data.
  • A confidence-gated workflow: below-90% cases route to a human queue, everything else flows straight through.
  • Structured JSON output feeding downstream order-creation systems automatically.

Mechanism

How does it work under the hood?

  1. 01Discovery: a month of forms was OCR'd; the text from each form's top and bottom regions was embedded with sentence transformers and clustered hierarchically, yielding 50+ natural categories.
  2. 02In production, every incoming form is OCR'd and processed page by page: keyword search attempts classification first, and a 100%-confidence match passes immediately.
  3. 03Pages the rules can't settle go to GPT with few-shot examples drawn from the category's reference forms.
  4. 04Extraction runs per category: regex handles structured fields; GPT handles complex or free-form ones; every extracted value is validated with regex and located with a bounding box.
  5. 05Classification or extraction below the 90% confidence bar diverts the document to the manual review queue; confident documents proceed automatically.
  6. 06The final structured JSON is handed to downstream teams for order creation — the handoff that used to require human re-keying.

Outcome

What was the outcome?

The system processes the network's ~1.6M monthly forms at 94% classification-and-extraction accuracy, improving operational efficiency across 700+ pharmacies and freeing staff time from sorting and re-keying toward patient-facing work.

The bounding-box and confidence-queue design meant operations trusted the rollout: reviewers could verify any extraction in seconds, and the system never silently guessed on a low-confidence document.

Learnings

Key learnings

Discover the taxonomy from real volume before building the classifier — clustering a month of production forms beat any amount of guessing from samples.

Tier the intelligence by cost: keyword rules for the easy majority, LLMs only where rules run out. Most documents never need the expensive path.

Confidence gates plus bounding boxes are what make automation adoptable — reviewers verify in seconds, and the system never silently guesses.

Work with us

Have a challenge like this one?

Start a conversation