
The Challenge
Epilepsy treatment needs detailed information: which subtype of epilepsy, which seizures, how often they occur, which medicines and which side effects. The electronic record holds it, but mostly in prose.
- Diagnosis Codes used by hospitals miss the detail. Diagnostic codes depend on coding versions and on admin staff bothering to map to the correct codes.
- Rules don’t travel. Rule-based software extraction struggles with free text, and rules written for one hospital often fail at another.
- Doctors and nurses lack the time to do this admin work. Doctors with relevant expertise lack the time to read hundreds of pages of records.
- Privacy comes first. Clinic letters contain sensitive personal information, so AI services that send data over the internet were ruled out from the start.
The Solution
The team designed data pipelines that combine CogStack’s AI with openly available LLMs (from the Llama and Mistral families) were deployed on the hospital’s own GPU server, so no identifiable patient data left the NHS. King’s held more than 25,000 adult epilepsy records from 2013-2019. A subset of 280 randomly selected clinic letters were independently marked by two epileptologists. This marking by doctors showed high consistency for validity (Cohen’s kappa 0.84). Every result was checked against the epileptologists’ markings.
- Ask the letter a question: direct extraction posed a clear question about each letter, such as which anti-seizure medicines the patient currently takes.
- Try smarter prompts: the team also tested summarising the letter first, adding background on epilepsy classifications, giving the model a role such as “Expert Epilepsy Neurologist”, and showing it worked examples.
- Output structured data: every answer was converted into a consistent, structured format ready for analysis.
- Benchmark everything: five LLMs and six extraction methods were compared with expert annotations and with MedCAT.
Results & Impact
The best models came within a few points of the experts for epilepsy medications, epilepsy subtype, seizure type.
Simple beats the clever. Asking a direct question consistently worked well. Role prompts made little difference, and adding worked examples actually lowered performance.
Newer and bigger AI isn’t automatically better. The largest AI models at the time were frequently not the best, and often a mixed approach of small and large AI works best.
Some things are hard for humans too. For associated symptoms such as headache or depression, the best model was on par with the experts, who often missed these symptoms as well.
“What would have taken a resident doctor 3-4 years to fill an epilepsy registry now can be done in weeks or months”
What this means for real-world data
This study points to where clinical AI is heading. Locally run LLMs can now read clinic letters with near-expert accuracy and far faster than manual review. Paired with established clinical NLP, they can turn routine records into research-ready real-world data at scale. CogStack brings both into the hospital.
Read the full study: Fang S, Holgate B, Shek A, et al. Extracting epilepsy-related information from unstructured clinic letters using large language models. Epilepsia 2025;66:3369–3384. https://doi.org/10.1111/epi.18475
