Privacy-first PII/PHI sanitization for Medical AI Agents (Python Version).
Project description
MedShield-Py 🛡️
Professional PII/PHI Sanitization for Medical AI Agents (Python Version)
MedShield-Py is a high-performance, privacy-first library designed to protect sensitive patient data in AI-driven healthcare workflows. It mirrors the architecture of medshield-js, providing a consistent privacy layer across your entire stack.
🚀 Key Features
- Deterministic Tokenization: Replaces sensitive data (e.g., John Doe) with persistent IDs (e.g.,
[PERSON_0]) to maintain clinical context across conversation turns. - Medical Context Preservation: Automatically detects and preserves medical codes (ICD-10, RXNORM) while scrubbing PII/PHI.
- Agentic Middleware: Drop-in integrations for LangChain, OpenAI, and newer AI frameworks.
- Synthetic Data Engine: Replaces real data with medically plausible fake data for developer environments.
📦 Installation
pip install medshield-py
🛠️ Quick Start
Basic Sanitization
from medshield import sanitize
text = "Patient John Doe (SSN: 123-45-6789) has asthma."
clean_text = sanitize(text)
# Output: "Patient [PERSON_0] (SSN: [SSN_0]) has asthma."
LangChain Integration
from medshield.integrations.langchain import MedShieldTransformer
from langchain_community.document_loaders import TextLoader
loader = TextLoader("patient_record.txt")
docs = loader.load()
# Sanitize all documents before indexing into a Vector DB
sanitizer = MedShieldTransformer(options={"level": "SYNTHESIZE"})
sanitized_docs = sanitizer.transform_documents(docs)
Managed Session (Deterministic)
from medshield import Sanitizer
s = Sanitizer(options={"level": "MASK"})
print(s.sanitize("Call John at 555-0101")) # [PERSON_0] at [PHONE_0]
print(s.sanitize("Is John home?")) # Is [PERSON_0] home? (Identifies same person)
🛡️ Sanitization Levels
MASK(Default): Replaces data with consistent tokens like[PERSON_0].SYNTHESIZE: Replaces real data with plausible fakes (e.g., "John Doe" -> "Robert Smith").REDACT: Simple redaction with type labels like[PERSON].
📜 License
Apache License 2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file medshield_py-0.1.0.tar.gz.
File metadata
- Download URL: medshield_py-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96ae744ee8512d50a6af8c107920e6988e399147647260d8157549d9881acdd6
|
|
| MD5 |
8f8970c63b95029357cc97c488cf4c60
|
|
| BLAKE2b-256 |
2b54a72266552b6b5c9eb4507984e95f00ba1ac49dea863b7010420b543b0f74
|
Provenance
The following attestation bundles were made for medshield_py-0.1.0.tar.gz:
Publisher:
ci.yml on Amir-Benhadid/medshield-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
medshield_py-0.1.0.tar.gz -
Subject digest:
96ae744ee8512d50a6af8c107920e6988e399147647260d8157549d9881acdd6 - Sigstore transparency entry: 1345099343
- Sigstore integration time:
-
Permalink:
Amir-Benhadid/medshield-py@1e99191a122e28a733cf7ee563efcd0b4143098b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Amir-Benhadid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@1e99191a122e28a733cf7ee563efcd0b4143098b -
Trigger Event:
push
-
Statement type:
File details
Details for the file medshield_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: medshield_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20389764da27707f87e299b1ad59a1d99cae8a152acea08807df08dbcf288f21
|
|
| MD5 |
f242dd4427f6489174f7ff1e8470a51e
|
|
| BLAKE2b-256 |
6501af9fc7d39b4d8e43a34168283fcb5eeaeaa31d04636f3e19e6492e5d607c
|
Provenance
The following attestation bundles were made for medshield_py-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on Amir-Benhadid/medshield-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
medshield_py-0.1.0-py3-none-any.whl -
Subject digest:
20389764da27707f87e299b1ad59a1d99cae8a152acea08807df08dbcf288f21 - Sigstore transparency entry: 1345099407
- Sigstore integration time:
-
Permalink:
Amir-Benhadid/medshield-py@1e99191a122e28a733cf7ee563efcd0b4143098b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Amir-Benhadid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@1e99191a122e28a733cf7ee563efcd0b4143098b -
Trigger Event:
push
-
Statement type: