# Deidentifying Clinical Text

Remove, mask, or replace PHI/PII in clinical free text on-device with OpenMed's...

- Repository: https://github.com/maziyarpanahi/openmed (5755 stars)
- Category: Writing
- License: Apache-2.0
- Last updated: 2026-10-31
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add maziyarpanahi/openmed --skill deidentifying-clinical-text -g -a claude-code -y`
Codex: `npx skills add maziyarpanahi/openmed --skill deidentifying-clinical-text -g -a codex -y`
Cursor: `npx skills add maziyarpanahi/openmed --skill deidentifying-clinical-text -g -a cursor -y`
Gemini CLI: `npx skills add maziyarpanahi/openmed --skill deidentifying-clinical-text -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add maziyarpanahi/openmed`

## Description

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 auditing-deidentification-runs.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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

```python
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):

The rest: https://github.com/maziyarpanahi/openmed/blob/HEAD/skills/deidentifying-clinical-text/SKILL.md
