A MuleSoft IDP prompt that finds each distinct patient inside a batched, multi-patient medical PDF and returns each one's contiguous page range with a confidence score, using name/DOB boundary detection.
IDP Prompt — Multi-Patient Packet Segmentation
Objective: Some inbound scans batch multiple patients' records into a single PDF (e.g. a fax with several onboarding packets). Downstream processing needs each patient handled separately. This prompt finds patient boundaries by name/DOB change and returns each patient's page range so the packet can be split before extraction.
Prerequisites
- MuleSoft IDP (Einstein) enabled; a
GENERIC document action created in Anypoint IDP.
- IDP Connector wired into the calling Mule app.
- Document-action prompt configured with
source: "llm".
The prompt
You are extracting patient packet boundaries from a multi-patient medical PDF.
Task:
Identify EACH distinct patient in the PDF and the contiguous page range (1-indexed) that belongs to that patient's packet.
Definitions / rules:
- A "patient packet" is a contiguous set of pages that all refer to the same patient.
- A new patient packet starts when a page prominently introduces a different patient name and date of birth/birthdate.
- Page numbers must be 1-indexed integers (first page is 1).
- Each patient must have exactly one startPage and one endPage (inclusive).
- Extract DOB in ISO format YYYY-MM-DD.
- If the document shows DOB like "Nov 4, 1962", convert to "1962-11-04".
- If you are uncertain, make your best determination and lower confidence.
Output requirements (STRICT):
- Output ONLY valid JSON.
- Output MUST be a JSON array.
- Each array element MUST be an object with EXACTLY these keys:
- "firstName" (string)
- "lastName" (string)
- "dob" (string, YYYY-MM-DD)
- "startPage" (integer)
- "endPage" (integer)
- "confidence" (number from 0.0 to 1.0)
No extra keys. No markdown. No explanations.
Example format:
[
{ "firstName":"Jane","lastName":"Doe","dob":"1990-01-02","startPage":1,"endPage":3,"confidence":0.93 }
]
Sample payload — segmentation output
[
{ "firstName": "Jane", "lastName": "Doe", "dob": "1990-01-02", "startPage": 1, "endPage": 3, "confidence": 0.93 },
{ "firstName": "Marcus", "lastName": "Lee", "dob": "1962-11-04", "startPage": 4, "endPage": 6, "confidence": 0.88 }
]
Testing and validation
- Happy path: a 2-patient PDF returns two non-overlapping page ranges covering every page.
- Edge case: a patient whose name/DOB header only appears once at the very start of their section, with subsequent pages carrying no header — confirm the model still attributes those trailing pages to the right patient rather than starting a spurious new "Other" segment.
- Verify DOB reformatting handles varied source formats ("Nov 4, 1962", "11/04/1962") consistently to
YYYY-MM-DD.
Deliverable: A page-range map of every patient in a batched PDF, ready to drive a page-scoped split before per-patient extraction runs.