Writings
Drafting pathology reports with AI
My master's final-year project: a tool that drafts pathology reports from a few keywords and the pathologist's voice, built with CHU Mohammed VI in Tangier.
Published
Reading time
3 minutes
Post
So, for every specimen, a pathologist writes a report, it’s long, it’s structured, and for the same organ it’s pretty much the same report every time, with only the findings changing inside it. That’s a lot of typing the same sentences over and over around a few new facts. Patho Draft, my master’s final-year project, drafts those reports for them, so the pathologist only has to read, correct and sign.
I built it with the pathology department of CHU Mohammed VI in Tangier, between March and August.
Templates first, AI second
The obvious idea would be to just let a model write the whole report freely, and Patho Draft doesn’t do that. A pathology report is a medical document, its structure is fixed, its wording matters, and a sentence that sounds right but isn’t is worse than no sentence at all.
So at the heart of Patho Draft are templates, each organ has several of them, and to write them I created TL (Template Language), a small DSL made just for defining these templates. A template declares typed inputs (text, a number, one choice or several), groups its text into sections, and only includes a passage when a condition holds. A value can also go through converters, like a measurement turned into another unit, and expressions are evaluated safely, they’re never run as code.
The point of TL is to keep the model from hallucinating stuff. TL code gets compiled and validated, so a broken template gets caught before it ever reaches a report, and the compiled template is then used as a scaffold for the text that gets generated, the structure, the sections and what’s allowed in them all come from the template, not from whatever the model feels like writing that day.
The same template then becomes the form the pathologist fills in, and that form, once filled, produces the report. Pathologists can edit templates on the fly, and the language was designed to sit under a drag-and-drop editor, so nobody has to write templates by hand (don’t you worry).
Where AI helps
AI does two narrow jobs, both on the way in:
- Picking the template, from a few keywords, it figures out which template applies, so the pathologist doesn’t have to hunt through a list.
- Dictation, it turns speech into text in the report’s fields, because at the microscope, a pathologist rarely has a free hand.
So AI picks the template and transcribes the dictation, the template writes the report, and the pathologist reviews everything before it’s final.
For picking the template, the model is Llama 4, and it doesn’t run on the hospital’s machines, it runs on Cerebras, an AI inference platform. Now the reason I went with Cerebras is speed, and that speed comes from their own hardware. Instead of a rack of GPUs, they build their chips out of a whole silicon wafer (the Wafer-Scale Engine), and they keep all of the model’s weights in the on-chip memory, so it never has to keep shuffling them back and forth from external memory the way a GPU does, which is exactly where most of the waiting comes from. When they launched Llama 4 back in April, they were doing over 2,600 tokens per second on Llama 4 Scout, while the fastest GPU setup was at around 137, so for a pathologist typing a few keywords, the template is basically there before they look up.
Built for a hospital
Report writing can’t stop just because the network does, so Patho Draft keeps working offline, and access is limited to the hospital’s staff. Under the hood, it’s a Next.js application on Supabase, with a Lexical editor for the reports.
What I took from it
In a field where mistakes actually matter, I’d rather keep the model on the small, boring jobs and let the templates do the writing.
Next
One lint config for every repoorAll 21 writingsorRandomorHome