Medical Records Prompt
Building a patient medical record summarization prompt: from a naive first draft to a production solution with system prompt, XML structure, example, and JSON output.
The Task
Summarize long patient medical records for doctors before appointments. Each summary must include: name, age, key diagnoses, medications, other treatments, current concerns, and action items.
Naive Prompt (Bad)
initial_prompt = """
I have this patient medical record. Can you summarize it for me?
{record}
I need this for a quick review before the patient's appointment tomorrow.
"""
Problem: Claude produces different formats — sometimes long paragraphs, sometimes lists. Not compatible with programmatic processing.
Improved Prompt
system = """
You are a highly experienced medical professional with a specialty
in translating complex patient histories into concise, actionable summaries.
Your role is to analyze patient records, identify critical information,
and present it in a clear, structured format that aids in diagnosis
and treatment planning.
"""
updated_prompt = """
I need your help summarizing patient medical records for our team of doctors.
Each summary should include the following elements in this order:
- The patient's name and age
- A bulleted list of key diagnoses in chronological order
- A bulleted list of medications the patient is prescribed
- A bulleted list of other treatments (CBT, physical therapy, etc.)
- A short bulleted list of recent concerns
- A bulleted list of key action items for the doctor
<example>
<patient_record>Patient Name: Ethan Blackwood, Age: 55...</patient_record>
<summary>
Name: Ethan Blackwood
Age: 55
Key Diagnoses:
- Hypertension (2010)
...
</summary>
</example>
<patient_record>
{record}
</patient_record>
"""
JSON Version for Programmatic Processing
response = client.messages.create(
model="claude-3-sonnet-20240229",
max_tokens=4096,
system=system,
messages=[{"role": "user", "content": complete_prompt}]
)
import json
summary_data = json.loads(response.content[0].text)
action_items = summary_data.get("action_items", [])
Requesting JSON with fields name, age, key_diagnoses, medications, recent_concerns, action_items enables automatically aggregating a daily physician task list across all patients.
Write a medical record summarization prompt. Start with a naive version, observe format inconsistency, then add a doctor-role system prompt, XML tags for data, an example template, and JSON requirement. Compare results across three different 'patients'.
Copy and adapt to your context. Text in angle brackets should be replaced.
You are a highly experienced medical professional specializing in concise patient summaries.
I need help summarizing patient medical records before tomorrow's appointments.
<example>
<patient_record>Patient Name: [Example], Age: [N]
Medical Record: [history]</patient_record>
<summary>
Name: [Example] | Age: [N]
Key Diagnoses: - [Diagnosis (Year)]
Medications: - [Drug — purpose]
Recent Concerns: - [concern]
Action Items: - [action]
</summary>
</example>
<patient_record>
{{MEDICAL_RECORD}}
</patient_record>
Generate the summary inside <summary> tags.Not specifying the exact section format — Claude will vary the structure. Forgetting to request chronological order for diagnoses. Skipping the example — without it, output is unstable. In JSON mode, not verifying that Claude doesn't add text before/after the JSON.
For forced JSON output, use tool use (structured outputs) instead of a text request — more reliable. The <summary> tag in the example automatically teaches Claude to wrap output — easy to parse with regex without JSON.
Processing structured input documents requiring consistent output: medical records, legal cases, incident reports.
When physicians want to see a full narrative without formatting — structure may hide clinically important nuances.