Anatomy of a Prompt
The structural components of a production prompt — system message, role, task, context, constraints, format, and examples — and how each shapes model behaviour.
Prompt Components
A well-structured prompt typically contains some or all of these elements:
1. Role / Persona
2. Task / Objective
3. Context / Background
4. Input
5. Constraints / Rules
6. Output Format
7. Examples (few-shot)Not every prompt needs all components — but understanding each helps you diagnose when a prompt fails.
1. Role / Persona
Establish who the model is playing. This activates relevant knowledge and behavioural patterns from pretraining:
"You are an experienced clinical pharmacist reviewing medication orders
for potential drug-drug interactions and dosing errors."
vs.
(no role)
The role shapes:
Vocabulary: clinical vs. lay language
Detail level: how much pharmacology the model assumes the reader knows
Safety: "clinical pharmacist" implies professional responsibility
Format: pharmacists write concise, precise clinical notes2. Task / Objective
State clearly what the model should do. Use imperative verbs — not vague nouns:
Weak: "Information about the patient's medications."
Strong: "Review the medication list and identify: (1) any potential
drug-drug interactions, (2) any dosing outside standard ranges,
(3) missing monitoring parameters (e.g., INR for Warfarin)."
Weak: "The patient note."
Strong: "Summarise the patient note in 3 bullet points for the incoming
nurse shift. Focus on: primary problem, current plan, urgent actions."3. Context / Background
Provide domain-specific background the model needs. Don't assume it knows your system's conventions:
"This is a hospital clinical documentation system.
Notes are written by attending physicians and residents.
Your summaries will be read by nurses during handoff.
Patient data is real — maintain strict confidentiality conventions."Context also sets the stakes: clinical, legal, financial contexts raise the bar for accuracy.
4. Input
Clearly delimit the input from the instructions:
Using XML-style tags (recommended for clarity):
Patient is a 68-year-old female presenting with palpitations.
Current medications: Warfarin 5mg, Metformin 500mg.
Using delimiter lines:
---PATIENT NOTE---
Patient is a 68-year-old female...
---END NOTE---
Why delimiters matter:
Prevents prompt injection (hard to inject through XML tags)
Clearly signals to the model where instructions end and data begins
Makes multi-field inputs unambiguous5. Constraints / Rules
Specify what the model must NOT do, as well as what it must do:
"Rules:
- Do not add any information not present in the original note.
- Do not use abbreviations unless defined in the original note.
- If information for a required field is absent, write 'Not documented.'
- Do not make dosing recommendations.
- Always recommend physician or pharmacist consultation for clinical decisions."Constraints prevent specific failure modes — write them based on observed failures.
6. Output Format
Specify exact structure. Ambiguity in format leads to inconsistent output:
Weak: "Give me a structured summary."
Strong:
"Respond ONLY with valid JSON matching this schema:
{
'primary_diagnosis': string,
'medications': [string],
'urgent_actions': [string],
'risk_flags': [string]
}
Do not include any text outside the JSON."7. Examples (Few-Shot)
Examples are the most powerful way to communicate complex format and reasoning requirements:
"Here are examples of correctly formatted outputs:
Input: 'Patient has AF. On Warfarin 5mg. INR 1.8 last week.'
Output: {
'primary_diagnosis': 'Atrial fibrillation',
'medications': ['Warfarin 5mg daily'],
'urgent_actions': ['Check INR — last result subtherapeutic (target 2.0-3.0)'],
'risk_flags': ['Subtherapeutic anticoagulation']
}
Now process the following note:"Examples communicate what text description cannot: the exact level of detail, the phrasing conventions, and what counts as an "urgent action" vs a "risk flag."
Full Example: Clinical Note Summariser
You are an experienced clinical pharmacist reviewing medication orders
for a hospital patient handoff system.
Task: Summarise the patient's current clinical status for the incoming nurse.
Focus on: primary diagnosis, medications with dosing, required monitoring,
and any flagged concerns.
Rules:
- Only include information present in the note.
- For missing fields, write "Not documented."
- Do not recommend changes to medications.
- If you identify a potential drug interaction, flag it — do not diagnose.
Output format (respond only with this JSON):
{
"primary_diagnosis": string,
"medications": [{"name": string, "dose": string, "frequency": string}],
"monitoring_due": [string],
"flags": [string]
}
Patient note:
{{note_text}}
Interview Answer
"A production prompt typically has: a role (establishes persona and activates relevant knowledge), a task statement (imperative, specific), context (domain background, stakes), delimited input (XML tags prevent injection and ambiguity), constraints (explicit rules, especially what NOT to do), output format (exact schema for downstream parsing), and few-shot examples (most powerful tool for complex format/reasoning). Good prompts are written bottom-up from failure modes: write the constraint or example that prevents the specific failure you observed in testing."
Found this helpful?
Leave a comment
Have a question, correction, or just found this helpful? Leave a note below.