De-identifying multilingual text
OpenMed de-identifies clinical text in many languages, each with a dedicated
PII model, language-specific regex patterns (national IDs, phone formats), and a
locale-aware surrogate generator. Pass lang= to deidentify / extract_pii
and the right model, patterns, and fake-data tables are selected automatically.
Everything runs on-device.
When to use this skill
Use it whenever the source text is not English, or when surrogates must look
native to the locale (a German note should get German-looking fake names and a
valid-format Steuer-ID surrogate, not a US SSN).
Discover supported languages at runtime — don't hardcode
import openmed
from openmed.core.pii_i18n import SUPPORTED_LANGUAGES, get_patterns_for_language
print(sorted(SUPPORTED_LANGUAGES)) # query it; the set is the source of truth
# Language-appropriate default model for a code:
models = openmed.get_pii_models_by_language("es")
# Language-specific regex patterns (national IDs, phones, etc.):
patterns = get_patterns_for_language("de")
The set currently spans English plus European, South Asian, Middle Eastern, and
East Asian languages — but always read SUPPORTED_LANGUAGES rather than
trusting a number, since it changes as models ship. MCP exposes the same list
via openmed_list_pii_languages.
Quick start (Spanish)
import openmed
nota = (
"El paciente Carlos Hernández (DNI 12345678Z), nacido el 11/04/1979, "
"vive en Calle Mayor 5, Madrid. Teléfono 612 345 678."
)
result = openmed.deidentify(
nota,
lang="es", # selects the Spanish PII model + ES patterns
method="replace", # locale-native fake values
locale="es_ES", # Faker locale (defaults from lang via LANG_TO_LOCALE)
)
print(result.deidentified_text)
# El paciente [surrogate name] (DNI [surrogate]), nacido el [date], ...
For German, just switch the code:
befund = "Patientin Anna Müller, geb. 11.04.1979, Steuer-ID 12 345 678 901."
result = openmed.deidentify(befund, lang="de", method="replace")
Workflow
- Confirm the language is supported by checking
SUPPORTED_LANGUAGES.
- Pass
lang= to deidentify/extract_pii. This selects the
language-specific model (via get_pii_models_by_language) and the regex
pattern set (via get_patterns_for_language) for national IDs and formats.
- Set
locale= for surrogates when method="replace". If omitted, the
locale is derived from lang through LANG_TO_LOCALE (e.g. pt→pt_PT).
Override for regional variants (pt_BR, en_GB, Gulf/Levant Arabic).
- Let accent normalization happen. For models trained on accent-free text
(Spanish),
deidentify auto-strips diacritics before inference and maps
spans back to the original accented text. You normally do not set
normalize_accents yourself.
- Keep surrogates stable across a document with
consistent=True, seed=....
Language-specific national IDs
The pattern sets encode and the validators check real national identifier
formats and checksums, so structured IDs are caught even when the model is
unsure. Examples available in openmed.core.pii_i18n:
| Language |
Identifier |
Validator |
| French |
NIR / INSEE |
validate_french_nir |
| German |
Steuer-ID |
validate_german_steuer_id |
| Italian |
Codice Fiscale |
validate_italian_codice_fiscale |
| Spanish |
DNI / NIE |
validate_spanish_dni, validate_spanish_nie |
| Dutch |
BSN |
validate_dutch_bsn |
| Hindi |
Aadhaar |
validate_aadhaar |
| Portuguese |
CPF / CNPJ |
validate_portuguese_cpf, validate_portuguese_cnpj |
| Turkish |
TCKN |
validate_turkish_tckn |
These map to OpenMed CANONICAL_LABELS (ID_NUM, SSN) and are redacted by
the same policy actions as any other identifier.
Hand-off to / from OpenMed
- Core de-id:
deidentifying-clinical-text — methods, thresholds,
keep_mapping, policies (all accept lang/locale).
- Surrogates:
generating-synthetic-surrogates — locale-native fakes and
custom providers per language.
- Policies:
configuring-privacy-policies — policy= works with any lang.
- Audit:
auditing-deidentification-runs records the model and language in
the no-PHI report.
- Other surfaces: MCP
openmed_deidentify / openmed_list_pii_languages;
REST POST /pii/deidentify (both take a language parameter).
Edge cases & gotchas
- Never run the English model on other languages. Recall collapses. Always
pass
lang=; the default model is English only.
lang ≠ locale. lang picks the detection model and patterns;
locale shapes the replacement fakes. Set both when surrogate realism
matters (e.g. lang="pt", locale="pt_BR").
- Some locales are approximations. Faker has no Telugu locale, so OpenMed
maps
te→en_IN and warns once. Override locale= if you need closer
regional surrogates.
- Date order varies. Day-first languages (fr, de, it, es, nl, pt, …) parse
11/04/1979 as 11 April; the date logic is language-aware — keep lang set
when shifting dates.
- Mixed-language notes (e.g. English headers in a Spanish chart) may lower
recall; verify residual risk with
audit=True and consider a second pass.
- No raw PHI in logs regardless of language — offsets, labels, hashes only.
Standards & references
- HIPAA de-identification, 45 CFR 164.514(b) (US) and GDPR / national DPAs for
EU subjects: https://www.hhs.gov/hipaa/for-professionals/privacy/special-topics/de-identification/index.html
- National ID format references are encoded in OpenMed validators (no external
registry bundled).
- OpenMed source:
openmed/core/pii_i18n.py (SUPPORTED_LANGUAGES,
get_patterns_for_language, validators), openmed/core/model_registry.py
(get_pii_models_by_language), openmed/core/anonymizer/locales.py
(LANG_TO_LOCALE).
1---2name: deidentifying-multilingual-text3description: De-identify non-English clinical text on-device with OpenMed by passing lang= and locale= to deidentify(). Use when the user has Spanish, German, French, Italian, Portuguese, Dutch, Hindi, Telugu, Arabic, Japanese, or Turkish medical notes, needs locale-aware fake surrogates, must handle language-specific national IDs (DNI, NIR, Steuer-ID, codice fiscale, BSN, CPF, TCKN, Aadhaar), or asks which languages OpenMed PII supports. Covers SUPPORTED_LANGUAGES, get_pii_models_by_language, get_patterns_for_language, LANG_TO_LOCALE, and accent normalization. Pairs with OpenMed deidentifying-clinical-text and generating-synthetic-surrogates.4license: Apache-2.05---67# De-identifying multilingual text89OpenMed de-identifies clinical text in many languages, each with a dedicated10PII model, language-specific regex patterns (national IDs, phone formats), and a11locale-aware surrogate generator. Pass `lang=` to `deidentify` / `extract_pii`12and the right model, patterns, and fake-data tables are selected automatically.13Everything runs **on-device**.1415## When to use this skill1617Use it whenever the source text is not English, or when surrogates must look18native to the locale (a German note should get German-looking fake names and a19valid-format Steuer-ID surrogate, not a US SSN).2021## Discover supported languages at runtime — don't hardcode2223```python24import openmed25from openmed.core.pii_i18n import SUPPORTED_LANGUAGES, get_patterns_for_language2627print(sorted(SUPPORTED_LANGUAGES)) # query it; the set is the source of truth28# Language-appropriate default model for a code:29models = openmed.get_pii_models_by_language("es")30# Language-specific regex patterns (national IDs, phones, etc.):31patterns = get_patterns_for_language("de")32```3334The set currently spans English plus European, South Asian, Middle Eastern, and35East Asian languages — but **always read `SUPPORTED_LANGUAGES`** rather than36trusting a number, since it changes as models ship. MCP exposes the same list37via `openmed_list_pii_languages`.3839## Quick start (Spanish)4041```python42import openmed4344nota = (45 "El paciente Carlos Hernández (DNI 12345678Z), nacido el 11/04/1979, "46 "vive en Calle Mayor 5, Madrid. Teléfono 612 345 678."47)4849result = openmed.deidentify(50 nota,51 lang="es", # selects the Spanish PII model + ES patterns52 method="replace", # locale-native fake values53 locale="es_ES", # Faker locale (defaults from lang via LANG_TO_LOCALE)54)55print(result.deidentified_text)56# El paciente [surrogate name] (DNI [surrogate]), nacido el [date], ...57```5859For German, just switch the code:6061```python62befund = "Patientin Anna Müller, geb. 11.04.1979, Steuer-ID 12 345 678 901."63result = openmed.deidentify(befund, lang="de", method="replace")64```6566## Workflow67681. **Confirm the language is supported** by checking `SUPPORTED_LANGUAGES`.692. **Pass `lang=`** to `deidentify`/`extract_pii`. This selects the70 language-specific model (via `get_pii_models_by_language`) *and* the regex71 pattern set (via `get_patterns_for_language`) for national IDs and formats.723. **Set `locale=` for surrogates** when `method="replace"`. If omitted, the73 locale is derived from `lang` through `LANG_TO_LOCALE` (e.g. `pt`→`pt_PT`).74 Override for regional variants (`pt_BR`, `en_GB`, Gulf/Levant Arabic).754. **Let accent normalization happen.** For models trained on accent-free text76 (Spanish), `deidentify` auto-strips diacritics before inference and maps77 spans back to the *original* accented text. You normally do not set78 `normalize_accents` yourself.795. **Keep surrogates stable** across a document with `consistent=True, seed=...`.8081## Language-specific national IDs8283The pattern sets encode and the validators check real national identifier84formats and checksums, so structured IDs are caught even when the model is85unsure. Examples available in `openmed.core.pii_i18n`:8687| Language | Identifier | Validator |88| --- | --- | --- |89| French | NIR / INSEE | `validate_french_nir` |90| German | Steuer-ID | `validate_german_steuer_id` |91| Italian | Codice Fiscale | `validate_italian_codice_fiscale` |92| Spanish | DNI / NIE | `validate_spanish_dni`, `validate_spanish_nie` |93| Dutch | BSN | `validate_dutch_bsn` |94| Hindi | Aadhaar | `validate_aadhaar` |95| Portuguese | CPF / CNPJ | `validate_portuguese_cpf`, `validate_portuguese_cnpj` |96| Turkish | TCKN | `validate_turkish_tckn` |9798These map to OpenMed `CANONICAL_LABELS` (`ID_NUM`, `SSN`) and are redacted by99the same policy actions as any other identifier.100101## Hand-off to / from OpenMed102103- **Core de-id:** `deidentifying-clinical-text` — methods, thresholds,104 `keep_mapping`, policies (all accept `lang`/`locale`).105- **Surrogates:** `generating-synthetic-surrogates` — locale-native fakes and106 custom providers per language.107- **Policies:** `configuring-privacy-policies` — `policy=` works with any `lang`.108- **Audit:** `auditing-deidentification-runs` records the model and language in109 the no-PHI report.110- **Other surfaces:** MCP `openmed_deidentify` / `openmed_list_pii_languages`;111 REST `POST /pii/deidentify` (both take a language parameter).112113## Edge cases & gotchas114115- **Never run the English model on other languages.** Recall collapses. Always116 pass `lang=`; the default model is English only.117- **`lang` ≠ `locale`.** `lang` picks the *detection* model and patterns;118 `locale` shapes the *replacement* fakes. Set both when surrogate realism119 matters (e.g. `lang="pt", locale="pt_BR"`).120- **Some locales are approximations.** Faker has no Telugu locale, so OpenMed121 maps `te`→`en_IN` and warns once. Override `locale=` if you need closer122 regional surrogates.123- **Date order varies.** Day-first languages (fr, de, it, es, nl, pt, …) parse124 `11/04/1979` as 11 April; the date logic is language-aware — keep `lang` set125 when shifting dates.126- **Mixed-language notes** (e.g. English headers in a Spanish chart) may lower127 recall; verify residual risk with `audit=True` and consider a second pass.128- **No raw PHI in logs** regardless of language — offsets, labels, hashes only.129130## Standards & references131132- HIPAA de-identification, 45 CFR 164.514(b) (US) and GDPR / national DPAs for133 EU subjects: https://www.hhs.gov/hipaa/for-professionals/privacy/special-topics/de-identification/index.html134- National ID format references are encoded in OpenMed validators (no external135 registry bundled).136- OpenMed source: `openmed/core/pii_i18n.py` (`SUPPORTED_LANGUAGES`,137 `get_patterns_for_language`, validators), `openmed/core/model_registry.py`138 (`get_pii_models_by_language`), `openmed/core/anonymizer/locales.py`139 (`LANG_TO_LOCALE`).