Paper · Evaluation and safety · Version 1
Development and validation of a pragmatic pipeline for clinical free-text annotation using locally deployed open-weight large language models
First published: Scientific Reports, . Original
Copyright the authors. Licensed under Creative Commons Attribution 4.0 International.
This page holds the text of the paper, converted to HTML; figures may be left out.
A repeatable way to choose a locally run open-weight model for tagging symptoms in German emergency reports. Nine models were screened and the best was checked against careful manual labels.
Abstract
Clinical information required for surgical data science (SDS) is frequently embedded in unstructured text. We developed and evaluated a reproducible pipeline for selecting locally deployed open-weight large language models (LLMs) for binary symptom annotation. In this retrospective single-center study, 1,100 German emergency-department reports were manually annotated for nausea, vomiting, diarrhea, and dysuria. After reserving 100 reports for prompt formulation and temperature testing, nine LLMs were screened on symptom-specific stratified development sets (N = 250). Selected models were compared with a negation-aware rule-based baseline in independent validation sets (N = 750) using F-score and patient-level bootstrap confidence intervals. Temperature 0.0 provided the greatest overall stability. Validation F-scores were 0.985 for vomiting, 0.979 for nausea, 0.824 for dysuria, and 0.814 for diarrhea. Corresponding baseline F-scores were 0.913, 0.724, 0.705, and 0.853, respectively. Paired comparisons favored LLMs for nausea and vomiting; confidence intervals included zero for diarrhea and dysuria. Median inference times ranged from 0.298 to 1.653 s per report. Discrepancies reflected operational criteria, temporal variation, inconsistent documentation, missed mentions, and five reference errors. Pragmatic model screening can identify suitable local LLMs for clinical free-text annotation. The pipeline is reproducible and adaptable but requires context-specific configuration and validation.
Introduction
Background and problem statement
Recent advances in data science and machine learning (ML) have accelerated the development of surgical data science (SDS), an emerging field that aims to improve surgical care through data-driven methods. Because ML applications depend on large, well-annotated datasets, SDS places particular emphasis on efficient strategies for data acquisition, curation, and annotation. However, in abdominal surgery, the availability of such datasets remains limited, as highlighted in a recent systematic review. A major reason is that clinically relevant information is largely documented as unstructured free text rather than in standardized formats. While structured documentation could theoretically address this limitation, it is often impractical in routine clinical practice because increasing administrative demands already limit the time available for direct patient care. Consequently, manual extraction and annotation of surgical data remain labor-intensive, time-consuming, and dependent on expert input, creating a major bottleneck for scalable dataset generation in SDS. These limitations have direct consequences for the development of ML models in surgery. A recent scoping review showed that most models relied solely on internal validation, many were trained on relatively small datasets, and important aspects such as uncertainty estimation and model explainability were frequently not reported. Consequently, automated approaches for extracting structured information from clinical free text have become an important focus in SDS, as they could enable the generation of structured datasets required for downstream ML applications. However, scalable and reliable solutions for high-quality annotation remain limited.
Natural language processing and large language models
Earlier natural language processing (NLP) approaches sought to automate symptom extraction from clinical free text, but their broader application has often been limited by manual rule maintenance, requirements for large domain-specific datasets, and the need for adaptation to new clinical contexts. Recently, large language models (LLMs) have emerged as a potentially scalable solution, achieving expert-level annotation quality in selected tasks and reliably extracting clinical attributes without task-specific training. For example, GPT-3.5 achieved performance comparable to or exceeding that of trained terminology-based classifiers for most symptoms, while relative performance remained symptom-dependent. Multiple studies indicate that locally hosted LLMs can achieve comparable performance to online LLMs like GPT-4o, supporting their potential use under strict data-protection requirements. Recent studies also highlight that both expert and LLM-based annotation have distinct strengths and limitations. LLM approaches have nevertheless demonstrated higher consistency and faster annotation, which may facilitate the generation of large datasets for ML research. Despite these promising findings, there is limited evidence on pragmatic and reproducible strategies for selecting and applying locally hosted open-weight LLMs to surgical clinical free text. Therefore, this study aimed to develop and evaluate a reproducible annotation pipeline in which multiple locally deployed models are pragmatically screened on a limited manually annotated development sample before the selected model is applied to an independent validation sample. A simple zero-shot prompting strategy was held constant to focus on the feasibility of the model-selection and annotation workflow rather than comprehensive model benchmarking or prompt optimization.
Results
Of 2,127 identified records, 1,466 were screened until 1,100 eligible reports were included. Exclusions comprised 197 records without an eligible emergency report, 14 trauma-related presentations, 22 repeated presentations, and 133 records with incomplete documentation. The remaining 661 records were not screened after the target sample size had been reached. The median age was 46 years (IQR 32–64) and 551 (50.1%) were female. Table 1 summarizes symptom prevalence in the full cohort and study subsets. Nausea was present in 482 patients (43.8%), vomiting in 301 (27.4%), diarrhea in 146 (13.3%), and dysuria in 59 (5.4%). The final text input provided to the LLMs had a median length of 298 words (IQR, 221–404) and 2,524 characters (IQR, 1,836–3,466).
Table 1 Symptom prevalence in the full cohort and study subsets.
| Symptom | All N = 1,100 | Prompt and Configuration N = 100 | Development N = 250 | Validation N = 750 |
|---|---|---|---|---|
| Nausea (N, %) | 482 (43.8) | 52 (52.0) | 107 (42.8) | 323 (43.1) |
| Vomiting (N, %) | 301 (27.4) | 33 (33.0) | 67 (26.8) | 201 (26.8) |
| Diarrhea (N, %) | 146 (13.3) | 13 (13.0) | 33 (13.2) | 100 (13.3) |
| Dysuria (N, %) | 59 (5.4) | 2 (2.0) | 14 (5.6) | 43 (5.7) |
- Development and validation sets were generated separately for each symptom by stratified random sampling of the 1,000 reports not included in the exploration set. Consequently, patient membership could differ between symptom-specific splits. Values are presented as N (%).
Temperature evaluation
Annotation performance and output validity were generally most stable at low temperatures. Several models maintained near-perfect F-scores across the evaluated range, whereas mistral-large:123b and nemotron-mini:4b showed decreasing performance at higher temperatures. For mistral-large:123b, the median F-score decreased from 0.981 at temperature 0.0 to 0.789 at temperature 1.0, while the median invalid-response rate increased from 0% to 30%. For nemotron-mini:4b, the median F-score decreased from 0.863 to 0.734, and the invalid-response rate increased from 0% to 8%. Based on the greater overall stability of annotation performance and output validity, a temperature of 0.0 was used for all subsequent analyses. Complete results are presented in Supplementary Table S2 and Supplementary Figure S1.
Model selection
Figure 1 summarizes the performance and inference efficiency of the nine candidate LLMs across the four symptom-specific development sets of 250 reports each. F-scores varied across symptoms and models, with the greatest differences observed for diarrhea and dysuria. For nausea, gemma2:27b achieved the highest F-score of 0.991 (95% CI, 0.976–1.000), with a median inference time of 0.299 s per report (IQR, 0.235–0.350). For vomiting, mistral-large:123b achieved the highest F-score of 0.964 (95% CI, 0.929–0.992), marginally exceeding llama3.3:70b with 0.964 (95% CI, 0.926–0.992). However, mistral-large:123b required a longer median inference time per report than llama3.3:70b (1.620 s, IQR, 1.313–2.110 versus 0.880 s, IQR 0.707–1.079). For diarrhea, the two leading models were llama3.3:70b, with the highest F-score of 0.930 (95% CI, 0.857–0.986), and mistral-small:22b, with an F-score of 0.925 (95% CI, 0.848–0.984). The latter was faster, with a median inference time of 0.271 s per report (IQR, 0.231–0.357), compared with 0.890 s (IQR, 0.707–1.089) for llama3.3:70b. Dysuria represented the most challenging symptom, with lower F-scores and wider confidence intervals across models. Here, llama3.3:70b achieved the highest F-score of 0.897 (95% CI, 0.741–1.000), followed closely by gemma2:27b with 0.889 (95% CI, 0.727–1.000). Despite its slightly lower F-score, gemma2:27b had a shorter median inference time per report than llama3.3:70b (0.282 s, IQR, 0.233–0.339 versus 0.751 s, IQR, 0.641–1.075).
Fig. 1 Development-set performance and inference efficiency of the candidate LLMs. Results are shown for the symptom-specific development sets of 250 reports for nausea (A), vomiting (B), diarrhea (C), and dysuria (D). Blue bars indicate observed F-scores with error bars representing patient-level bootstrap 95% confidence intervals. Gray bars indicate median steady-state inference time per report, with error bars representing the first and third quartiles. Models are ordered by decreasing F-score within each symptom.
Independent validation
Based on the predefined selection procedure, gemma2:27b for nausea, mistral-large:123b for vomiting, and llama3.3:70b for diarrhea and dysuria were applied to the corresponding symptom-specific validation sets of 750 reports each. Results are summarized in Table 2; Fig. 2. Final performance varied across symptoms. The highest F-scores were observed for nausea (0.979; 95% CI, 0.966–0.989) and vomiting (0.985; 95% CI, 0.972–0.995), both characterized by high sensitivity, specificity, positive predictive value, and negative predictive value. F-scores were lower for diarrhea (0.814; 95% CI, 0.749–0.868) and dysuria (0.824; 95% CI, 0.734–0.896). For both symptoms this reflected a reduced positive predictive value despite high specificity and negative predictive value. Median inference times per report ranged from 0.298 s (IQR 0.247–0.345) for nausea to 1.653 s (IQR 1.315–2.110) for vomiting, reflecting differences between the selected model architectures. The selected LLMs outperformed the rule-based baseline for nausea (F-score, 0.979 versus 0.724; paired difference, 0.255) and vomiting (0.985 versus 0.913; paired difference, 0.073). No clear difference was observed for diarrhea (0.814 versus 0.853; paired difference, − 0.039), while dysuria nearly favored the LLM despite the paired confidence interval narrowly including zero (0.824 versus 0.705; paired difference, 0.119) (Table 2; Fig. 2).
Table 2 Performance of the selected LLMs and rule-based baseline in the independent symptom-specific validation sets comprising 750 reports each.
| Nausea gemma2:27b | Vomiting mistral-large:123b | Diarrhea llama3.3:70b | Dysuria llama3.3:70b | ||
|---|---|---|---|---|---|
| Accuracy | LLM | 0.981 (0.971–0.991) | 0.992 (0.985–0.997) | 0.951 (0.935–0.965) | 0.976 (0.964–0.987) |
| Rule | 0.801 (0.773–0.829) | 0.953 (0.937–0.969) | 0.960 (0.945–0.973) | 0.965 (0.952–0.979) | |
| Sensitivity | LLM | 0.991 (0.979–1.000) | 1.000 (1.000–1.000) | 0.810 (0.732–0.879) | 0.977 (0.919–1.000) |
| Rule | 0.604 (0.549–0.656) | 0.910 (0.869–0.948) | 0.870 (0.802–0.933) | 0.721 (0.577–0.854) | |
| Specificity | LLM | 0.974 (0.959–0.988) | 0.989 (0.979–0.996) | 0.972 (0.959–0.983) | 0.976 (0.963–0.986) |
| Rule | 0.951 (0.930–0.971) | 0.969 (0.953–0.984) | 0.974 (0.960–0.986) | 0.980 (0.969–0.990) | |
| PPV | LLM | 0.967 (0.946–0.984) | 0.971 (0.945–0.991) | 0.818 (0.739–0.889) | 0.712 (0.589–0.821) |
| Rule | 0.903 (0.861–0.941) | 0.915 (0.874–0.954) | 0.837 (0.763–0.904) | 0.689 (0.545–0.821) | |
| NPV | LLM | 0.993 (0.983–1.000) | 1.000 (1.000–1.000) | 0.971 (0.958–0.983) | 0.999 (0.996–1.000) |
| Rule | 0.760 (0.725–0.797) | 0.967 (0.952–0.981) | 0.980 (0.969–0.989) | 0.983 (0.973–0.992) | |
| F-score | LLM | 0.979 (0.966–0.989) | 0.985 (0.972–0.995) | 0.814 (0.749–0.868) | 0.824 (0.734–0.896) |
| Rule | 0.724 (0.679–0.764) | 0.913 (0.882–0.941) | 0.853 (0.798–0.902) | 0.705 (0.582–0.808) | |
| Inference time/report (s) | LLM | 0.298 (0.247–0.345) | 1.653 (1.315–2.110) | 0.887 (0.688–1.073) | 0.889 (0.706–1.076) |
- Performance values are reported as point estimates with patient-level bootstrap 95% confidence intervals; inference times are reported as medians with interquartile ranges. PPV: positive predictive value, NPV: negative predictive value.
Fig. 2 Validation-set F-scores of the selected symptom-specific LLMs and rule-based baseline. Each independent symptom-specific validation set comprised 750 reports. A F1-scores with patient-level bootstrap 95% confidence intervals. B Paired differences in F1-score between the selected LLM and rule-based baseline, with paired bootstrap 95% confidence intervals. Positive values favor the selected LLM; the dashed vertical line indicates no difference.
Analysis of discrepant cases
Cases with disagreement between the LLM output and the reference annotation were systematically reviewed and categorized according to the underlying error type, as summarized in Table 3. Discrepancy patterns varied across symptoms. For nausea, the most frequent categories were symptoms not mentioned in the source text and inconsistent documentation. For vomiting, inconsistent documentation was the most frequent category. In contrast, for diarrhea and dysuria, the most frequent category was diagnostic criteria not met. Additional categories included fluctuating symptoms and missed symptom mentions. Five original reference annotations were retrospectively identified as incorrect during post hoc consensus review. Overall, discrepancies reflected both model errors and challenges related to temporal variation, inconsistent clinical documentation, application of the predefined symptom definitions, and occasional inaccuracies in the original reference standard.
Table 3 Consensus-based categorization of discrepancies between LLM predictions and reference annotations in the independent validation sets.
| Error Type | Nausea gemma2:27b | Vomiting mistral-large:123b | Diarrhea llama3.3:70b | Dysuria llama3.3:70b | |
|---|---|---|---|---|---|
| FP | Symptom not mentioned | 6 | 0 | 3 | 5 |
| FP | Diagnostic criteria not met | 0 | 1 | 13 | 11 |
| FN | Fluctuating Symptom | 2 | 0 | 10 | 0 |
| FN | Symptom missed | 0 | 0 | 4 | 0 |
| FP FN | Inconsistent documentation | 6 | 3 | 4 | 2 |
| FP FN | Reference Error | 0 | 2 | 3 | 0 |
| Total | 14 | 6 | 37 | 18 |
- FP: false positive, FN: false negative. “Reference Error” indicates an incorrect reference annotation identified retrospectively during post hoc consensus review.
Discussion
This study supports the feasibility of using locally deployed open-weight LLMs to annotate symptoms in unstructured German clinical documentation. The proposed workflow combined symptom-specific model screening with independent validation and comparison against a rule-based baseline, while considering both annotation performance and inference efficiency.
Interpretation of annotation agreement
Human annotation of symptoms in unstructured clinical text requires interpretation and may therefore be subject to variability in the resulting labels. Accordingly, agreement between LLM outputs and reference annotations should be interpreted considering the strengths and limitations of both approaches. Our consensus review revealed that discrepancies arose from LLM errors (e.g., false-positives and false-negatives), fluctuating or inconsistent clinical documentation, and five errors in the original reference annotations. Moreover, higher F-scores for nausea and vomiting than for diarrhea and dysuria may reflect differences in operational definitions and contextual ambiguity. These findings reflect the broader variability in how clinicians interpret and classify clinical information. Dindo et al. found that complication recording by surgical residents remained inconsistent despite standardized classification and targeted training. Conversely, Staubli et al. reported high agreement between ChatGPT and human Clavien–Dindo classifications, together with consistent results across repeated evaluations. Similarly, Kang et al. reported consistent and standardized LLM-based annotation with comparable accuracy while reducing physician workload by more than 90% relative to manual review. Taken together, discrepancies between LLM outputs and human reference annotations may reflect not only LLM errors but also differences in clinical interpretation and limitations of the reference standard. Although both approaches remain susceptible to error, standardized LLM-based annotation may improve consistency and scalability.
Temperature
In our nausea-based experiments, higher temperatures increased variability in annotation performance and the frequency of invalid responses, although the magnitude of these effects varied across LLMs. Stability was not determined by LLM size alone, as performance deteriorated at higher temperatures for different sized LLMs. In contrast, a temperature of 0.0 produced the most reproducible outputs across all LLMs in our setting. These observations align closely with Gilardi et al. and Alizadeh et al., who reported improved consistency and agreement at lower temperatures without compromising accuracy in nonclinical text-classification tasks. Drawing on published research, extensive practical experience, and discussions with researchers, Törnberg proposed a broader best-practice framework recommending a low temperature for data annotation to ensure deterministic and reproducible outputs. To our knowledge, no prior study has systematically evaluated temperature effects across multiple locally deployed open-weight LLMs for clinical symptom annotation. Our findings therefore extend existing evidence to this specific domain and support a temperature of 0.0 as the most reproducible setting for model screening and validation within our pipeline.
LLM size and computational trade-offs
In our study, LLM size strongly influenced inference time but did not uniformly determine annotation performance. Although larger LLMs often achieved high F-scores, the relationship between annotation performance and inference time varied by symptom. This pattern is consistent with Nowak et al., who evaluated open-weight LLMs ranging from approximately 3.8B to 405B parameters for zero-shot information extraction from radiology reports and found increasing performance with size, but diminishing gains and substantially longer inference times. Similar performance–computation trade-offs have been reported for structuring pathology reports. In our study, Ollama-reported GPU-memory allocation ranged from 2.63 to 112.70 GB and exceeded the quantized model size for several LLMs (Supplementary Table S1). Moreover, mid-sized LLMs either achieved the highest development-set F₁-score or their performance overlapped with that of the top-performing LLM. They generally also required substantially shorter median inference times, making them practical alternatives when larger LLMs cannot be hosted locally. However, neither these prior studies nor our analysis comprehensively evaluated computational requirements beyond inference time (e.g., energy consumption or monetary costs).
Comparison with rule-based and conventional NLP approaches
Our comparison with the rule-based baseline showed that the added value of LLM-based annotation was symptom-specific, with clear advantages for nausea and vomiting. For dysuria, the point estimate favored the LLM and the paired confidence interval narrowly included zero, whereas no clear difference was observed for diarrhea. In the literature, high-performing zero-shot LLMs outperformed rule-based systems for variably expressed radiological findings, whereas supervised encoder models became competitive when sufficient annotated training data were available. Fine-tuned encoder models likewise achieved useful symptom-extraction performance but required at least 800 annotated training samples, with performance varying across symptoms, class imbalance, and missing documentation. Similarly, a symptom-specific comparison found that an LLM generally outperformed a conventional classifier, but that the classifier performed better for one target symptom. Taken together, these studies indicate that the relative performance of different clinical NLP approaches depends on the target concept, the availability of task-specific training data, and the extent of contextual interpretation required. The approach should therefore be selected and validated for the target concept rather than assuming that LLMs invariably provide added value.
Toward reproducible pipelines
The observed variation across symptoms, LLMs, and inference settings underscores the need for a stepwise and reproducible workflow rather than an isolated prompting task. Although our workflow was developed for adaptation to other settings, its application requires local configuration and validation. In line with previous methodological guidance, adaptation should begin by clearly defining the target concept, source data, and documentation context. Second, predefined operational rules should be applied to create expert reference annotations for development and independent validation. Third, our workflow implements pragmatic symptom-specific screening by comparing candidate LLMs on dedicated development sets. Additionally, previous work indicates that LLM performance and the optimal prompting strategy may vary across annotation targets. All configuration choices should therefore be optimized only on this development data to preserve test-set independence. Fourth, the resulting configuration should be evaluated on independent validation data and compared with a task-appropriate rule-based baseline to assess its relative added value. Fifth, aggregate performance metrics should be complemented by systematic analysis of discrepant cases. In our analysis, this distinguished LLM errors from discrepancies related to operational annotation rules, ambigious documentation, and errors in the reference standard. Sixth, when extracted variables are intended for downstream ML, their impact requires separate evaluation. Recent studies have integrated LLM-derived symptom information into appendicitis and cardiovascular risk-prediction pipelines, a step not evaluated in our study. Together, these steps define a reproducible approach to the task-specific selection and validation of locally deployed open-weight LLMs for clinical free-text annotation. The accompanying open-source implementation makes the workflow transparent and adaptable, although performance must be re-evaluated for each target concept and documentation setting.
Limitations
This study has several limitations. First, this single-center analysis was limited to German emergency department reports from patients presenting with abdominal pain, which restricts generalizability to other institutions, clinical settings, patient populations, or languages. Second, annotation was restricted to four binary symptoms. Performance varied across these symptoms and may not generalize to other clinical concepts or more complex tasks, including multilabel classification and temporal reasoning. Third, the reference may be subject to annotator variability because reports were not systematically annotated independently and separate initial ratings were not retained. Consequently, formal inter-rater agreement could not be calculated. Moreover, discrepancy categories were developed post hoc and assigned by joint consensus rather than independent coding, making the error analysis exploratory. Fourth, the evaluation was focused on zero-shot prompting with fixed inference parameters and did not assess few-shot prompting or fine-tuning. By design, our pragmatic model-screening approach was not a comprehensive LLM benchmark and does not establish a general ranking across model architectures. Fifth, despite fixed inference settings and exact model digests, complete reproducibility across systems cannot be guaranteed because outputs may still vary across hardware and inference software environments. Sixth, no external validation on an independent dataset was performed. Finally, the hardware requirements of the larger evaluated LLMs may limit local deployment in resource-constrained environments.
Conclusions
We developed and evaluated an open-source pipeline for the task-specific selection and validation of locally deployed open-weight LLMs for annotating four binary symptoms in German emergency department reports. Annotation performance varied by LLM, inference configuration, and target symptom, supporting task-specific development, independent validation, and comparison with simpler baselines. The accompanying open-source implementation makes the workflow transparent and adaptable, although performance must be re-evaluated for each target concept and documentation setting. How mere annotation quality affects downstream ML performance remains to be investigated. By providing a reproducible approach to extracting predefined variables from clinical free text, this work represents a focused step toward unlocking the wealth of information embedded in unstructured clinical documentation—a key objective in the field of SDS.
Methods
Study cohort and clinical reports
This retrospective exploratory study analyzed reports of patients presenting to the emergency department at the University Hospital Bonn in 2023 with the chief complaint “abdominal pain in adults”. Records were screened until the target sample of 1,100 reports was reached. Inclusion required an emergency report documenting atraumatic abdominal pain that contained a medical history, was electronically signed, and included a laboratory block as a pragmatic surrogate for document completeness. Only one index presentation per patient was retained. Reports were manually extracted from the electronic health record system as PDF files (Fig. 3A). The reports were semi-structured and typically contained a clinic header, triage information, anamnesis, medication lists, clinical findings, laboratory results, diagnoses, and procedural or disposition information. Only the header and the laboratory results existed in a structured form, whereas all other information was documented in free text. Documentation originated from different clinical departments contributing to emergency department care, including general surgery, trauma surgery, internal medicine, and urology, resulting in substantial heterogeneity across clinicians. The study was conducted in accordance with the Declaration of Helsinki and was approved by the Ethics Committee of the University Hospital Bonn (reference number: 163/23-EP). Due to the retrospective study design, the requirement for individual informed consent was waived according to local regulations.
Fig. 3 Analysis Pipeline. A Data preparation: emergency department reports were extracted from the electronic health record (EHR), converted from PDF to UTF-8 plain text, and linked with binary expert reference annotations. B Prompt and configuration: an initial set of 100 reports was used for exploratory zero-shot prompt development and temperature testing across nine LLMs, 11 temperature settings, and ten repeated runs. Prompts and temperature were subsequently fixed. C LLM screening: for each symptom, nine LLMs were evaluated on a stratified development set of 250 reports. The LLM with the highest F-score was selected, with inference time used as a tiebreaker. D Independent validation: the selected symptom-specific LLM and a predefined negation-aware rule-based baseline were evaluated on the corresponding validation set of 750 reports. Evaluation included performance metrics, patient-level bootstrap 95% confidence intervals, paired baseline comparison, inference efficiency, and consensus-based error analysis.
Reference annotation
Four common symptoms associated with acute abdominal pain (nausea, vomiting, diarrhea, and dysuria) were annotated using binary labels (“yes” / “no”) to establish the reference dataset (Fig. 3A). Primary annotation was performed by a medical doctoral student under the supervision of two board-certified surgeons, who also annotated subsets of the reports. Uncertain cases were jointly reviewed and resolved through discussion and consensus. The reference annotations were completed before LLM inference and without access to model predictions. Before annotation, decision rules were defined for all symptoms and did not change throughout the process. Symptoms were considered positive if documented as part of the current clinical presentation, even if they had resolved shortly before assessment. Symptoms referring exclusively to unrelated past episodes were annotated as negative. Negated, uncertain, or ambiguous symptom descriptions were annotated as negative. Dysuria was defined as pain or discomfort during urination and diarrhea was defined according to the World Health Organization definition.
Pipeline
The PDF files were converted to UTF-8 plain text, and the relevant clinical section was isolated using two document-specific markers specified in the configuration file (Fig. 3A, Supplementary Methods S1). Texts were presented to nine locally deployed open-weight LLMs with different parameter sizes using a zero-shot prompting strategy in German (Table 4, Supplementary Methods S2, Supplementary Table S1). Model responses were converted into binary labels using a predefined deterministic parsing rule (Supplementary Methods S3). A separate exploration set of 100 reports was used for prompt formulation and temperature testing and was excluded from subsequent LLM screening and validation (Fig. 3B). Symptom-specific prompt wording was iteratively refined on the exploration set, guided by the achieved F-score. Using nausea, the final prompt was evaluated for each LLM across 11 temperatures. Output consistency was assessed across 10 iterations per temperature and summarized using median and interquartile range (IQR). Based on these results, a fixed temperature was selected for subsequent analyses. For each symptom, the remaining 1,000 reports were randomly divided into stratified development (n = 250) and validation sets (n = 750) using a fixed random seed (Fig. 3C–D, Supplementary Methods S4). All nine LLMs were applied once to each symptom-specific development set using the frozen prompts and fixed temperature (Fig. 3C). For each symptom, the LLM with the highest F-score was selected and shorter inference time was used as the tiebreaker (Fig. 3C, Supplementary Methods S5). The selected LLM and a predefined negation-aware rule-based baseline were then applied to the corresponding independent validation set of 750 reports (Fig. 3D). Validation performance was summarized using the predefined evaluation metrics and paired comparisons with the rule-based baseline. Cases with discrepancies between LLM predictions and reference annotations were reviewed by the same three annotators using the source text and model output and grouped into post hoc discrepancy categories by consensus.
Table 4 Overview of the evaluated LLMs used in this study. All models were obtained from publicly available Ollama releases using the default published quantized variants.
| Model | Developer | Parameters | Quantization | Maximum Context Length | Model Size (GB) |
|---|---|---|---|---|---|
| gemma2:9b | 9.2B | Q4_0 | 8,192 | 5.4 | |
| gemma2:27b | 27.2B | Q4_0 | 8,192 | 15.6 | |
| llama3.1:8b | Meta | 8.0B | Q4_K_M | 131,072 | 4.9 |
| llama3.1:70b | Meta | 70.6B | Q4_K_M | 131,072 | 42.5 |
| llama3.3:70b | Meta | 70.6B | Q4_K_M | 131,072 | 42.5 |
| mistral-small:22b | Mistral AI | 22.2B | Q4_0 | 131,072 | 12.6 |
| mistral-large:123b | Mistral AI | 122.6B | Q4_K_M | 131,072 | 73.2 |
| nemotron-mini:4b | NVIDIA | 4.2B | Q4_K_M | 4,096 | 2.7 |
| nemotron:70b | NVIDIA | 70.6B | Q4_K_M | 131,072 | 42.5 |
Rule-based base and statistical analysis
A deterministic negation-aware rule-based baseline used symptom-specific German terms and spelling variants. Mentions were classified as positive when no negation occurred within a five-word context and diarrhea additionally incorporated the WHO definition. The rules were fixed before any LLM inferencing. LLM and baseline performance was assessed using accuracy, sensitivity, specificity, positive and negative predictive values, and F-score. Patient-level 95% confidence intervals were calculated using 2,000 bootstrap resamples with a fixed random seed. Identical resamples were used across LLMs and for the paired comparison between the selected LLM and baseline.
Software and hardware
All preprocessing, downstream analysis, and LLM inference were performed locally within the secure institutional infrastructure of the University Hospital Bonn. Reference annotation and data management were performed using Excel (version 16.93, Microsoft, Redmond, USA). A study-specific analysis pipeline was developed in Python (version 3.14.4, Python Software Foundation, Wilmington, USA) using Visual Studio Code (version 1.135.0, Microsoft, Redmond, USA) to implement PDF text extraction, data splitting, LLM inference, deterministic response parsing, rule-based baseline classification, and statistical evaluation. The source code is available through the project’s GitHub repository (https://github.com/boster-hub/llm-surgical-free-text-annotation) and archived in Zenodo. The pipeline architecture is reusable, whereas document markers, target concepts, prompts, annotation rules, reference labels, rule-based patterns, and local server settings require context-specific configuration and validation. The LLMs were served locally using Ollama (version 0.31.2, Ollama Inc., Palo Alto, USA) and accessed through the Ollama Python package (version 0.6.2). Inference was restricted to a single NVIDIA B200 GPU with 180 GB HBM3e on an institutional DGX B200 system equipped with two Intel Xeon Platinum 8570 processors and 2 TB RAM. The server operated on Ubuntu 24.04.3 LTS with CUDA 12.8 and NVIDIA driver 570.195.03.
Data availability
The datasets generated and/or analyzed during the current study are not publicly available due to the inclusion of sensitive patient information but are available from the corresponding author on reasonable request and subject to institutional approval. The source code used for preprocessing, prompting, and benchmarking is publicly available at: https://github.com/boster-hub/llm-surgical-free-text-annotation.
Abbreviations
IQR: Interquartile range LLM: Large language model ML: Machine learning NLP: Natural language processing SDS: Surgical data science
References
- [1] Maier-Hein, L. et al. Surgical data science for next-generation interventions. Nat. Biomed. Eng. 1, 691–696. https://doi.org/10.1038/s41551-017-0132-7 (2017).
- [2] Rajkomar, A., Dean, J. & Kohane, I. Machine Learning in Medicine. N Engl. J. Med. 380, 1347–1358. https://doi.org/10.1056/NEJMra1814259 (2019).
- [3] Henn, J., Buness, A., Schmid, M., Kalff, J. C. & Matthaei, H. Machine learning to guide clinical decision-making in abdominal surgery—a systematic literature review. Langenbecks Arch. Surg. 1–11. https://doi.org/10.1007/s00423-021-02348-w (2021).
- [4] Joukes, E., Abu-Hanna, A., Cornet, R. & De Keizer, N. Time Spent on Dedicated Patient Care and Documentation Tasks Before and After the Introduction of a Structured and Standardized Electronic Health Record. Appl. Clin. Inf. 09, 046–53. https://doi.org/10.1055/s-0037-1615747 (2018).
- [5] Loftus, T. J. et al. Artificial Intelligence–enabled Decision Support in Surgery: State-of-the-art and Future Directions. Ann. Surg. 278, 51–58. https://doi.org/10.1097/SLA.0000000000005853 (2023).
- [6] Maier-Hein, L. et al. Surgical Data Science: A Consensus Perspective. (2018). https://doi.org/10.48550/ARXIV.1806.03184
- [7] Sheikhalishahi, S. et al. Natural Language Processing of Clinical Notes on Chronic Diseases: Systematic Review. JMIR Med. Inf. 7, e12239. https://doi.org/10.2196/12239 (2019).
- [8] Goel, A. et al. LLMs Accelerate Annotation for Medical Information Extraction. (2023). https://doi.org/10.48550/ARXIV.2312.02296
- [9] Huang, J. et al. A critical assessment of using ChatGPT for extracting structured data from clinical notes. Npj Digit. Med. 7, 106. https://doi.org/10.1038/s41746-024-01079-8 (2024).
- [10] Khan, A. Z. Extraction of Normalized Symptom Mentions From Clinical Narratives Using Large Language Models. AMIA Annu. Symp. Proc. AMIA Symp. 2024, 600–609 (2024).
- [11] Nowak, S. et al. Privacy-ensuring Open-weights Large Language Models Are Competitive with Closed-weights GPT-4o in Extracting Chest Radiography Findings from Free-Text Reports. Radiology 314, e240895. https://doi.org/10.1148/radiol.240895 (2025).
- [12] Grothey, B. et al. Comprehensive testing of large language models for extraction of structured data in pathology. Commun. Med. 5, 96. https://doi.org/10.1038/s43856-025-00808-8 (2025).
- [13] Kang, Y-J. et al. Large Language Model Versus Manual Review for Clinical Data Curation in Breast Cancer: Retrospective Comparative Study. JMIR Med. Inf. 13, e73605–e73605. https://doi.org/10.2196/73605 (2025).
- [14] Dindo, D., Hahnloser, D. & Clavien, P-A. Quality Assessment in Surgery: Riding a Lame Horse. Ann. Surg. 251, 766–771. https://doi.org/10.1097/SLA.0b013e3181d0d211 (2010).
- [15] Staubli, S. M. et al. Decoding the Clavien-Dindo Classification: Artificial Intelligence (AI) as a Novel Tool to Grade Postoperative Complications. Ann. Surg. 281, 273–279. https://doi.org/10.1097/SLA.0000000000006399 (2025).
- [16] Gilardi, F., Alizadeh, M. & Kubli, M. ChatGPT outperforms crowd workers for text-annotation tasks. Proc. Natl. Acad. Sci. 120, e2305016120. https://doi.org/10.1073/pnas.2305016120 (2023).
- [17] Alizadeh, M. et al. Open-source LLMs for text annotation: a practical guide for model setting and fine-tuning. J. Comput. Soc. Sci. 8, 17. https://doi.org/10.1007/s42001-024-00345-9 (2025).
- [18] Törnberg, P. Best Practices for Text Annotation with Large Language Models. Sociologica 18, 67–85. https://doi.org/10.6092/ISSN.1971-8853/19461 (2024).
- [19] Spiero, I. et al. Comparison of local large language models for extraction of signs and symptoms data from electronic health records. PLOS One ;21:e0350625. https://doi.org/10.1371/journal.pone.0350625. (2026).
- [20] Wiest, I. C. et al. A software pipeline for medical information extraction with large language models, open source and suitable for oncology. Npj Precis Oncol. 9, 313. https://doi.org/10.1038/s41698-025-01103-4 (2025).
- [21] Verhees, F. G. et al. clickBrick Prompt Engineering: Optimizing Large Language Model Performance in Clinical Psychiatry. (2025). https://doi.org/10.1101/2025.06.28.25330267
- [22] Mese, I. et al. Reporting checklist for foundation and large language models in medical research (REFINE): an international consensus guideline. Diagn. Interv Radiol. https://doi.org/10.4274/dir.2026.263812 (2026).
- [23] Yang, H. et al. LLM-Augmented Symptom Analysis for Cardiovascular Disease Risk Prediction: A Clinical NLP Approach. In: 2025 19th International Conference on Complex Medical Engineering (CME). Lanzhou, China: IEEE; pp. 176–81. (2025). https://doi.org/10.1109/CME67420.2025.11239360
- [24] Schipper, A. et al. Large Language Model Automated Extraction of Clinical Signs and Symptoms From Emergency Department Reports for Machine Learning Prediction Models: Development and Validation Study. JMIR Med. Inf. 14, e81500–e81500. https://doi.org/10.2196/81500 (2026).
- [25] World Health Organization. Diarrhoeal disease. Factsheet. https://www.who.int/news-room/fact-sheets/detail/diarrhoeal-disease. Accessed 28 May 2026.
- [26] BOSTER - Bonn Surgical Technology Center. boster-hub/llm-surgical-free-text-annotation: Version 2.0.0 – Reproducible Python pipeline. (2026). https://doi.org/10.5281/ZENODO.22250324
Funding
Open Access funding enabled and organized by Projekt DEAL. The Ministry of Economic Affairs, Industry, Climate Action, and Energy of the State of North Rhine-Westphalia (Project: Innovative Secure Medical Campus) partly funded this work.
Contributions
Conceptualization: JH, AS, PF, HM; Data curation: JH, AS, JR, IG; Formal analysis: JH, AS, DS, PF; Funding acquisition: HM, JCK, JA, PF; Investigation: JH, AS; Methodology: JH, AS, PF, DS, BW; Project administration: JH, HM, JCK; Resources: DS, PF; Software: JH, AS, PF, DS; Supervision: JA, IG, BW, JCK, HM; Validation: DS, PF; Visualization: JH, AS, PF; Writing – original draft: JH, AS; Writing – review and editing: all authors. All authors reviewed, edited, and approved the final version of the manuscript. JH and AS contributed equally to this work and share first authorship.
Ethics declarations
Competing interests
The authors declare no competing interests.
Ethics approval and consent to participate
The study was conducted in accordance with the Declaration of Helsinki and approved by the Ethics Committee of the University Hospital Bonn (163/23-EP). No dedicated informed consent was required for this retrospective study according to local legislation.
Generative AI and AI-assisted technologies in the manuscript preparation process
During the preparation of this work the authors used ChatGPT 5.3 (OpenAI, San Francisco, USA) to assist with language editing, refinement of scientific phrasing, and structuring of the manuscript. After using this tool, the authors reviewed and edited the content as needed and take full responsibility for the content of the published article.
Supplementary Information
Below is the link to the electronic supplementary material.