reidentifying-text
できること
このスキルは、臨床テキストから個人情報を取り除き、それを復元できる対応表を保つ方法をエージェントに教えます。許可のもとで、元の身元を後から結びつける必要がある場合に使います。
使う場面
- ✓今は患者の詳細を隠し、許可のもとで後から記録を結びつける必要があるとき。
- ✓プロジェクトがGDPRの仮名化に従い、識別子を、データとは別に保つ必要があるとき。
- ✓レビューする人が、伏せ字が正しいかを抜き取りで確認するため、伏せ字のテキストと元のテキストを比べたいとき。
スキルのリンク
https://github.com/maziyarpanahi/openmed/blob/master/skills/reidentifying-text/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“患者の名前は伏せてください。ただし後で復元できるように、対応表は保存してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、保存された対応表を使って匿名化の手順を実行し、その後、再識別の手順を使って元の値を復元します。対応表は伏せたテキストとは別に保存する必要があります。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Reidentifying Text
Some workflows need to remove PHI for processing but keep the ability to
restore it later under authorization — adjudication, patient recontact, linking
results back to a record. That is pseudonymization (reversible), not
anonymization (irreversible). OpenMed supports it with
deidentify(..., keep_mapping=True) to capture a mapping, and reidentify to
restore. Everything runs on-device.
When to use
- You need to re-link redacted output to the original record later.
- You are doing GDPR pseudonymization (Art. 4(5)): identifiers held separately, reversible under controlled conditions.
- A reviewer must spot-check redactions against originals.
Do NOT use reversibility when:
- The goal is HIPAA Safe Harbor anonymization or a true anonymous release —
a re-identification mapping defeats anonymization. Use
method="remove"and keep no mapping. - The redacted text leaves your trust boundary and the mapping might travel with it. The mapping is the secret; never co-locate it with the de-identified output.
Install
pip install "openmed[hf]"
Quick start: reversible round-trip
import openmed
note = "Patient John Doe (MRN 00481726) seen on 2024-03-02 by Dr. Alice Smith."
# 1) De-identify AND capture the reversal mapping
deid = openmed.deidentify(
note,
method="mask", # or "replace" for realistic surrogates
keep_mapping=True, # <-- required to enable reidentify()
policy="gdpr_pseudonymization",
)
safe_text = deid.deidentified_text # ship/process this
mapping = deid.mapping # SECRET: store separately, encrypted
# 2) Later, under authorization, restore the original
restored = openmed.reidentify(safe_text, mapping)
assert restored == note
reidentify(deidentified_text, mapping) performs the inverse substitution. The
mapping is a dict[str, str] of redacted → original text, produced only when
keep_mapping=True.
Use consistent surrogates for stable pseudonyms
For replacement that maps the same identifier to the same surrogate across a document (and reproducibly across runs with a seed):
import openmed
deid = openmed.deidentify(
"Mr. John Doe called. John Doe's MRN is 00481726.",
method="replace",
consistent=True, # same input value -> same surrogate within the run
seed=42, # reproducible across runs (implies consistent=True)
keep_mapping=True,
)
print(deid.deidentified_text)
restored = openmed.reidentify(deid.deidentified_text, deid.mapping)
consistent=True keeps surrogates stable so analytics on the pseudonymized text
stay coherent; seed makes them reproducible. Either way, reversal still requires
the saved mapping.
Store the mapping securely — separate from the text
The mapping is the re-identification key. Treat it like a secret:
- Never write it to the same store/file/log as the de-identified text.
- Encrypt at rest; restrict access; audit every reversal.
- Key the store by an opaque document id, not by any patient identifier.
import json, os
import openmed
note = "Patient John Doe (MRN 00481726), DOB 1970-01-15."
deid = openmed.deidentify(note, method="mask", keep_mapping=True, seed=7)
doc_id = "doc-7f3a" # opaque id, no PHI
# De-identified text -> general processing store (safe to share downstream)
with open(f"deid/{doc_id}.txt", "w", encoding="utf-8") as fh:
fh.write(deid.deidentified_text)
# Mapping -> SEPARATE, access-controlled, encrypted vault (illustrative path)
os.makedirs("vault", exist_ok=True)
with open(f"vault/{doc_id}.map.json", "w", encoding="utf-8") as fh:
json.dump(deid.mapping, fh) # encrypt this store in production
To re-identify later, load only the mapping for the authorized doc_id:
import json, openmed
with open("vault/doc-7f3a.map.json", encoding="utf-8") as fh:
mapping = json.load(fh)
with open("deid/doc-7f3a.txt", encoding="utf-8") as fh:
safe_text = fh.read()
original = openmed.reidentify(safe_text, mapping)
Reversible vs irreversible: pick deliberately
| Goal | Call | Mapping |
|---|---|---|
| GDPR pseudonymization (reversible) | deidentify(..., keep_mapping=True, policy="gdpr_pseudonymization") |
keep, encrypted, separate |
| HIPAA Safe Harbor anonymization | deidentify(..., method="remove", policy="hipaa_safe_harbor") |
none |
| Irreversible token linking | `deidenti |
よくある質問
真に匿名で公開するデータに使えますか?
いいえ。再識別の対応表は匿名化を無効にするので、対応表のない除去の方法を使います。
対応表はどこに保存しますか?
匿名化された出力とは別の場所です。対応表こそが秘密だからです。
すべて端末上で動きますか?
はい。すべてが端末上で動くと、スキルは説明しています。
詳細
作者による元の説明
Reversibly de-identify clinical text with OpenMed and later restore the original PHI from a saved mapping. Use when the user needs pseudonymization rather than permanent anonymization, wants to mask PHI now and re-link it later under authorization (e.g. recontact, adjudication, GDPR pseudonymization), asks about deidentify keep_mapping, reidentify, or how to store and protect the re-identification mapping. Covers when reversibility is and is not appropriate (pseudonymization vs HIPAA Safe Harbor anonymization). Pairs after extracting-pii-entities and deidentifying-clinical-text.
repo: maziyarpanahi/openmed
人気
- GitHubのスター
- 5.8k
- ランキング
- #14724
- ライセンス
- Apache-2.0
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
annotating-variants
5.8kエージェントが、無料の公開アノテーターを使って、遺伝子バリアントの作用を予測し、HGVS名をゲノム上の位置に変換し、集団の頻度を付与できるよう支援します。
ask-openmed
5.8kエージェントが、臨床テキストの依頼に合ったOpenMedのワークフローを選べるよう支援します。患者データが含まれる可能性がある場合は、必ずプライバシーの確認から始めます。
assembling-fhir-bundles
5.8kエージェントが、複数のFHIR健康記録を、内部の参照を正しくつないだ一つのトランザクションBundleにまとめ、EHRに送れる状態にします。
auditing-deid-leakage
5.8kエージェントが、匿名化済みの臨床テキストに残っている識別子(SSN、カード番号、メール、日付など)をスキャンし、残っていれば公開を止めます。
似ているスキル
gitcrawl
394k保存されたGitHubのイシューとプルリクエストのアーカイブを検索し、重複をまとめ、GitHub上の現在の状態を確認するようエージェントを支援します。
slacrawl
394kローカルのSlackアーカイブ内のメッセージを検索して件数を数え、アーカイブの新しさを確認し、必要に応じて更新するようエージェントを支援します。
goplaces
394kGoogle Placesを使って、場所を検索し、詳細や口コミを取得し、場所の名前を解決するようエージェントを支援します。スクリプト用にJSON出力もできます。