Skip to main content

ClinicSentry

Framework-agnostic compliance middleware for clinical AI agents

ClinicSentry is an open-source Python library that wraps any AI agent framework (LangGraph, CrewAI, Google ADK, OpenAI Agents SDK, Claude SDK, MCP, A2A) and enforces clinical-domain guardrails — without requiring changes to your existing agent code.

⚠️ Important disclaimers

  • ClinicSentry is not a medical device and is not FDA-cleared or CE-marked. Its controls align with HIPAA, FDA TPLC draft guidance, and IEC 62304 — alignment is not certification, and using this library does not make your system compliant by itself.
  • The default detectors catch structured identifiers (SSN, MRN, phone, email, dates, …) deterministically. Person-name detection requires the optional NER extras (pip install 'clinicsentry[phi]'); its recall on real clinical text is not yet characterized on a public benchmark.
  • Read RESPONSIBLE_USE.md before any deployment that touches real PHI or influences patient care.

Four Orthogonal Controls

Module What it does Regulatory alignment
PHI Firewall Detect, redact, and track PHI across agents HIPAA §164.502(b), §164.312
Clinical Escalation Router Risk-tier actions; route uncertain decisions to humans IEC 62304 §9, FDA TPLC §III.B
Regulatory Audit Trail Tamper-evident HMAC-signed hash chain of every event 21 CFR Part 11, HIPAA §164.312(b)
MedDevice Mode IEC 62304 Class A/B/C enforcement, dose-range checks, emergency stop IEC 62304 §5.1/§8, EU AI Act

Install

pip install clinicsentry            # core
pip install 'clinicsentry[all]'     # everything (Presidio, FHIR, OTEL, cloud KMS, …)

Extras: [postgres], [cloud-kms], [otel], [dashboard], [all]

Quick Example

from clinicsentry import ClinicSentry, ClinicalRiskTier

guard = ClinicSentry(framework="my-agent")

# 1. Scan input for PHI
scan = guard.firewall.scan(
    {"note": "Patient Jane Doe (MRN 12345678), SSN 123-45-6789"},
    origin_agent="intake",
)
print(scan.redacted)  # PHI replaced with [REDACTED:MRN], [REDACTED:SSN]

# 2. Register actions with risk tiers
@guard.register_action(
    tier=ClinicalRiskTier.ADVISORY,
    description="Summarize a clinical note",
    required_fields={"note"},
)
def summarize(payload: dict) -> str:
    return f"Summary ({len(payload['note'])} chars)"

# 3. Evaluate — router decides: proceed / escalate / block
decision = guard.evaluate_action(
    "summarize",
    output_text="Summary of visit note",
    reasoning_text="High confidence, structured input",
    provided_fields={"note"},
)
print(decision.action, decision.confidence)

# 4. End session → regulatory compliance report
report = guard.end_session(intended_use="clinical summarization")
print(report.compliance_attestation)

Or let the context manager guarantee the session boundary — SESSION_END is audited even if your pipeline raises:

with ClinicSentry(framework="my-agent") as guard:
    ...  # scans, evaluations, tool calls
# report available as guard.last_report

Risk Tiers

Tier Behavior Example
INFORMATIONAL Auto-proceed; audit logged "How do I use my device?"
ADVISORY Proceed with annotation; confidence score visible Triage patients by glucose trends
INTERVENTIONAL Auto-blocked; routed to human reviewer Adjust insulin dosing parameters

Unregistered actions escalate by default (fail closed) — see escalation.on_unregistered_action in the policy reference.

Fail-Safe by Default

  • Adversarial PHI detection on the production scan path: homoglyphs, zero-width characters, full-width forms, percent-encoding, and base64-encoded payloads are normalized with exact offset mapping, then redacted in the original text (ADR-0016). Plain-ASCII inputs take a no-overhead fast path (~0.7 ms p95 on 3 KB notes, pure Python, no extra LLM calls).
  • Whole-payload coverage: strings, dicts (keys included), lists, tuples, sets, UTF-8 bytes, FHIR/HL7/DICOM; nesting deeper than phi_firewall.max_depth is redacted wholesale rather than erroring.
  • Tamper-evident auditing under concurrency: thread-safe gapless sequencing, plus tail-truncation detection on verify().
  • Strict policy loading: typo'd keys and out-of-range values raise PolicyError at startup instead of silently disabling enforcement; CLINICSENTRY_* env overrides for containerized deployments.
  • MedDevice guardrails: undeclared dose parameters and non-finite values fail validation; rate limits use a true rolling 1-hour window.

CLI

clinicsentry demo                                    # seeded demo session
clinicsentry scan "Patient SSN 123-45-6789"          # one-shot PHI scan
clinicsentry verify ./audit.sqlite --secret <hex>    # verify audit chain
clinicsentry report ./audit.sqlite --session <id>    # compliance report
clinicsentry policy-validate examples/policy.yaml    # validate policy file

Bundled Compliance Frameworks

Framework Key rules
HIPAA PHI redacted, audit signed, chain integrity, minimum necessary
FDA TPLC Session boundaries, no sequence gaps, postmarket data capture
IEC 62304 Agent traceability, chain integrity, interventional escalation
EU AI Act Transparency, human oversight

All four are checked automatically by clinicsentry report.

Production Stack

# Postgres audit + S3 + OTEL + Grafana dashboard
docker compose -f deploy/compose/docker-compose.yml up

Open http://localhost:3000 (Grafana) or http://localhost:9001 (MinIO).

Documentation

Status, Versioning, and Support

v0.3.0 — pre-1.0 software (per-module status). SemVer: breaking changes only in minor releases until 1.0, always flagged in the CHANGELOG with migration notes. Only the latest minor release receives security fixes (security policy — PHI-detection bypasses are treated as vulnerabilities, reported privately).

How It Compares

ClinicSentry NeMo Guardrails / Guardrails AI Presidio
Clinical regulatory mapping (HIPAA / FDA TPLC / IEC 62304) built-in, rule DSL generic rails none
Tamper-evident audit chain HMAC hash chain logging only none
Risk-tiered human escalation built-in build your own none
Extra LLM calls on hot path zero often 1+ per check zero
PHI detection regex + adversarial normalization (+ optional Presidio/NER) delegate NER engine

Presidio is a complementary detector (we wrap it via [phi]); rails frameworks are complementary conversation shapers. ClinicSentry is the compliance enforcement and evidence layer between your agent and the world.

License

Apache-2.0. See LICENSE and NOTICE. Apache-2.0 permits commercial use, modification, and redistribution — including inside proprietary products.

Download files

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

Source Distribution

clinicsentry-0.4.0.tar.gz (216.5 kB view details)

Uploaded Source

Built Distribution

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

clinicsentry-0.4.0-py3-none-any.whl (141.1 kB view details)

Uploaded Python 3

File details

Details for the file clinicsentry-0.4.0.tar.gz.

File metadata

  • Download URL: clinicsentry-0.4.0.tar.gz
  • Upload date:
  • Size: 216.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clinicsentry-0.4.0.tar.gz
Algorithm Hash digest
SHA256 05c879767725a55a25bbd2b16fc0415a179d246f0906cffff2441ce87357c84b
MD5 a7ed1469814edf8d7d6296db0b5a75d4
BLAKE2b-256 5e361786a57214cfa2986ea0b0310fdee73aadf0e69961e4e6221d815e324b6c

See more details on using hashes here.

Provenance

The following attestation bundles were made for clinicsentry-0.4.0.tar.gz:

Publisher: release.yml on aakash1411/clinicsentry

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

File details

Details for the file clinicsentry-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: clinicsentry-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 141.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clinicsentry-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca027c8d4b8231ec89ddb1bd7d26e6bd531db1f0bdac57db9f4c820aa4b7a6e
MD5 4bdf39831a8b39be646db38747b36fb5
BLAKE2b-256 49fb5e7d27fcf56878c2af38782703e097c1fcf2a49f42c650fa5f4ee7e7209e

See more details on using hashes here.

Provenance

The following attestation bundles were made for clinicsentry-0.4.0-py3-none-any.whl:

Publisher: release.yml on aakash1411/clinicsentry

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

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 files

0.3.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page