Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

medshield_py-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

medshield_py-0.1.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

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

Hashes for medshield_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 96ae744ee8512d50a6af8c107920e6988e399147647260d8157549d9881acdd6
MD5 8f8970c63b95029357cc97c488cf4c60
BLAKE2b-256 2b54a72266552b6b5c9eb4507984e95f00ba1ac49dea863b7010420b543b0f74

See more details on using hashes here.

Provenance

The following attestation bundles were made for medshield_py-0.1.0.tar.gz:

Publisher: ci.yml on Amir-Benhadid/medshield-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for medshield_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20389764da27707f87e299b1ad59a1d99cae8a152acea08807df08dbcf288f21
MD5 f242dd4427f6489174f7ff1e8470a51e
BLAKE2b-256 6501af9fc7d39b4d8e43a34168283fcb5eeaeaa31d04636f3e19e6492e5d607c

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page