Prompt Engineering

Tips for Effective Prompts for Language Models

Sean Davis, MD, PhD

Thursday, October 17, 2024

What is a Prompt, anyway?

  • A prompt is a set of instructions or guidelines given to a language model to generate a specific output.
  • It can be a question, a task, or a description of the desired output.
  • Prompts help guide the model’s response and ensure it provides relevant and accurate information.
  • Effective prompt design is crucial for obtaining useful and reliable results from language models.

And Prompt Engineering?

  • Prompt engineering is the process of designing prompts to elicit the desired responses from language models.
  • It involves crafting clear, specific, and structured instructions that guide the model’s behavior.
  • Well-designed prompts can improve the accuracy, relevance, and usability of the model’s outputs.
  • Prompt engineering is essential for leveraging the full potential of language models in various applications.

Rule 1: Start with a Clear Objective

Why? A well-defined goal guides the prompting process.

How? Begin with a specific question, task, or instruction.

Example:

❌ "Tell me about diabetes." 

✅ "Summarize the key risk factors for developing Type 2 diabetes."

Rule 2: Provide Context

Why? Context helps the model understand the background and purpose.

How? Include relevant details such as patient demographics, medical history, or specific symptoms.

Example:

✅ “A 55-year-old male with a history of hypertension presents with chest pain…”

Rule 3: Use Precise Language

Why? Ambiguity can lead to inaccurate or irrelevant results.

How? Choose specific medical terms and avoid vague descriptions.

Example:

❌ “stomach pain”

✅ “epigastric pain radiating to the back”

Rule 4: Specify the Desired Output Format

Why? This ensures the information is delivered in a usable format.

How? Request specific formats like lists, tables, summaries, or code.

Example:

✅ “Generate a differential diagnosis list for these symptoms…”

✅ “Summarize the patient’s history in bullet points.”

Rule 5: Iterate and Refine

Why? Prompt engineering is an iterative process.

How? Experiment with different phrasing, keywords, and levels of detail. Analyze the outputs and refine the prompts to improve accuracy.

Example:

  • Initial Prompt: “What are the treatment options for this patient?”
  • Refined Prompt: “Given the patient’s age, medical history, and contraindications, provide a prioritized list of evidence-based treatment options for their condition.”

Rule 6: Employ “Few-Shot” Prompting

Why? Providing examples helps the model understand the desired pattern.

How? Include a few examples of the desired input-output pairs in the prompt.

Example:

Prompt: “Translate these medical abbreviations:

  • CHF: Congestive Heart Failure
  • MI: Myocardial Infarction

Now translate:

  • COPD: ”

Rule 7: Break Down Complex Tasks

Why? Large language models perform better with focused, step-by-step instructions.

How? Decompose complex tasks into smaller, more manageable subtasks.

Example:

Instead of asking for a complete treatment plan, first ask for:

  1. Possible diagnoses
  2. Treatment options for each diagnosis
  3. Factors influencing treatment selection

Rule 8: Utilize Delimiters

Why? Delimiters help the model distinguish between different parts of the prompt.

How? Use clear separators like “```”, “###”, or “**” to mark different sections.

Example:

Prompt:

Your goal is to generate a differential diagnosis for this patient. 

### Start of patient information
Patient History:
60-year-old female
History of type 2 diabetes

Current Symptoms:
Fatigue
Increased thirst
### End of patient information

Rule 9: Be Mindful of Biases

Why? Language models can reflect biases present in the training data.

How? Use neutral language and avoid stereotypes.

Example:

❌ “This is a typical case of…”

✅ “Based on the presented information, consider…”

Rule 10: Stay Updated on Best Practices

References

Meskó, Bertalan. 2023. “Prompt Engineering as an Important Emerging Skill for Medical Professionals: Tutorial.” Journal of Medical Internet Research 25 (1): e50638. https://doi.org/10.2196/50638.