SPE-ECG: An Ontology-Guided Knowledge Representation Framework for Enhancing LLM-Based Code Generation
Talha Mahmood, Muhammad Tanvir Afzal, Ahmad Sami Al-Shamayleh, Ghulam Mustafa, Isabel De la Torre Díez, Lázaro Javier Hernández Rodríguez, Pablo Herrero García
Key points
From the paper's conclusion- We propose SPE-ECG (Structured Prompt Engineering for Enhanced Code Generation), a transparent, rule-based pipeline that converts unstructured domain text into a JSON prompt using text cleaning, part-of-speech tagging, bigram matching, and hand-built domain dictionaries, without fine-tuning any model.
Abstract
Large Language Models (LLMs) can translate natural-language instructions into code, but when the input is unstructured clinical protocol text, the generated code may omit doses, monitoring intervals, or safety thresholds that the text states. Such omissions matter because they can propagate into software that supports clinical monitoring. We propose SPE-ECG (Structured Prompt Engineering for Enhanced Code Generation), a transparent, rule-based pipeline that converts unstructured domain text into a JSON prompt using text cleaning, part-of-speech tagging, bigram matching, and hand-built domain dictionaries, without fine-tuning any model. In a case study of 43 rheumatoid arthritis DMARD monitoring protocols, we compared raw and structured prompts on three LLMs (GPT-3.5, LLaMA 2, and Gemma), scoring the generated Python code using version 3.15.1 with BLEU against the raw-prompt code of the other two models. Mean BLEU rose for all three models (relative gains of 55.1%, 32.5%, and 19.9%); the paired differences were significant for GPT-3.5 and LLaMA 2 but not, after correction for multiple comparisons, for Gemma. These results suggest that lightweight input structuring can change how closely different models’ outputs agree, and that it could serve as a low-cost, auditable preparation step for protocol-to-code tools built on free or open models. BLEU does not measure correctness, no ablation or state-of-the-art baseline was run, and clinical validation is required before any use.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- TEA-Bench-BR: Can Coding Agents Turn a Branching Clinical Specification into Correct Code?arXiv · 2026
- Enhanced LLM-supported instructions for medication use through retrieval-augmented generationComputers in Biology and Medicine · 2025
- TrialCode Agent: LLM-Assisted Clinical Code-Set Construction for Trial EmulationmedRxiv · 2026
- Exploratory Implementation and Feasibility Report of CLASS (Clinical LLM Abstraction & Structuring System), A Large Language Model Pipeline for Extracting Unstructured Data From Clinical Notes.Journal of medical systems · 2026
- Comparison of Large Language Model‐Based Systems and Prompt Engineering for Internal Medicine Clinical Pharmacy CasesJACCP JOURNAL OF THE AMERICAN COLLEGE OF CLINICAL PHARMACY · 2026
- Developing an open-source framework for LLM evaluation of patients using EHR clinical documentation; performance of LLMs relative to medical professionalsmedRxiv · 2026