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 건강 기록을 EHR로 보낼 수 있도록 하나의 트랜잭션 Bundle로 묶고, 내부 참조를 올바르게 연결하도록 에이전트를 돕습니다.
auditing-deid-leakage
5.8k비식별화된 임상 텍스트에 남은 SSN, 카드 번호, 이메일, 날짜 같은 식별자를 검사하고, 남은 것이 있으면 공개를 막도록 돕습니다.
비슷한 스킬
gitcrawl
394k에이전트가 저장된 GitHub 이슈와 풀 리퀘스트 보관본을 검색하고, 중복 항목을 묶고, GitHub에서 현재 상태를 확인하도록 돕습니다.
slacrawl
394k에이전트가 로컬 Slack 보관본에서 메시지를 검색하고 개수를 세며, 보관본이 얼마나 최신인지 확인하고 필요할 때 새로 고치도록 돕습니다.
goplaces
394k에이전트가 Google Places로 장소를 검색하고, 세부 정보와 리뷰를 가져오고, 장소 이름을 확인하며, 스크립트용 JSON을 출력하도록 돕습니다.