
Extracting Pii Entities
Detect PHI/PII spans in clinical text with OpenMed's extract_pii without altering the...
Install
npx skills add maziyarpanahi/openmed --skill extracting-pii-entities -g -a claude-code -y- Repository
- maziyarpanahi/openmed5.8k
- Category
- Engineering
- Updated
- 4d ago
- License
- Apache-2.0
- Context cost
- Mediumabout 1,555 tokens
- Runs scripts
- No, instructions only
What it does
Detect PHI/PII spans in clinical text with OpenMed's extract_pii without altering the text. Use when the user wants to find names, dates, MRNs, phone numbers, addresses, SSNs, or other identifiers and get their offsets and labels (not redact them), inspect what would be removed before de-identifying, route spans to a custom redactor, normalize labels to a canonical taxonomy, or filter by confidence and language. Covers extract_pii, the PIIEntity fields, CANONICAL_LABELS / normalize_label, and how it differs from deidentify. Pairs before reidentifying-text and deidentifying-clinical-text.
Extracting PII Entities
openmed.extract_pii finds PHI/PII spans and returns them without changing the
text. Use it when you need to see the identifiers, to audit, route to a
custom redactor, or decide a policy, rather than produce redacted output. It runs
on-device.
When to use
- You want the spans and labels of identifiers, with the original text intact.
- You need a preview of what
deidentifywould act on before committing. - You are feeding detected spans into a downstream redactor (your own,
Presidio, or
deidentify). - You want to normalize model labels to a stable canonical taxonomy.
If you instead want redacted/masked output directly, use
deidentifying-clinical-text (openmed.deidentify). If you need reversible
masking, see reidentifying-text.
extract_pii vs deidentify
extract_pii | deidentify | |
|---|---|---|
| Changes the text? | No | Yes (mask/remove/replace/hash/shift) |
| Returns | PredictionResult (spans) | DeidentificationResult (redacted text) |
| Default threshold | 0.5 | 0.7 (safety-biased) |
| Use for | detection, audit, routing | producing safe output |
Install
pip install "openmed[hf]"
Quick start
import openmed
note = "Patient John Doe (MRN 00481726), DOB 1970-01-15, phone 617-555-0142."
result = openmed.extract_pii(note, confidence_threshold=0.5)
for ent in result.entities:
print(f"{ent.label:10} {ent.text!r:18} {ent.confidence:.2f} [{ent.start}:{ent.end}]")
extract_pii(...) returns a PredictionResult. Its .entities are PIIEntity
objects (synthetic example fields shown):
