AI Fax Referral Intake in Healthcare: The Model Reads, Code Decides

How to build AI fax referral intake in healthcare: PHI-free events, page classification, field provenance, NPI checks, patient matching and per-field evals.

Clint JohnsonPublished 11 min read

Key takeaways

  • Let the LLM read the fax and propose fields, but code checks every field it can verify and the model never picks the patient chart.
  • Every extracted field should point to a page and bounding box from the OCR layer, and a missing field stays null instead of being guessed.
  • Track wrong-patient attachments as safety events separately from misroutes, and turn every staff override into a regression fixture.

A referral fax is an inbound API. Most intake pipelines don't treat it like one.

I've spent a lot of years making HL7v2 feeds durable: Mirth for the transform, RabbitMQ for delivery, and Snowflake and Google Cloud's Healthcare API on the receiving end. Those feeds get retries, idempotency, validation and audit trails. A faxed referral usually gets an inbox and someone squinting at it. It needs the same rigor, and putting an LLM in the loop doesn't remove that need.

My rule is short. Let the LLM read the referral fax. Don't let it decide what reaches the EHR. An LLM is good at turning a skewed scan into candidate fields. It is bad at knowing when it's wrong. So code checks every field it can verify, a person reviews every page the model can't classify with confidence, and the model never picks the patient chart.

In practice, AI fax referral intake is a five-step pipeline. First, turn each inbound document into a PHI-free event. Second, classify every page. Third, extract fields into a candidate FHIR ServiceRequest, with provenance and code checks on each field. Fourth, match the patient through your EMPI, not the model. Fifth, count errors per field and treat wrong-patient attachments as safety events.

Referrals come in by fax machine, eFax inbox and Direct message. Neither CMS-0053-F nor CMS-0057-F covers provider-to-provider referral faxes (more on both at the end). So the pipeline that reads them has to fail safely.

How to automate inbound referral faxes without PHI in the queue

A fax arrives as a TIFF or PDF from your fax server, an eFax inbox or a Direct message. Store the file once, in an encrypted bucket with access logging. Then publish an event that carries a pointer and nothing else: event, document_id, channel, received_at, page_count.

No patient name, no MRN, no OCR text. Of everything in this post, this is the rule I'd never relax. Queues get logged, replayed, mirrored into dev and dumped into dead-letter tooling that half the team can read. When the message holds only an ID, every consumer has to go back to the store and pass an access check before it sees PHI. The broker moves pointers. The store holds the PHI. Key every downstream step on document_id so a redelivered message doesn't get processed twice.

OCR first, and keep the coordinates

Before any model sees a page, run OCR that returns word-level text, coordinates and a per-word confidence. Faxes are hostile input. Pages arrive skewed, compressed and low-resolution, with stamps over the text and handwriting in the margins. Deskew and clean each page first. When most words on a page come back low-confidence, send that page to a human. Don't make a model guess at it.

It's tempting to skip OCR and hand the page image straight to a vision model. Keep the OCR layer anyway. The provenance check below compares against it, and it gives you coordinates you can verify. You can still give the model the image next to the text. When the two disagree on a field, that's a review, not a tiebreak.

One trap specific to fax: the transmission header across the top of each page carries a date, a time and a sending number. Mask that strip or label it. Otherwise the model can read the fax date as the referral date, or the fax number as the office phone.

Classifying fax pages: referral, records, results or junk

One fax is usually several documents stapled together: cover sheet, referral form, last office note, labs, a copy of the insurance card. Classify each page, not each fax. Use a small fixed set of types: referral, records, results, prior auth response, junk. Then group adjacent pages into documents.

A low-confidence page goes to a human, never to a default bucket. The tempting shortcut is "if unsure, call it records." A prior auth response filed as records throws no error. It just sits unread.

"Low confidence" needs a real mechanism, and the model's opinion of itself isn't one. Ask an LLM to rate its confidence from 1 to 10 and you get a number, not a calibrated probability. Here's what I'd use instead:

  • Constrained choice with abstain. The output is one of the fixed types or unsure. No free text and no invented sixth category. unsure routes to a human.
  • Two-pass agreement. Classify each page twice, once from the OCR text and once from the image, or with two different models. Disagreement routes to a human. It doubles per-page cost and adds latency. A misfiled prior auth response costs more.
  • A trained classifier score, once you have enough labeled pages. Cheap and fast, but it needs labels you don't have on day one.

Whichever you pick, set the threshold from real staff overrides (more on those below), not from a number that felt reasonable on day one.

Pick types that map cleanly to LOINC document codes. LOINC is how the federal claims attachment standard identifies the type of attachment content. You'll want that mapping later.

Extracting referral fields into FHIR with provenance

The referral pages become a candidate FHIR ServiceRequest: who is referring, who the patient is, what's being requested, and why. The pages themselves become a DocumentReference. Neither resource is written anywhere yet.

Every extracted field carries its evidence:

{
  "field": "requester.npi",
  "value": "1234567893",
  "page": 2,
  "bbox": [412, 188, 590, 214],
  "source_text": "NPI: 1234567893",
  "status": "candidate"
}

Two rules follow from this. First, the model never fills in a missing field. If the fax has no date of birth, the field is null and it goes on the missing-info list. The prompt says so, and code enforces it: any value whose source_text doesn't appear in the OCR text inside that bounding box on that page gets rejected. That catches the model "helpfully" inferring a DOB from an age. It won't catch an NPI copied from the wrong letterhead on the same page, because that text really is there. The NPPES identity check below catches that one. It's the same cite-every-claim pattern from detecting hallucinations in AI clinical notes.

Second, a reviewer clicks a field and sees the exact spot on the page it came from. Review becomes a quick look instead of a hunt through nine pages.

Then code checks every field that has a known shape:

  • Dates must parse, can't be in the future, and the DOB has to come before the referral date.
  • ICD-10 codes get a shape check first: a letter, a digit, an alphanumeric, then an optional dot and up to four more characters. Then a lookup in the code set. A code that looks right but isn't in the set fails. The model reads the code off the page. It doesn't type one from memory.
  • Payer IDs get checked against your own payer table. An unknown payer becomes missing info, not a guess.
  • NPIs get the most work, because a wrong one quietly attaches the wrong provider.

How to validate an NPI from a fax

The NPI's tenth digit is a Luhn check digit. You compute it over the number with the prefix 80840 in front (80 for health, 840 for the US). With first nine digits 123456789, the check digit comes out to 3, so 1234567893 is valid. Here it is in code, with the ICD-10 check alongside:

import re

def npi_luhn_ok(npi: str) -> bool:
    if len(npi) != 10 or not npi.isdigit():
        return False
    total = 0
    for i, ch in enumerate(reversed("80840" + npi)):
        d = int(ch)
        if i % 2 == 1:
            d = d * 2 - 9 if d > 4 else d * 2
        total += d
    return total % 10 == 0

ICD10_SHAPE = re.compile(r"^[A-Z][0-9][0-9A-Z](\.?[0-9A-Z]{1,4})?$")

def icd10_ok(code: str, code_set: set[str]) -> bool:
    c = code.strip().upper()
    # code_set holds codes without dots
    return bool(ICD10_SHAPE.match(c)) and c.replace(".", "") in code_set

Luhn catches every single-digit error and most adjacent transpositions, but not 09 swapped with 90. A pass only tells you the number is well formed. It doesn't tell you the number belongs to the doctor who sent the fax. So add two more layers. An NPPES lookup confirms the NPI is assigned and active. An identity check confirms the registry name, entity type and taxonomy match the provider on the fax (a three-layer check like this one). The identity check is what catches the NPI lifted from the wrong letterhead.

One trap: some sites claim the first digit encodes individual vs. organization. The NPI carries no embedded information. Read the entity type from the NPPES record, not from the digit.

Matching a faxed referral to the right patient

The model extracts demographics, with provenance like every other field. It does not match the patient. Matching runs through the same deterministic EMPI rules your other inbound feeds use.

The fields I'd key on are date of birth, last name, first initial, sex, and an identifier. The identifier is either an MRN your EMPI already knows or the payer member ID from the insurance card page. Normalize before comparing: uppercase, strip punctuation and name suffixes, and parse the DOB into one format.

A confident match is exactly one candidate chart where every one of those fields agrees, including at least one identifier. Everything else goes to a human: zero candidates, two or more, or one candidate that agrees on demographics but has no identifier to confirm it. The reviewer sees the extracted values and their page crops on one side and the candidate charts on the other, field by field, with disagreements highlighted. They pick a chart, create a new patient, or reject the document. The model never chooses between candidate charts, no matter how sure it sounds.

A misrouted document costs time. A document attached to the wrong patient puts someone else's clinical information in a chart where clinicians will read it and act on it. That doesn't belong in a probabilistic step.

Once a referral clears the checks and the match, writing it to the EHR is its own problem: FHIR on the outside, vendor-specific behavior on the inside. See writing AI output back to Epic as DocumentReference.

The missing-info request goes out under a human's name

Everything that came back null or failed a check goes on a missing-info list keyed to the document:

{
  "document_id": "doc_01J8Q4...",
  "missing": [
    { "field": "patient.birthDate", "reason": "not_found" },
    { "field": "requester.npi", "reason": "nppes_name_mismatch", "page": 2 },
    { "field": "reasonCode", "reason": "not_found", "page": 2 }
  ]
}

Each reason maps to one fixed sentence template. Code fills the templates, not the model, so the draft reads: "Date of birth missing. The NPI on page 2 doesn't match the referring provider in the NPI registry. No diagnosis code on page 2." A human reviews it and sends it. It goes to an outside office, it contains PHI, and it carries your organization's name, so a person owns it.

Evaluating AI fax intake: count errors per field

A single accuracy number hides which field is failing. Count errors per field: NPI wrong, DOB wrong, a missing field filled in when it should have been null, a page misclassified. A pipeline that is 97% accurate overall can still get the referring NPI wrong often enough to cause damage. It's the same binary, per-failure counting I push for in any LLM eval.

Keep two failure classes out of the shared score entirely:

  • Wrong-patient attachment is a safety event. The target is zero, and every one gets reviewed like an incident.
  • Misroute is a queue delay. Measure it in time-to-correct-queue.

If you blend them, a model change that fixes a hundred misroutes and adds one wrong-chart attachment looks like a win.

The best eval data you'll get is free. Every time intake staff override the pipeline (change a page type, fix a field, reject a match), save that case as a regression fixture: the input pages, what the pipeline produced, and what the human corrected it to. These fixtures contain PHI, so they live in a PHI-controlled test environment or get de-identified first. Replay them on every prompt or model change. A change that breaks a past override doesn't ship. The same overrides are what you tune the classifier threshold on.

Does the CMS claims attachment rule end healthcare fax?

Not for referrals. CMS-0053-F, the claims attachments rule, was published March 24, 2026. It took effect May 26, 2026, and compliance is due May 26, 2028. The rule itself says claims attachments have stayed "largely manual, frequently relying on fax, mail, or portal uploads." Its fix is X12 275/277 carrying HL7 C-CDA/CDA documents. HHS considered FHIR and didn't adopt it.

Prior auth attachments were dropped from the final rule. Prior auth goes through the FHIR Prior Authorization Support API under CMS-0057-F. Provider-to-provider referral faxes, the main input to this pipeline, fall under neither rule. The "fax phase-out" headlines are about one payer-provider transaction.

Under the attachment standard, a CDA document's entire body can be a scanned image, while the header carries machine-readable document type, patient and provider identifiers, and service dates. Inbound referrals don't turn into outbound claims attachments. They are different documents moving in a different direction. But two pieces of this pipeline carry over: the page-type-to-LOINC mapping and the code that verifies identifiers and dates. Reuse both when your outbound attachments go electronic. The X12 275 transaction and payer connectivity are separate work.

Your referral inbox will keep getting faxes. Build the intake like it's staying.

Questions people ask

How do you validate an NPI number from a faxed referral?

Run a Luhn check over the NPI with the prefix 80840 in front, then confirm in NPPES that the NPI is assigned and active. Also check that the registry name, entity type and taxonomy match the provider on the fax, because a Luhn pass only shows the number is well formed.

Should an LLM match faxed referrals to patient charts?

No. The model extracts demographics, and matching runs through deterministic EMPI rules on date of birth, last name, first initial, sex and an identifier such as a known MRN or payer member ID. Zero matches, multiple matches, or a match with no confirming identifier go to a human, because a wrong-patient attachment is a safety event.

How do you decide when an AI fax page classification is low confidence?

Don't rely on the model rating its own confidence. Use a constrained choice with an unsure option, agreement between two classification passes, or a trained classifier score, and set the threshold from real staff overrides.

Does the CMS claims attachment rule eliminate healthcare fax?

No. CMS-0053-F standardizes claims attachments on X12 275/277 with C-CDA/CDA documents, with compliance due May 26, 2028. Prior auth attachments and provider-to-provider referral faxes fall outside it.