Abstract
Liver cancer primarily develops in patients with chronic liver disease (CLD), yet most cases are diagnosed at advanced stages with poor prognosis. While CLD surveillance generates extensive longitudinal data, its free-text nature hinders large-scale research. To address this, we developed a scalable framework using open-source LLMs with constrained decoding to process unstructured text across radiology, pathology, and transplant assessment domains. A calibration set comprising 507 reports from 30 patients was manually annotated to benchmark four LLMs against a regular expression baseline across 70 tasks. Llama-3.3-70B performed best, exceeding 90% accuracy on 59/70 tasks, outperforming Llama-3.1-8B (a smaller variant), OpenBioLLM-70B (a medically fine-tuned model), and DeepSeek-R1-8B. Constrained decoding achieved >99.9% format adherence, far surpassing unconstrained prompting (87.4%). Applied to the full cohort, the pipeline analysed 22,493 reports to generate a patient-level database of 29,225 datapoints (35 variables, 835 patients) without manual annotation. Further analysis confirmed known liver cancer risk factors (male sex, viral hepatitis, smoking, diabetes), and allowed for reconstruction of individualised disease timelines. This work provides a scalable blueprint for transforming real-world clinical free-text into structured formats and personalised patient trajectories. Future applications have the potential to accelerate data-driven research into early cancer detection within complex pre-cancerous diseases like CLD.
Competing Interest Statement
H.P. has received research funding from AstraZeneca. Z.G. has received research funding from GE healthcare. M.A.F. is a current employee and stockholder of AstraZeneca. M.H. has received speakers fees from Sirtex medical, consultancy fees from Quotient Therapeutics, Ensocell, Boston Scientific and Spliceor, in addition to unrestricted grant support from AstraZeneca and Pfizer. M.C.O. is a co-founder and employee of 52 North Health Ltd, has received research funding from GE HealthCare, and speaking fees from GSK. The other authors declare no competing interests.
Funding Statement
This study was funded by AstraZeneca UK Limited and the NIHR BioResource (G127831).
Author Declarations
I confirm all relevant ethical guidelines have been followed, and any necessary IRB and/or ethics committee approvals have been obtained.
Yes
The details of the IRB/oversight body that provided approval or exemption for the research described are given below:
The Health and Social Care Research Ethics Committee A of the Health and Social Care Business Services Organisation gave ethical approval for this work (REC reference 20/NI/0109, IRAS 285521)
I confirm that all necessary patient/participant consent has been obtained and the appropriate institutional forms have been archived, and that any patient/participant/sample identifiers included were not known to anyone (e.g., hospital staff, patients or participants themselves) outside the research group so cannot be used to identify individuals.
Yes
I understand that all clinical trials and any other prospective interventional studies must be registered with an ICMJE-approved registry, such as ClinicalTrials.gov. I confirm that any such study reported in the manuscript has been registered and the trial registration ID is provided (note: if posting a prospective study registered retrospectively, please provide a statement in the trial ID field explaining why the study was not registered in advance).
Yes
I have followed all appropriate research reporting guidelines, such as any relevant EQUATOR Network research reporting checklist(s) and other pertinent material, if applicable.
Yes
Footnotes
Contributing authors: zg323{at}cam.ac.uk; gk503{at}cantab.ac.uk; margarete.fabre{at}astrazeneca.com; swb35{at}cam.ac.uk; mwh20{at}cam.ac.uk; mc973{at}cam.ac.uk;
We have implemented several key changes to the manuscript: - We expanded the performance metrics, adding sensitivity, specificity, precision, and F1 score metrics with bootstrapped confidence intervals for all tested models. We also included patient-level performance metrics for timeline reconstructions to provide a better real-world perspective. - We conducted a comprehensive qualitative analysis of extraction failures and model hallucinations for tasks scoring below 90%. We added supplementary tables with illustrative examples of these failure modes and expanded our discussion on mitigation strategies and acceptable error thresholds. - We introduced a quantitative comparison of the latency and computational costs associated with unconstrained prompting versus constrained decoding (Guidance and Ollama). Furthermore, we included unconstrained decoding performance in our benchmarking figures to explicitly illustrate the trade-offs and the necessity of constrained methods. - We established a public GitHub repository containing all code, prompts, processing pipelines, and regular expressions to guarantee full methodological transparency.
Data Availability
The data underlying this article cannot be published due to confidentiality considerations.





