All insightsEngineering

How we built an AI auditor for healthcare paperwork

A pair of diabetic shoes costs the government a few hundred dollars. One wrong date in the paperwork can cost the supplier all of it, years later. We built an auditor that reads the paperwork before it ships, and the AI was the easy part.

Author
Ahmed Panju
Published
Read
4 min
In this note · 4 sections
  1. 01What does the government actually want?
  2. 02Why the AI doesn’t get to decide
  3. 03What happens when it isn’t sure?
  4. 04The AI was the easy part

A pair of diabetic shoes costs most governments a few hundred dollars.

If doctors get 1 date wrong on the paperwork when they’re applying on behalf of a patient, the government can take all of that money back. Sometimes even years later, in an audit, long after the patient wore the shoes out.

A week ago I wrote about a founder whose healthcare AI demo turned out to be ChatGPT on a screen share. What I didn’t mention was that we are building the real version of that app for a diabetic footwear supplier.

What does the government actually want?

Our client sells diabetic shoes, and a national health program pays for most of them. The problem is the paperwork, and the difficulty of making sure everything is perfect, down to every last detail.

For the government to approve and ultimately pay, the supplier needs four documents from up to two doctors:

  • A statement from the doctor who manages the patient’s diabetes
  • A foot exam that shows why the patient needs the shoes
  • A note that shows the doctor actually manages the diabetes
  • A signed order for the shoes

Every page must name the same patient. The visits must fall inside a six-month window before the shoes are delivered. The signatures must come after the exams they sign off on.

Before our tool, staff checked every packet by hand. Most packets arrive by fax. (Yes, fax. In 2026. Healthcare still runs on it.)

My first thought was the same one that founder had: give all of the PDFs to the most powerful AI I had API access to, and ask if the documents are compliant or not.

This works surprisingly well… in a demo.

Why the AI doesn’t get to decide

The problem is that “looks fine to the AI” is not a standard that a government auditor accepts.

So we split the job into two separate segments: 1) an agent that is responsible for reading and unpacking the information from the PDFs and 2) a plain code algorithm that determines the verdict on the compliance of the document.

For each rule the government checks, the AI gives one of three answers, plus its proof:

TypeScript
type Finding = {  status: "supported" | "contradicted" | "unknown"  quote: string       // the exact words on the page  page: number | null // where those words are}

This way, the AI never says “this packet passes.” Instead it says something like “page 2 shows a history of foot ulcers, and here’s the quote.”

Then a set of rules, written in code and covered by tests, decides whether that meets the government’s rule. Here’s one of them: the foot exam only counts if the doctor who signed the statement actually wrote it.

TypeScript
// compliance.tsexport function certifierAuthored(  exam: ExamEvidence,  certifierName: string,): boolean {  return (    ["MD", "DO"].includes(exam.authorRole) &&    sameProvider(exam.authorName, certifierName)  )}

No prompt, no model, no “it looks right to me.” Just a function that a test can break.

This gives us two things a chatbot can’t:

  1. Every pass or fail has a “View” link that opens the exact page, allowing a staff member to check the AI’s work in about two seconds, instead of reading the whole packet again.
  2. When the AI can’t find a quote, the answer is “unknown,” and it sends the case to a person.

What happens when it isn’t sure?

Dates are where things can sometimes get complicated. Most of the time, dates are easy to read, neatly typed out portions of the document. Sometimes, however, we are dealing with handwritten dates, from a group of professionals who are not exactly known for having the best handwriting of all time.

Every date the AI reads comes with a confidence score. At first, we only let a date through on its own at 0.90 confidence or higher, and the rest required manual verification by a person. This, however, was overkill, and instead we lowered the threshold to 0.75, with a few exceptions:

  • A date like 01/02/2026 can be January 2 or February 1. These dates still need a 0.90 confidence score.
  • A date in the future always goes to a person.
  • A birth date that makes the patient 121 years old goes to a person.

In code, the whole policy fits in one object:

TypeScript
// date-review.tsexport const DATE_READ_THRESHOLD = {  confidence: 0.75,       // a date stands on its own at this score  sureConfidence: 0.9,    // a date like 01/02/2026 needs this score  birthDateMaxYears: 120, // older than this goes to a person}

And here’s how we catch the 01/02/2026 problem:

TypeScript
// 01/02/2026 is January 2 or February 1: both parts can be the month.function monthDaySwap(text: string): boolean {  const m = /(\d{1,2})\/(\d{1,2})\/\d{4}/.exec(text)  if (!m) return false  const a = Number(m[1])  const b = Number(m[2])  return a !== b && a <= 12 && b <= 12}

There is an equilibrium to be found here. Lower the threshold too much, and dates that shouldn’t pass end up returning positive audits. A threshold that is too high requires too much intervention by the user, defeating the time savings of the AI auto-reviewing the documents.

The AI was the easy part

Looking back, the model was the smallest part of this project. That founder’s weekend demo could read these PDFs too.

What took us months was everything around the model: rules written as code, a quote and a page for every answer, and a clear point where a person takes over. If an auditor shows up years from now, every answer in the packet points back to the exact page it came from.

More insights

All insights →
  1. Engineering · Read · 1 min

    Eight minutes from advisory to offline. Patching came second.

    When NGINX2Root dropped, we took the affected service off the internet before patching anything. Here’s why that was the faster safe move.

    XORS Studio

  2. Engineering · Read · 6 min

    Building an AI-powered pipeline to process returns

    We built a pipeline to automatically read return forms, processing 81% of a batch without human review. AI agents perform multiple roles within the pipeline to improve accuracy.

    Edward Yan

  3. Engineering · Read · 5 min

    Our hardware test timed out. A longer timeout would have passed a slow filesystem.

    A new filesystem image for Flightwall’s wall displays stalled on our test bench. We nearly fixed it by waiting longer, blamed the wrong thing, then rebuilt the image eight ways on a laptop to find out what actually made it slow.

    XORS Studio

Start a project

Tell us what you need to ship.

Message us, or pick a day below. We reply within 24 hours.

x@xors.xyz
XORS Studio
Book a call
Talk to one of our engineers.
  1. 1Pick a day on the calendar.
  2. 2One of our 7 senior engineers runs the call.
  3. 3Tell us the problem. We plan the build with you on the call.
30 minutes
Google Meet

Within 24 hours you get a written plan and a price. It is free, and it is yours to keep.

 
AvailableSelected
Pick a day
About: “How we built an AI auditor for healthcare paperwork”

Calendly shows the open times for this day. You book the call there.

See open times →