Korean J Abdom Radiol > Volume 8(1); 2025 > Article
Lee and Shin: Prompt Engineering for Large Language Models: A Primer for Radiologists

Abstract

Among artificial intelligence applications, large language models (LLMs) like ChatGPT have shown promising potential in streamlining workflows and facilitating research. This review article aims to provide basics and examples of prompt engineering in optimizing interactions with LLMs for radiologists, promoting precise, relevant, and useful LLM outputs.

Introduction

Large language models (LLMs), such as ChatGPT, equipped with advanced natural language processing capabilities, offer a unique avenue for enhancing clinical practices. Prompt engineering is crucial for optimizing the performance of LLMs. Prompt engineering refers to the practice of meticulously designing natural language queries that steer the model to produce the desired output.[1]
Prompt engineering i s fundamentally about communication, how to converse with an AI in its language. It may be likened to computer programming wherein the difference is that the "code" is natural language, and the output is not just any text but one that fulfills a specific task or answers a particular question. One key difference to programming, however, is the responsiveness of LLMs to input prompts; slight variations in how a prompt is structured can lead to significantly different outcomes. This sensitivity, often referred to as "prompt brittleness," highlights the importance of syntax and semantics of the prompts given to LLMs.[1] Just as the results from a search engine can vary significantly with minor adjustments in search terms, despite the terms conveying essentially the same meaning, so too can the outputs of LLMs vary based on the subtle intricacies of the input prompt (Fig. 1).
Prompt brittleness turns prompt engineering into both a science, with its principles and patterns, and an art, requiring intuition and creativity to master; akin to the practice of medicine. Exploring prompt engineering shows it is often more about art than science, with success heavily depending on experience and intuition.
The goal of this section is to introduce the concept of prompt engineering and make it accessible and practical for radiologists. Although the following material introduces components of effective prompts and best practices, it is critical to remember that prompt engineering is a skill that improves with trial-and-error. Getting hands-on experience with prompt engineering for a task is crucial to become proficient. As an important sidenote, because the following principles are learned from experience with the GPT family by OpenAI, they may not apply equally to other LLMs.

Best Practices for Prompt Engineering [2-4]

1) Be specific with clear instructions: Ensure your instructions are straightforward and leave little room for interpretation. Be explicit about what you want. If you seek concise answers, specify the desired length (e.g. three sentences, one paragraph, or 200 words, etc.) or ask for brief replies. Similarly, if you're looking for expert-level writing, state that explicitly. This helps minimize the guesswork for the model (Fig. 2).
2) Persona and Perspective: Encourage the model to adopt a specific persona or tone if that suits your task (e.g. “You are an experienced radiologist in abdominal imaging.”). This could range from a scholarly tone for academic inquiries to a more casual one for everyday questions. Likewise, the level and role of the listener can be specified (e.g. “Simplify this for explanation to a patient.”) (Fig. 3).
3) Use of Delimiters and Syntax: Clearly mark different sections or types of information within your prompt using delimiters or clear textual separation. This helps the model distinguish between instructions, reference content, and the questions themselves. Even simple ones, such as two consecutive hyphens (“--"), are effective. This might be because a large portion of LLMs training data are structured text such as HTML and JSON (Fig. 4) [5].
4) Break down complex tasks into subtasks: For complex tasks, break them down into simpler, manageable sub-tasks. Provide instructions step by step or ask the model to follow a sequence of operations. This method reduces errors and enhances the quality of the output (Fig. 5) [5].
5) Repetition and Order: Don’t hesitate to repeat critical instructions or use both instructions and cues to emphasize what you need. The placement of your instructions (before or after your main content) can also significantly affect the model's responses. Therefore, experiment with various orders to achieve the best results (Fig. 4).
6) Provide Options to avoid hallucinations: Giving the model an "out," such as the option to reply "I don't know" or "not found," can prevent it from making up answers (hallucination) or straying too far from factual accuracy (Fig. 4).
7) Reference Material: Supplying reference text or asking the model to use specific sources can steer responses away from fabrications, especially on esoteric topics. This approach grounds the model’s answers in provided or known content and reduces hallucination (Fig. 4).
8) Use of External Tools: Augment the model's capabilities by incorporating outputs from other tools for tasks that require specific knowledge, precise calculations, or data retrieval [6, 7]. This can include using code execution for mathematical operations or application programming interface (API) calls (Fig. 6).
9) Allow for ‘Thinking’ Time: Encourage the model to present a "chain of thought" or reasoning process before delivering its final answer [8]. This can improve the accuracy and depth of responses, especially for complex queries (Fig. 7).
10) Evaluation and Testing: Systematically test changes to your prompts to ensure they consistently improve performance. Evaluate against a set of criteria or a "gold-standard" to verify the effectiveness of your modifications. To accomplish this, it is necessary to separately prepare a validation set for fair comparison of various prompts.

Advanced Prompting Techniques

There are more complex and nuanced prompting techniques, but most of them require multi-turn prompting, usage of programming, or are applicable to very specific scenarios. Most of these are beyond the scope of this review, so in this section, we will introduce two important and easily implementable prompting techniques: incontext learning (ICL) and self consistency.

1) In-Context Learning (also known as few-shot or zero-shot learning)

ICL refers to an LLM’s capability to learn from the prompt without changing the model weights. ICL capitalizes on the ability of LLMs to understand and learn from the concatenation of training data examples provided through the prompt.[1] This enables the user to use the LLM in various natural language processing tasks without the need to train a specialized model. In fact, it is so effective that in some scenarios GPT-4 with 10-shots (examples) shows similar accuracy to a 7900 example-trained BERT model.[9] (Fig. 8)

## Mechanics of ICL

ICL operates through two main mechanisms: task recognition and task learning. Task recognition involves the model's capability to identify and understand the nature of the task from the provided demonstrations, even if these include incorrect labels. Once the task is recognized, the model then applies its pre-existing knowledge to address the task. Task learning, on the other hand, refers to the model's ability to learn new input-label mappings that were not part of its pre-training, effectively adapting to new information and tasks.

## Leveraging ICL

The number of examples given is, in general, positively correlated to the model performance.[10] So, giving the model as many examples as possible is a good way to maximize performance. In practice, since the context is limited and creating the examples are also a burden, we experiment with what we have or create a few, then expand if we need better accuracy. Also, one interesting aspect in task learning is that the order of the examples affect the performance.[11] Consequently, experimenting with different permutations can optimize task learning outcomes.

2) Self-consistency

Self-consistency works by choosing the most consistent answer after multiple generations. Self-consistency is achieved by taking the majority vote as the final answer, after having the model generate multiple chains-of-thought and answers to the same question while introducing a slight randomness in the generation.[12] By default, GPT-3.5 and GPT-4 has a randomness to its response which cannot be completely removed. In other words, even the same prompt may, and probably will, output different generations each time. When the model tries to solve a problem, this randomness might make it take a slightly different path to reach an answer, even though the starting conditions remain the same.
By generating a number of these slightly varied solutions, a spectrum of answers can be obtained. Despite the differences, correct answers tend to cluster around the truth because logical paths, even when varied, often lead to the same conclusion. The self-consistency method leverages this tendency by identifying the most common answer among these attempts, treating it as the most probable or "consistent" solution. This has been experimentally proven to be superior to greedy sampling in LLMs in which the randomness can be turned off.[12] In practice, this means that if resources allow, taking the majority vote after multiple runs will produce better results. (Fig. 9)

Potential applications for abdominal radiology

LLMs can aid or simplify routine tasks like text generation, summarization, and feature extraction, enhancing efficiency and content quality without compromising the written context. In clinical settings, for instance, they can swiftly simplify formal conclusions by evaluating radiological reports [13]. Gu et al. reported that GPT-4 can be used to extract LI-RADS features from existing radiology reports. In particular, the authors iteratively applied various prompt engineering strategies to build the best prompt on a training set, and externally validated it on a separate dataset [5]. In this way, researchers can harness the full potential of LLMs to produce desired outcomes, assisting in the advancement of LLMs for clinical use in radiology.

Conclusion

The strategic application of prompt engineering is crucial for radiologists to effectively leverage LLMs, enhancing clinical application, workflow efficiency, and future research. The authors hope this review of prompt engineering will help improve radiologists' comprehension and application of LLMs in clinical practice.

Fig. 1.
Example of different results from search engine (www.google.com) with minor adjustments in search terms.
kjar-2024-00017f1.jpg
Fig. 2.
Example of prompt engineering, “Be specific with clear instructions”. (A) Original prompt. (B) Modified prompt with more specificity. (C) Additional modification to adjust tone.
kjar-2024-00017f2.jpg
Fig. 3.
Example of prompt engineering, “Persona and Perspective”. (A) Original prompt. (B) Modification of listening level to make the explanation easier. (C) Designation of persona and addition of specific details for the task.
kjar-2024-00017f3.jpg
Fig. 4.
Example of prompt engineering, “Use of Delimiters and Syntax”, “Repetition and Order”, “Provide Options to avoid unfaithful output”, and “Reference Material”. The red arrows denote how delimiters are used. The red box denotes how the prompt can be structured. The blue boxes denote repetition of important instructions. The black arrow denotes an example of giving an ‘out’ option. The gray arrow denotes how a set of instructions can be made for reference.
kjar-2024-00017f4.jpg
Fig. 5.
Example of prompt engineering, “Break down complex tasks into subtasks”. The prompt in the upper panel gives a complex instruction in two sentences. The prompt in the lower panel shows how this task can be broken down to subtasks.
kjar-2024-00017f5.jpg
Fig. 6.
Example of prompt engineering, “Use of External Tools” with Python code. The prompt instructs the LLM to output the results in JSON format, which can be read as a dictionary object in Python. Then, using multiple conditional statements, a LI-RADS category is calculated.
kjar-2024-00017f6.jpg
Fig. 7.
Example of prompt engineering, “Allow for ‘Thinking’ Time”. (A) GPT-3.5 fails to solve the original riddle. (B) Just by adding one sentence that encourages chain-of-thought, GPT-3.5 correctly solves the riddle.
kjar-2024-00017f7.jpg
Fig. 8.
Example of few-shot chain-of-thought prompting. Even though the model is prompted to create a chain-of-thought by enforcing a ‘rationale’ in the output format, the chain-of-thought is not effective. By adding a one-shot exemplar, we demonstrate how the rationale should be structured. The model then mimics the reasoning path to arrive at the correct answer.
kjar-2024-00017f8.jpg
Fig. 9.
Example of self-consistency. The model initially failed the riddle with greedy decoding (not shown). With non-greedy decoding, we can generate multiple chains-of-thought and arrive at different answers. Performing a majority vote over these answers is more likely to lead to the correct answer than using greedy decoding.
kjar-2024-00017f9.jpg

References

1. Kaddour J, Harris J, Mozes M, Bradley H, Raileanu R, McHardy R. Challenges and applications of large language models. arXiv preprint arXiv:2307.10169, 2023.
2. Microsoft. Introduction to prompt engineering. [cited 2024 April 2nd]; Available from: https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/prompt-engineering.
4. OpenAI. Prompt engineering. [cited 2024 April 2nd]; Available from: https://platform.openai.com/docs/guides/prompt-engineering/prompt-engineering.
5. Gu K, Lee JH, Shin J, Hwang JA, Min JH, Jeong WK, et al. Using GPT-4 for LI-RADS feature extraction and categorization with multilingual free-text reports. Liver Int 2024;Jul;44(7):1578-1587.
pmid
6. Schick T, Dwivedi-Yu J, Dessì R, Raileanu R, Lomeli M, Hambro E, et al. Toolformer: Language models can teach themselves to use tools Advances in Neural Information Processing Systems 2024;36.
7. Mialon G, Dessì R, Lomeli M, Nalmpantis C, Pasunuru R, Raileanu R, et al. Augmented language models: a survey. arXiv preprint arXiv:2302.07842 2023.
8. Wei J, Wang X, Schuurmans D, Bosma M, Xia F, Chi E, et al. Chain-of-thought prompting elicits reasoning in large language models. Advances in neural information processing systems 2022;35:24824-24837.
crossref
9. Wu Z, Zhang L, Cao C, Yu X, Dai H, Ma C, et al. Exploring the trade-offs: Unified large language models vs local fine-tuned models for highly-specific radiology nli task. arXiv preprint arXiv:2304.09138 2023.
crossref
10. Hao Y, Sun Y, Dong L, Han Z, Gu Y, Wei F. Structured prompting: Scaling in-context learning to 1,000 examples. arXiv preprint arXiv:2212.06713 2022.
11. Lu Y, Bartolo M, Moore A, Riedel S, Stenetorp P. Fantastically ordered prompts and where to find them: Overcoming few-shot prompt order sensitivity. arXiv preprint arXiv:2104.08786 2021.
crossref
12. Wang X, Wei J, Schuurmans D, Le Q, Chi E, Narang S, et al. Self-consistency improves chain of thought reasoning in language models. arXiv preprint arXiv:2203.11171 2022.
13. Doshi R, Amin KS, Khosla P, Bajaj S, Chheang S, Forman HP. Quantitative Evaluation of Large Language Models to Streamline Radiology Report Impressions: A Multimodal Retrospective Analysis. Radiology 2024;310(3):e231593.
crossref pmid
TOOLS
METRICS Graph View
  • 0 Crossref
  •  0 Scopus
  • 2,112 View
  • 32 Download
Related articles


ABOUT
BROWSE ARTICLES
EDITORIAL POLICY
FOR CONTRIBUTORS
Editorial Office
103-1103, The Sharp Seocho, 21, Seochojungang-ro 2-gil, Seocho-gu, Seoul 06720, Korea
Tel: +82-2-3474-1983    Fax: +82-2-3474-1982    E-mail: office@e-kjar.org                

Copyright © 2026 by The Korean Society of Abdominal Radiology.

Developed in M2PI

Close layer
prev next