How to Split PDF Document Bundles with AI Accurately
A 29-page fax was filed as one document called "Holter". Here is how we now split bundled PDFs with AI for a medical practice and a family office, with the test numbers.
By Matthew Clarkson · December 2, 2026

A cardiology practice in Melbourne received a 29-page fax. Page 1 was a cover sheet. Pages 2 to 28 were a GP's results printout: about 45 short pathology reports from three labs, with a CT chest, an ECG and a CT pulmonary angiogram mixed in. Page 29 was a Holter report on a cardiology provider's letterhead.
Their original n8n workflow filed the whole fax as one document called "Holter". All the pathology went in with it.
We have now built bundle splitting twice, for multiple clients with very different paperwork. The cardiology practice gets referrals, results and letters by email and fax, and each document has to be filed on its own in Xestro. A US family office has thousands of legal and financial documents, many scanned as packets, and wants them read by models running on its own servers. This post covers what we learned on both, with the numbers.
Why the split comes first
Every later step inherits a bad split. Merge two reports and the classifier gives the file one type, the extractor reads one date, and the second report is filed under the wrong test. Drop a page and a result disappears. In a medical practice that is a patient-safety fault.
So we treat splitting as its own step, with its own prompt and its own tests, before anything is classified or extracted.
Number every page the model sees
The model never sees the PDF. It sees text, one block per page, and each block starts with a marker:
=== PAGE 4 of 29 ===
The prompt says to take page numbers from these markers and nowhere else. Without them, models estimate where a page starts from the amount of text, and they get it wrong.
Digital pages keep their own text layer, which costs nothing. Scanned pages go to a vision model. One thing caught us out: many scans already carry a text layer from the scanner's own OCR, and it is usually poor. In the medical app a page counts as a scan when images cover 70% or more of it, and a scan is always read again, text layer or not.
Trust printed page counters, but check them first
"Page 2 of 3" in a footer is the strongest clue you will get. A page marked 2 of 3 continues the document that holds 1 of 3. It never starts a new one.
The trouble is that medical documents are full of things that look like counters. A heart rate prints as "66/128". ECG strips are labelled "1/2". So we keep a counter only when a neighbouring page continues the same sequence: page 3 says 2/3 and page 4 says 3/3. A lone "66/128" has no neighbour, so it is dropped.
Confirmed counters go into the markers, so the model can use them:
=== PAGE 3 of 5 (printed page counter 2/3) ===
Code uses them again later to check the model's answer. They also let you skip the model altogether. A one-page file is one document, and so is a file whose pages form one counter sequence. Neither needs an AI call.
The model proposes, code decides
If we could keep only one rule from both projects, it would be this one.
The model returns a list of documents, each with a first and last page, a type, and the patient and date it can see. Those ranges never go straight to the PDF splitter. A corrector written in ordinary code checks them first:
Every range must sit inside the file and run forwards. If one does not, the file stops.
A printed counter sequence stays in one document. The range that holds most of it is stretched over the rest. A range wholly inside the sequence is removed, and a range that spans both ends of it is an error.
No page is lost. A page after the first document that belongs to no document goes to the document that ends on the page before.
Exact duplicates are removed.
Whether the file is one document or several is decided by counting the list. A count the model reports about itself is ignored.
Rule 3 came from a real run. The model ended one pathology group a page early because the next page started with a new referring doctor. That page was in no document. Nothing failed and nothing was logged, and a page of results was never filed. Now the corrector gives the page to the document before it, records the change and flags the document for a person.
When the corrector cannot make an answer safe, it does not guess. The file stops as "needs a person", the original is kept, and staff see the model's ranges as a suggestion on the split screen (more on that below).
Some questions belong to the client
Back to the fax. How should 45 pathology reports be filed? One file per report, per lab, per day?
A model cannot answer that, so we asked the practice. They chose:
Pathology: one file per requested date, even when the reports come from different labs. If a report has no requested date, use the collected date.
Everything else (CT, ECG, echo, Holter, X-ray) is its own file, even when it sits between pathology reports and even when a pathology lab issued it.
Requested date won over collected date for a specific reason. In the test fax, a blood count was collected the day after it was requested, and it carried the same lab number as the rest of that request. Grouping by collected date would have split it from its own results.
In the new app this is a practice setting: one file per requested date, or one file per report.
Let page ranges overlap
This was the real reason the old workflow gave up. In a results printout, one page often holds the end of one report and the start of the next. One page of the fax held the end of the CT chest, the whole ECG and the start of a thyroid antibody report. You can only cut a PDF between pages, so with ranges that could not overlap, one file per report was impossible. The model returned one document instead.
The fix was to let ranges overlap and nest, and to put a shared page in every file that has content on it. The CT chest on pages 8 and 9 sits inside a pathology group that runs from page 4 to page 11, and both files hold those pages. The practice accepted that a file may show part of a neighbouring report on its first or last page. They would not accept losing a result.
After the change, the live workflow split the fax into 10 files, exactly as the practice expected, with the cover sheet left out.
Overlap brought two new problems:
A printout often prints "Page 3 of 28" on every page. The counter rule would glue the whole printout back into one document, so it now skips documents the model marks as part of a printout.
Outside a printout, two documents should not share a page. When they do, both get a flag.
Don't let a later step undo a good split
This one surprised us. When we rebuilt the workflow as a proper app, the first real run on three synthetic printouts split every file correctly. Then 12 of the 19 documents came out wrong anyway, and all 12 were filed with no flag.
The classifier sees only a document's own pages. The last page of a pathology group is shared with the next group, so it also shows the next group's requested date. The classifier's rule was to use the most recent date it could see, so 9 of the 12 pathology groups took the next group's date. Duplicate filenames then got a " [2]" suffix, which hid the mistake.
Now, for a document in a printout, the type and date come from the split step, which read the whole printout. The classifier reads only the patient, the author and the detail. Code then checks the date: every requested date printed on a document's pages must belong to a document that holds that page. A date shifted to the next group fails that check. On the next run, none of the printout documents was wrong.
The step that saw the most context should own the fact.
Let the splitter decide "one document or a bundle"
On the family office project, the classifier on its own reached 94%, one point under the client's 95% target. All six of its errors were the same question: is this file one document or a bundle? Three bundles got the type of their first document. Three single documents, two of them with a cover letter, were called a bundle. No document got the wrong type for any other reason.
When the splitter makes that call, 98 of 100 documents get the right type, the same as Claude Sonnet 5.5 on the same set. The medical app works the same way. The split step picks a type for each range from the practice's list, the classifier picks one independently, and a disagreement flags the document.
Test the splitter on single documents as well as bundles. On the family office set it found every boundary in 23 bundles, and it also split 2 of 82 single documents by mistake. A test set made only of bundles would never show you that.
A plain prompt beat a clever one
We expected that checking each page break on its own would beat reading the whole packet. One request per break, with the end of one page and the start of the next, page text and image, asking whether a new document starts here.
It scored a boundary F1 of 0.797. The plain method, the whole packet in one request with a list of document categories, scored 0.952 on the same model. We kept the plain one. Our best guess is that most breaks only make sense with the rest of the packet in view.
Measure it against an answer key
Neither client could give us thousands of labelled bundles, and their real files are confidential. Both projects use synthetic documents with an answer key:
The family office set has 166 documents and 736 pages, including 23 bundles. About 30% are scans, many of them skewed, one sideways and one upside down.
The medical set has 67 files and 134 documents: referrals, faxes with cover sheets, three results printouts, and some files that should never become documents, such as a logo, an email signature, a blank page and a password-protected PDF.
We score boundaries as F1 over the first page of each document after page 1, and we count files where every range is exact. For the medical app, though, the number we watch is wrong documents that would be filed with no flag. We call them dangerous documents, and the target is zero. The other targets: flag at least 95% of wrong documents, and flag no more than 10% of correct ones. A prompt change stays only if all three hold. One new dangerous document is a reason to stop and read what went wrong, even when the averages improve.
Some results:
| Project | Run | Result |
|---|---|---|
| Medical | First full run | 120 documents, 6 wrong, 2 filed with no flag, 18.6% of correct documents flagged |
| Medical | Full run after the printout date fix | 134 documents, 94% filed automatically, 1 wrong and flagged, none dangerous, 2.3% of correct documents flagged |
| Family office | Gemma 4 31B (FP8) on two RTX PRO 6000 GPUs | Boundary F1 1.00, exact ranges 98.7% |
| Family office | Gemma 4 26B | Boundary F1 0.95, exact ranges 89.5% |
| Family office | Claude Sonnet 5.5, as a reference | Boundary F1 0.98 |
Most false alarms in the first medical run came from the model's own "needs review" opinion. It flagged correct echo reports because their findings did not seem to match their conclusions, which is a clinical question and not ours to raise. We replaced the free opinion with a short list of allowed reasons.
Two habits made the test loop much cheaper. The first is an oracle run, where a fake model answers from the answer key. It costs nothing and tests only our code: the corrector, the checks and their false alarms. We can also plant a known mistake, such as the shifted printout dates, and confirm the checks catch it. The second is a version number on every prompt, recorded with every AI call, so each run can be compared with the last.
Be honest about what synthetic data proves. At 100 documents, a model that is 97% accurate makes about three mistakes, so treat catch rates for splitting as a rough guide. The original medical prompt also used the test fax as its worked example, which proved the rules on that fax and nothing more. The new app uses an invented printout in its prompt, and both clients test real files of their own before go-live.
Use a small model for the boundaries
Finding boundaries does not need the biggest model. In the medical app, splitting runs on Claude Haiku 5.5 at under one US cent per file. A 29-page printout is about 35,000 input tokens. Claude Sonnet 5.5 reads the scanned pages and classifies each document. A full run of the 67-file test set costs about US$3.
Where the model runs depends on where the data may go. Patient documents stay in Australia, so the medical app uses Amazon Bedrock's Australian inference profiles in Sydney. The family office's documents may not leave the building, so it runs open-weight models on its own GPUs. The pipeline is the same shape either way.
Give staff a quick way to fix a split
Some splits will still be wrong, so staff need a screen that shows the pages as thumbnails with a bracket beside each document. They can split a document at a page, join two documents, add a document, or remove one. There is no drag and drop. Every action is a button, so it works with a keyboard and on a phone. Each flag about where a document starts or ends links straight to that page.
Fax cover sheets are not filed, but they sometimes carry a message. The app looks for words such as "urgent", "please call" and "please book" on the cover, after it removes the standard confidentiality notice. Every fax cover says to call the sender if you got it in error, so without that step every cover would fire.
If you are building this yourself
Put a page marker on every page of text the model reads.
Keep a printed page counter only when a neighbouring page confirms it.
Skip the model when the answer is certain.
Treat the model's page ranges as a proposal, and check them in code.
Never lose a page. When the plan is unsafe, stop and keep the original.
Ask the client how documents should be grouped.
Allow overlapping ranges if your documents share pages.
Count the wrong documents that would be filed without a flag, and keep that number at zero.
We build document pipelines like these for medical practices and for anyone else with a backlog of bundled PDFs. See our automated data processing work, or send us a few anonymised examples and we will tell you what a reliable split would take.
Last updated on December 2, 2026
Free tool · 2 minutes
Automation ROI Calculator
See what a manual process is really costing you, and the payback on automating it.
Continue Reading
View all
Business Software Integration: How to Connect Your Systems
Business software integration means your accounting, CRM, job management and other tools pass data to each other automatically, so nobody retypes the same information twice.
Nov 25, 2026

Automating Data Entry into Xestro Without an API
Xestro has no public API. Here is how we get referrals, ECG and other device reports, and hospital results into it automatically, with a person checking what matters.
Nov 4, 2026

What Is Data Warehousing? A Simple Guide for Humans
Curious about what is data warehousing? This guide explains core concepts, architectures, and real-world benefits in simple terms for modern business.
Nov 2, 2025
Sick of reading about automation?
Book a free 15-minute intro call. We’ll talk through what you’re trying to automate and whether we’re a good fit.