Problem
A consumer health app collects lab results, discharge summaries and imaging reports from many labs and countries. They arrive as PDFs with or without a text layer, scans and crooked photos. Test names, units and reference ranges are written in many ways, so values cannot be compared over time. One LLM prompt stopped working when a test result from a Greek lab could not be parsed at all. Silent LLM mistakes are hard to find.
Example from the article: a reference range may be written as 3.9-6.1, up to 6.1 or N: 70-99, and a result as trace, negative or +/- instead of a number.
Solution in brief
Build parsing as an engineering pipeline, not one LLM call. Extract text several ways, classify the document, extract by a strict JSON Schema, post-process deterministically, validate with retries on fallback models, and save an audit trail for every fact. Keep originals separate from derived facts so old documents can be reprocessed.
Questions this case answers
- How to build a unified structured record from heterogeneous semi-structured documents in many formats with LLM extraction that is auditable and reprocessable
- How to normalize heterogeneous measurement names, units and reference ranges so values can be compared over time
- How to build a unified patient data model from messy lab results and medical documents
- How to extract structured data from scanned PDFs and photos with LLMs reliably and reproducibly
Tools and methods
- Multi-method text extraction — pdftotext, OCR, computer vision.
- Document classification — 6 record types, about 50 subtypes.
- JSON Schema extraction — strict contract and validation of LLM output.
- LOINC / SNOMED CT / ATC / FHIR — codes for atomic facts and the exchange format.
- Provenance and Data Vault — every fact linked to its source span.
Google or a one-time email code. No password.