deidentifying-clinical-text
What it does
This skill removes or hides patient identifiers in clinical notes, such as names, dates and record numbers, on your own computer. It is for anyone who must share or analyze medical notes without exposing patients.
When to use it
- ✓When you need to redact patient names, dates or record numbers from medical notes before sharing.
- ✓When you want to replace identifiers with realistic fake values so the notes stay readable.
- ✓When you must pick a de-identification method, such as masking, removing or shifting dates.
Skill link
https://github.com/maziyarpanahi/openmed/blob/master/skills/deidentifying-clinical-text/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Remove the patient names, dates and phone numbers from these discharge summaries before I share them with my research team.”
5 new skills a week. 1 minute to read.
How it works
The agent runs on-device detection to find identifiers, applies the chosen method such as masking or replacement, and returns the cleaned text with a list of what changed.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
De-identifying clinical text
openmed.deidentify detects PHI/PII and rewrites the text so it can be shared,
stored, or analyzed without exposing patients. It runs fully on-device after
a one-time model download — no network calls, no telemetry, no raw PHI leaving
the process. This is the single most important OpenMed entry point for privacy
work; everything else (policies, audit, multilingual, date-shifting) layers on
top of it.
When to use this skill
Reach for deidentify when you need to transform text — replace, mask, remove,
hash, or date-shift the identifiers. If you only need to locate PHI spans
without changing the text, use extract_pii (see extracting-pii-entities). To
restore masked text later, use reidentify (see reidentifying-text).
Quick start
import openmed
note = (
"Patient John Doe (MRN 1234567) was seen on 2024-03-02 by Dr. Alice Reed. "
"Contact: john.doe@example.com, 617-555-0142."
)
result = openmed.deidentify(
note,
method="mask", # mask | remove | replace | hash | shift_dates
confidence_threshold=0.7, # safety default; raise to reduce false negatives' impact
policy="hipaa_safe_harbor", # optional bundled profile (see below)
)
print(result.deidentified_text)
# Patient [NAME] (MRN [ID_NUM]) was seen on [DATE] by Dr. [NAME]. ...
for e in result.pii_entities:
# NEVER log e.text / e.original_text — those are raw PHI. Use offsets + label.
print(e.canonical_label, e.start, e.end, round(e.confidence, 3))
deidentify returns a DeidentificationResult with these fields (note the
exact names):
| Field | What it holds |
|---|---|
.deidentified_text |
the rewritten, PHI-safe string (your output) |
.pii_entities |
list[PIIEntity] — each has start, end, canonical_label, confidence, action, surrogate; original_text/text hold raw PHI |
.mapping |
redacted→original dict, only when keep_mapping=True (secret) |
.method |
the method actually applied |
.metadata |
run metadata (model, policy, counts) |
The five methods
method= |
Effect | Reversible? | Use when |
|---|---|---|---|
"mask" |
John Doe → [NAME] |
with keep_mapping=True |
default; clear that redaction happened |
"remove" |
deletes the span entirely | no | minimal-footprint output |
"replace" |
type-matched fake value (John Doe→Mark Lee) |
with keep_mapping=True |
keep notes readable/parseable (see generating-synthetic-surrogates) |
"hash" |
stable hash per value, links repeats | no (one-way) | cohort linkage without revealing identity |
"shift_dates" |
moves dates, preserves intervals | n/a | research needing temporal structure (see shifting-clinical-dates) |
Workflow
- Pick a method and a policy. Start from a bundled
policy=profile (hipaa_safe_harbor,gdpr_pseudonymization,research_limited_dataset, …) so per-label actions are set for you. Seeconfiguring-privacy-policies. - Set
confidence_thresholddeliberately. Default is0.7. For de-id, prefer over-redaction: a missed identifier is a breach, an over-redacted token is just noise. The bundled safety sweep catches structured IDs (SSN, MRN-like, emails) even below threshold. - Run
deidentify. Inspectresult.pii_entitiesby offset and label, not raw text, to confirm coverage. - For stable surrogates, pass
consistent=True, seed=<int>so the same input maps to the same fake value every run (reproducible pipelines). - For reversibility, pass
keep_mapping=Trueand storeresult.mappingin a secured vault — never alongside the de-identified output. - Verify, don't assume. Check residual risk with
audit=True(auditing-deidentification-runs) and the 18-identifier checklist (auditing-safe-harbor-checklist).
Consistent surrogates and reversibility
# Same fake identity for every mention of the same person, reproducibly:
r = openmed.deidentify(note, method="replace", consistent=True, seed=42)
# Reversible de-id (keep the mapping secret and separate from output):
r = openmed.deidentify(note, method="mask", keep_mapping=True)
restored = openmed.reidentify(r.deidentified_text, r.mapping)
assert restored == note
Hand-off to / from OpenMed
- Detect only:
openmed.extract_pii(text)→PredictionResultwith.entities(spans, no rewrite). Use it to preview coverage first. - Restore:
FAQ
Does the text leave my computer?
No. Processing runs on the device after a one-time model download, with no network calls.
Can I restore the original text later?
Some methods support reversal. The reidentification skill covers restoring masked text.
Is there a safety setting?
Yes. A confidence threshold is set to favor safety, and you can adjust it.
Details
Original description by the author
Remove, mask, or replace PHI/PII in clinical free text on-device with OpenMed's deidentify(). Use when the user needs to de-identify medical notes, strip patient identifiers, redact PHI before sharing or analysis, anonymize discharge summaries, or pick a de-id method (mask vs remove vs replace vs hash vs shift_dates). Covers confidence_threshold for safety, consistent+seed for stable surrogates, keep_mapping for reversible de-id, policy= profiles, and the DeidentificationResult fields. Pairs with OpenMed extract_pii (detect spans), reidentify (restore), configuring-privacy-policies, and auditi
repo: maziyarpanahi/openmed
Popularity
- GitHub stars
- 5.8k
- Ranking position
- #14689
- License
- Apache-2.0
- Updated
- 11/2/2026
Comments
- …
More skills from this repository
annotating-variants
5.8kHelps your agent predict what a genetic variant does, convert HGVS names to genome positions and attach population frequencies, using free public annotators.
ask-openmed
5.8kHelps your agent pick the right OpenMed workflow for a clinical text request, starting with a privacy check whenever patient data may be present.
assembling-fhir-bundles
5.8kPackages several FHIR health records into one transaction Bundle ready to send to an EHR, with the internal references linked correctly.
auditing-deid-leakage
5.8kScans de-identified clinical text for leftover identifiers such as SSNs, card numbers, emails and dates, and blocks release if any remain.
Similar skills
reverse-engineer-anything
422kHelps your agent look inside shipped apps and packages to explain features, compare versions, or guide a rebuild, using the REA tool.
1password
394kHelps your agent set up the 1Password CLI, sign in, and read or inject secrets without printing their values into chat.
healthcheck
394kHelps your agent audit the computer or server that runs OpenClaw for security risks, such as SSH, firewall, updates, and backups, then suggest safe fixes.