Skip to main content
Glama

phiguard

Zero-dependency PHI de-identification, pseudonymization, and compliance guardrails for HL7 FHIR R4/R5, HL7 v2.x, Vietnam MOH QĐ 130/4750 BHYT XML, Japan APPI / JP-Core, and US HIPAA Safe Harbor — 100% offline.

CI Live Playground Zero Dependencies Node >= 20 License: MIT

npx phiguard scan ./clinical-fixtures

Try the 100% Offline Browser Playground — inspect, de-identify, validate, and re-hydrate FHIR R4 Bundles, HL7v2 messages, and Vietnam QĐ 4750 XML directly in your browser with zero uploads and zero network calls.


Why phiguard?

Healthcare engineering teams adopting AI agents and building EHR/HIS pipelines hit four immediate failure modes when using generic regex redactors or heavy Python NLP servers:

  1. Broken Clinical Structure — Naive [REDACTED] replacement corrupts FHIR Bundle cross-resource Reference links (Patient/123), shifts pipe positions in HL7 v2 PID/PV1/OBX, and misses Base64-encoded XML inside <NOIDUNGFILE> in Vietnam QĐ 4750 GIAMDINHHS claims.

  2. Narrative & Edge-Case Leakage — Stripping Patient.name while leaving Patient.text.div XHTML narratives, 5-digit ZIP codes in the 17 restricted HIPAA Safe Harbor ZIP-3 areas (830xx -> 00000), or birth years revealing age >89 fails compliance audits.

  3. Lost Context for Downstream AI — Replacing every person with [NAME] destroys co-reference ([PATIENT_01] vs [PRACTITIONER_01]), and stripping every date destroys length-of-stay intervals unless dates are shifted deterministically per subject.

  4. Zero Cloud Trust for Clinical Data — Security teams cannot send real or borderline clinical fixtures to commercial APIs or install 40-package dependency trees just to audit prompts, tests, or MCP payloads.


Related MCP server: Payment Intelligence

Key Capabilities

Capability

US HIPAA Safe Harbor

Vietnam MOH QĐ 130/4750

Japan APPI / JP-Core

Checksums & Formats

SSN, NPI (80840 Luhn), DEA check-digit, Medicare MBI, 17 ZIP-3 regions

15-char BHYT (42 prefixes), 12-digit CCCD (001–096), +84/VN phone, XML1–XML15 + Base64 <NOIDUNGFILE>

12-digit MyNumber (個人番号 Mod-11), postal 〒, JP phone, 患者氏名 / カルテ番号

FHIR R4/R5 AST & Bulk NDJSON

Consistent id/Reference rewriting (JSON Bundles & .ndjson $export streams), text.div XHTML & Base64 Attachment.data scrubbing, meta.security, age > 89 -> 1900

BHYT/CCCD identifiers, localized clinic labels & narrative scrubbing

JP-Core patient/practitioner names, Karte IDs, MyNumber identifiers

HL7 v2.x (ADT/ORU)

Preserves MSH delimiters; scrubs PID, NK1, GT1, IN1, PV1, OBR, OBX, NTE

Free-text Vietnamese PHI inside OBX-5 / NTE-3

Free-text Japanese PHI inside OBX-5 / NTE-3

De-identification Modes

redact, pseudonymize (HMAC-SHA256 TokenVault), date-shift (exact interval preservation)

Same + round-trip Base64 XML preservation

Same + consistent entity tokens

CI/CD & AI Agent Integration

SARIF 2.1.0, Markdown, JUnit XML, JSON, --fail-on, --min-score, GitHub Action @v1, Stdio MCP Server

Same

Same


Quick Start

# Audit files or directories across all profiles (exit 1 if >= high severity)
npx phiguard scan ./fixtures --profile all --fail-on high

# Export SARIF 2.1.0 or Markdown compliance reports
npx phiguard scan ./fixtures --sarif -o phiguard.sarif
npx phiguard scan ./fixtures --markdown --summary-only -o COMPLIANCE.md

# De-identify FHIR R4 Bundle with deterministic date shifting & HMAC-signed TokenVault
npx phiguard clean patient-bundle.json \
  --profile hipaa \
  --mode date-shift \
  --secret "$VAULT_SECRET" \
  --vault-out vault.json \
  -o patient-bundle.safe.json

# Restore authorized records using the HMAC-verified TokenVault
npx phiguard reidentify patient-bundle.safe.json --vault vault.json --secret "$VAULT_SECRET"

# Clean FHIR Bulk Data ($export .ndjson) preserving cross-line Patient/Encounter references
npx phiguard clean bulk-export.ndjson --profile hipaa --mode pseudonymize -o bulk-export.safe.ndjson

# Clean clinical EHR CSV/TSV exports while preserving numeric vitals/labs & per-patient date intervals
npx phiguard clean patient-cohort.csv --profile hipaa --mode date-shift -o patient-cohort.safe.csv

# Batch-deidentify an entire directory of clinical files sharing a single TokenVault
npx phiguard clean-dir ./clinical-fixtures -o ./clinical-safe --vault-out vault.json

# Validate FHIR R4 structural referential integrity + HIPAA Safe Harbor compliance
npx phiguard validate patient-bundle.safe.json --profile hipaa

# Clean Vietnam MOH QD 4750 BHYT XML (including Base64 NOIDUNGFILE payloads)
npx phiguard clean claim-4750.xml --profile vn-byt --mode pseudonymize -o claim-4750.safe.xml

# Install Git pre-commit (--staged) + Claude Code PreToolUse PHI blocker + .mcp.json
npx phiguard guard install

# Generate a dynamic Shields.io compliance badge for your README
npx phiguard scan ./fixtures --badge

Preventative Hooks (phiguard guard & .pre-commit-hooks.yaml)

Stop unredacted PHI before it enters git history or an AI coding assistant transcript:

  • Pre-commit Framework (.pre-commit-hooks.yaml) — supports repo: https://github.com/tranhoangtu-it/phiguard (phiguard and phiguard-hipaa hooks).

  • Git pre-commit Hook — runs npx --no-install phiguard scan --staged --fail-on high automatically on staged clinical fixtures, JSON, HL7, and XML files.

  • Claude Code PreToolUse Hook (phiguard guard-check) — evaluates Read|Edit|Write|MultiEdit|Bash payloads on stdin and exits with code 2 if high/critical unredacted PHI is present.

  • .mcp.json Registration — configures the stdio phiguard MCP server alongside existing servers without overwriting them.


MCP Server (Claude Desktop, Cursor, VS Code, Codex, Gemini CLI)

Expose all 5 local-first guardrails (phiguard_scan, phiguard_deidentify, phiguard_reidentify, phiguard_validate_fhir, phiguard_rules) over stdio JSON-RPC 2.0:

{
  "mcpServers": {
    "phiguard": {
      "command": "npx",
      "args": ["-y", "phiguard", "mcp"]
    }
  }
}

Or manage/install alongside your existing stack via mcphub and mcpman.


GitHub Action (@v1)

- name: PHI Compliance Gate
  uses: tranhoangtu-it/phiguard@v1
  with:
    target: "./src"
    profile: "hipaa"
    fail-on: "high"
    sarif-file: "phiguard.sarif"

TypeScript / JavaScript SDK (Node & Browser)

import { deidentify, reidentify, scan, validateFhirHipaa } from "phiguard";

const audit = scan(fhirBundleJson, { profile: "hipaa" });
const { output, vault } = deidentify(fhirBundleJson, {
  profile: "hipaa",
  mode: "pseudonymize",
  secret: "clinic-hmac-key",
});

const validation = validateFhirHipaa(output, "hipaa");
console.log(validation.hipaaCompliant, validation.score); // true, 100

const restored = reidentify(output, vault, "clinic-hmac-key");

  • dicomguard — Zero-dependency binary DICOM Part 10 inspector, NEMA PS3.15 de-identifier, burned-in PHI risk detector & MCP server (Live Playground).

  • clawleak — Find, losslessly redact, and block plaintext API keys/secrets leaked into AI coding agents (0 deps, 100% offline).

  • mcphub — Curated hub & CLI for verified MCP servers.

  • mcpman — Universal package manager & security auditor for MCP servers.


License

MIT. See LICENSE.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Enables coding assistants to check code for common health-data mistakes locally without an account, and, with a configured core service, de-identify clinical text, restore placeholders, and append tamper-evident audit log entries.
      1
      6 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI assistants to explain, scrub and check ISO 20022 payment messages and SSI files entirely on the local machine, including CBPR+ readiness hints, lifecycle triage, IBAN/BIC validation and payment-vs-SSI checks against the user's own licensed reference data. Runs as a local stdio MCP server with no network calls, telemetry or bundled vendor data.
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Exposes 24 evidence-grounded medical skills as JSON-RPC tools over stdio, letting agents run deterministic clinical calculators, PHI de-identification, negation-preserving multilingual parsing, and drug interaction checks locally with no token cost. It also enforces provenance and safety gates so high-risk dosing or prescribing decisions require documented clinical records rather than model inference.
      10
      8
      47 npm
      1
      Apache 2.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI clients to perform sandboxed file-system operations, read-only SQLite querying and schema inspection, environment diagnostics, and cryptographic hashing over Stdio or HTTP using JSON-RPC.
      2
      MIT