bridging-presidio-and-spacy
What it does
This skill links OpenMed clinical text tools to Presidio, spaCy and LangChain, popular tools for personal data detection and language apps. It is for developers who already run one of those tools and want OpenMed inside it.
When to use it
- βWhen you already run Microsoft Presidio and want OpenMed clinical PII detection added to it.
- βWhen your spaCy pipeline should produce OpenMed personal data spans.
- βWhen you build LangChain chains and want patient data removed before text reaches a language model.
Skill link
https://github.com/maziyarpanahi/openmed/blob/master/skills/bridging-presidio-and-spacy/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βI already use Microsoft Presidio. Add OpenMed clinical PII detection to my Presidio pipeline.β
5 new skills a week. 1 minute to read.
How it works
The agent installs only the extra needed for the chosen tool, then uses the matching adapter to convert between OpenMed results and that tool's format.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Bridging Presidio, spaCy & LangChain
OpenMed interoperates with the dominant PII/NLP ecosystems through a single,
lazy adapter registry: openmed.interop. Adapters live behind explicit
imports, so importing openmed never drags in Presidio, spaCy, or LangChain β
each is an optional extra you install only when you need that bridge.
When to use
Reach for a bridge when:
- you already run Microsoft Presidio and want OpenMed's clinical PII recall on top (or to feed OpenMed spans back into Presidio's anonymizer);
- you have a spaCy pipeline and want OpenMed PII spans on the
Doc; - you build LangChain chains and want to redact PHI before text reaches an LLM (the on-device guardrail in front of a cloud model);
- you need OpenMed's de-identification reachable from an existing framework
instead of rewriting the pipeline around
openmed.deidentify.
The lazy adapter registry (verified)
import openmed.interop as interop
interop.available_adapters()
# ('cda', 'hl7v2', 'langchain', 'presidio', 'spacy')
spec = interop.adapter_spec("presidio")
# AdapterSpec(name='presidio', module='openmed.interop.presidio',
# extra='presidio', description='Presidio RecognizerResult adapter')
mod = interop.get_adapter("presidio") # imports openmed.interop.presidio
# Attribute access also works lazily:
openmed.interop.presidio # same module, imported on first touch
available_adapters() and adapter_spec() never import the adapter module, so
they are safe to call for discovery even without the extra installed.
get_adapter(name) (and attribute access) triggers the import β and the
adapter's own optional dependency.
Install only the extra you need:
pip install "openmed[presidio]" # Presidio RecognizerResult adapter
pip install "openmed[spacy]" # spaCy openmed_deid component
pip install "openmed[langchain]" # LangChain redaction runnable
# cda and hl7v2 adapters ship in core (no extra) β see their own skills
Presidio bridge (verified callables)
Module openmed.interop.presidio converts between Presidio
RecognizerResults and OpenMed canonical PIIEntitys, and merges both
detectors through OpenMed's semantic-unit merger.
from openmed.interop.presidio import (
to_canonical, # RecognizerResult(s) -> [PIIEntity]
from_canonical, # [PIIEntity] -> [RecognizerResult] (needs presidio extra)
merge_with_openmed, # combine OpenMed + Presidio spans, resolve overlaps
PresidioAdapterConfig,
)
import openmed
text = "Dr. Smith called patient at 617-555-0123 on 2024-03-02."
# Presidio gives you RecognizerResults; OpenMed gives PIIEntities.
openmed_spans = openmed.extract_pii(text).entities
presidio_results = analyzer.analyze(text=text, language="en") # your Presidio analyzer
merged = merge_with_openmed(
openmed_spans, presidio_results, text=text,
config=PresidioAdapterConfig(preserve_presidio_labels=True),
)
# -> de-duplicated [PIIEntity]; overlaps resolved by score, length, OpenMed-origin
Why merge instead of union: merge_with_openmed runs both detectors' spans
through merge_entities_with_semantic_units, so overlapping/adjacent detections
collapse into one correct span (e.g. PHONE from Presidio vs a partial OpenMed
hit) rather than producing double redactions. Label mapping is built in
(Presidio PHONE_NUMBER β OpenMed PHONE, US_SSN β SSN, etc.).
To push OpenMed spans into Presidio's anonymizer, convert back:
results = from_canonical(openmed_spans) # [RecognizerResult]
anonymized = anonymizer.anonymize(text=text, analyzer_results=results)
spaCy bridge (verified factory)
Module openmed.interop.spacy_component registers a spaCy pipeline factory
named openmed_deid. Add it to a pipeline and OpenMed PII spans land on the
Doc.
import spacy
import openmed.interop.spacy_component # registers the @Language.factory
nlp = spacy.blank("en")
nlp.add_pipe("openmed_deid", config={
"confidence_threshold": 0.5,
"lang": "en",
"target": "openmed_pii", # doc.spans key
"merge_ents": False, # set True to also write doc.ents
"alignment_mode": "expand", # char->token alignment: strict|contract|expand
})
doc = nlp("Patient John Doe, MRN 12345, seen today.")
for span in doc.spans["openmed_pii"]:
print(span.label_, span.text)
# raw char-offset spans also available on doc._.openmed_pii
`merge
FAQ
Will installing OpenMed load all three tools?
No. Each bridge is an optional extra, so you install only the one you need.
Can OpenMed spans go back into Presidio?
Yes. The skill covers converting results back and forth with Presidio's format.
Is LangChain covered?
Yes. It covers redacting text before it reaches a language model.
Details
Original description by the author
Combine OpenMed clinical NLP with Microsoft Presidio, spaCy, or LangChain through OpenMed's built-in interop adapter registry (openmed.interop). Covers the lazy adapter registry (available_adapters, get_adapter, adapter_spec), the presidio/spacy/langchain pip extras, and the verified callables β Presidio to_canonical/from_canonical/merge_with_openmed, the spaCy openmed_deid pipeline factory, and the LangChain create_redaction_runnable. Use when the user wants to add Presidio recognizers, embed OpenMed PII detection in a spaCy pipeline, or use OpenMed de-identification as a LangChain runnable.
repo: maziyarpanahi/openmed
Popularity
- GitHub stars
- 5.8k
- Ranking position
- #14677
- License
- Apache-2.0
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
annotating-variants
5.8kHelps your agent predict what a genetic variant does, convert HGVS names to genome positions and attach population frequencies, using free public annotators.
ask-openmed
5.8kHelps your agent pick the right OpenMed workflow for a clinical text request, starting with a privacy check whenever patient data may be present.
assembling-fhir-bundles
5.8kPackages several FHIR health records into one transaction Bundle ready to send to an EHR, with the internal references linked correctly.
auditing-deid-leakage
5.8kScans de-identified clinical text for leftover identifiers such as SSNs, card numbers, emails and dates, and blocks release if any remain.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.