extracting-pii-entities
できること
このスキルは、臨床テキストの中の個人の識別子と健康上の識別子、たとえば名前、日付、記録番号を見つけ、その位置を報告します。テキストは変更しません。取り除く前に識別子を確認したい人向けです。
使う場面
- ✓テキストを変えずに、識別子とその位置を見つけたいとき。
- ✓匿名化を実行する前に、何が取り除かれるかをプレビューしたいとき。
- ✓検出された識別子を、自分の伏せ字ツールに渡すか、標準のラベルに対応づける必要があるとき。
スキルのリンク
https://github.com/maziyarpanahi/openmed/blob/master/skills/extracting-pii-entities/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このノートにあるすべての名前、日付、電話番号を、位置とともに示してください。ただしテキストは変えないでください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは端末上で検出を実行し、各識別子をラベル、位置、信頼度とともに返します。必要であれば、ラベルを標準のセットに対応づけます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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):
ent.text # the identifier surface string, e.g. "617-555-0142"
ent.label # detected label, e.g. "PHONE"
ent.confidence # model score in [0, 1] (NOTE: .confidence, not .score)
ent.start / ent.end # character offsets into the original note
ent.canonical_label # label mapped to OpenMed's canonical taxonomy (if set)
ent.entity_type # same as label
The text is unchanged — result.text is your original input.
Signature & key parameters
openmed.extract_pii(
text,
model_name="OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1", # default EN model
confidence_threshold=0.5, # raise for precision, lower for recall
use_smart_merging=True, # merge fragmented spans into whole units
lang="en", # en es pt fr de it nl hi te ar tr ja
loader=None, # reuse a ModelLoader across calls
)
use_smart_merging=True(default) reassembles fragmented predictions into complete units (a full phone number, a full date) — keep it on.langselects the language-appropriate default model and regex patterns. Pass the right language; do not run the English model on non-English text. Useopenmed.get_default_pii_model(lang)to confirm coverage.
Normalize labels to the canonical taxonomy
Different models may emit slightly different label spellings. Normalize them to OpenMed's canonical set so downstream logic is stable:
import openmed
from openmed import CANONICAL_LABELS, normalize_label
result = openmed.extract_pii("Email jane.roe@example.org; SSN 123-45-6789.")
for ent in result.entities:
canon = ent.canonical_label or normalize_label(ent.label)
assert canon in CANONICAL_LABELS or canon == "OTHER"
print(ent.text, "->", canon)
CANONICAL_LABELS is a frozenset of UPPER_SNAKE_CASE labels (e.g. PERSON,
DATE, PHONE, EMAIL, SSN, ID_NUM, LOCATION). normalize_label(label)
accepts messy inputs ("FIRSTNAME", "first_name", "B-EMAIL") and maps unknown
labels to OTHER rather than raising.
Feed spans to a downstream redactor
extract_pii gives you offsets; you decide the action. A simple offset-based
redactor (replace highest-offset first so positions stay valid):
import openmed
note = "Patient John Doe, MRN 00481726, seen 2024-03-02."
result = openmed.extract_pii(note, confidence_threshold=0.6)
redacted = note
for ent in sorted(result.entities, key=lambda e: e.start, reverse=True):
redacted = redacted[:ent.start] + f"[{ent.label}]" + redacted[ent.end:]
print(redacted) # Patient [PERSON], MRN [ID_NUM], seen [DATE].
For production redaction, masking strategies, and policy profiles, hand the work
to openmed.deidentify instead of hand-rolling — it adds a safety sweep and
date-shifting (see `deidentifying-clinical-te
よくある質問
匿名化とはどう違いますか?
このスキルはスパンだけを返します。匿名化は、伏せられたテキストを生成します。
テキストは変わりますか?
いいえ。元のテキストはそのまま残ります。
信頼度を設定できますか?
はい。結果を信頼度で絞り込めます。
詳細
作者による元の説明
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.
repo: maziyarpanahi/openmed
人気
- GitHubのスター
- 5.8k
- ランキング
- #14702
- ライセンス
- 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、カード番号、メール、日付など)をスキャンし、残っていれば公開を止めます。
似ているスキル
reverse-engineer-anything
422kREAツールを使って、出荷済みのアプリやパッケージの中身を調べ、機能の説明、版の比較、再構築の手順をエージェントが支援します。
1password
394k1Password CLIをセットアップし、サインインして、秘密情報の値を会話に表示せずに読み取ったり注入したりするようエージェントを支援します。
healthcheck
394kOpenClawを動かすコンピューターやサーバーを、SSH、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。