Deidentifying Clinical Text logo

Deidentifying Clinical Text

CommunityPopular
maziyarpanahi
deidentifying-clinical-text

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.

Overview

Publishermaziyarpanahi
Repositoryopenmed
Skill namedeidentifying-clinical-text
Stars
5.3K
Forks
677
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by maziyarpanahi on GitHub. Read the source before you install it.

Installation

Install the Deidentifying Clinical Text AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/maziyarpanahi/openmed.git /tmp/openmed
mkdir -p .claude/skills
cp -r /tmp/openmed/skills/deidentifying-clinical-text .claude/skills/deidentifying-clinical-text
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Deidentifying Clinical Text in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Deidentifying Clinical Text on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Deidentifying Clinical Text is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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

FieldWhat it holds
.deidentified_textthe rewritten, PHI-safe string (your output)
.pii_entitieslist[PIIEntity] — each has start, end, canonical_label, confidence, action, surrogate; original_text/text hold raw PHI
.mappingredacted→original dict, only when keep_mapping=True (secret)
.methodthe method actually applied
.metadatarun metadata (model, policy, counts)

The five methods

method=EffectReversible?Use when
"mask"John Doe[NAME]with keep_mapping=Truedefault; clear that redaction happened
"remove"deletes the span entirelynominimal-footprint output
"replace"type-matched fake value (John DoeMark Lee)with keep_mapping=Truekeep notes readable/parseable (see generating-synthetic-surrogates)
"hash"stable hash per value, links repeatsno (one-way)cohort linkage without revealing identity
"shift_dates"moves dates, preserves intervalsn/aresearch needing temporal structure (see shifting-clinical-dates)

Workflow

  1. 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. See configuring-privacy-policies.
  2. Set confidence_threshold deliberately. Default is 0.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.
  3. Run deidentify. Inspect result.pii_entities by offset and label, not raw text, to confirm coverage.
  4. For stable surrogates, pass consistent=True, seed=<int> so the same input maps to the same fake value every run (reproducible pipelines).
  5. For reversibility, pass keep_mapping=True and store result.mapping in a secured vault — never alongside the de-identified output.
  6. 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

python
# 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)PredictionResult with .entities (spans, no rewrite). Use it to preview coverage first.
  • Restore: openmed.reidentify(deidentified_text, mapping) — requires keep_mapping=True at de-id time and proper authorization.
  • Policies: configuring-privacy-policies to choose/customize a policy=.
  • Audit: deidentify(..., audit=True)AuditReport with offsets, hashes, detector provenance, and residual-risk — never plaintext.
  • Other surfaces (same engine): MCP tool openmed_deidentify; REST POST /pii/deidentify. There is no CLI de-id command.

Edge cases & gotchas

  • Attribute names. It is result.deidentified_text and result.pii_entities — not .text/.entities. (extract_pii returns a PredictionResult whose spans are at .entities.)
  • Raw PHI never leaves the span objects. PIIEntity.text and .original_text contain real identifiers. Do not print, log, or cache them. Audit and logs use offsets, canonical_label, and hashes only.
  • Threshold is a safety dial, not an accuracy dial. Lowering it redacts more; in de-id, false positives are cheap and false negatives are breaches.
  • shift_dates is for dates only; combine with keep_year/date_shift_days (see shifting-clinical-dates). It does not touch names or IDs.
  • keep_mapping output is sensitive as PHI. The mapping re-identifies everyone — store it encrypted, access-controlled, and apart from the output.
  • Multilingual: pass lang= (and locale= for surrogates) for non-English notes; see deidentifying-multilingual-text. Do not run English models on other languages.
  • De-id is verified, not assumed. Gate releases on leakage/residual-risk, not F1 alone.

Standards & references

Frequently asked questions

What does the Deidentifying Clinical Text AI skill do?

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 aud...

Why use Deidentifying Clinical Text on TypingMind?

Because you install it once and use it with any model. Deidentifying Clinical Text is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Deidentifying Clinical Text in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/maziyarpanahi/openmed/tree/master/skills/deidentifying-clinical-text. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Deidentifying Clinical Text?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Deidentifying Clinical Text?

As many as you like. As long as a model supports skills, you can use Deidentifying Clinical Text with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Deidentifying Clinical Text AI skill free?

Yes. It is published on GitHub by maziyarpanahi under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇