Skip to content
reaatech

Files · Configurable PII redaction at ingress and egress for HIPAA, GDPR, and PCI compliance

82 (1 binary, 487.5 kB total)attempt 1

README.md·4785 B·markdown
markdown
# Configurable PII redaction at ingress and egress for HIPAA, GDPR, and PCI compliance
 
> Automatically strip PII from every LLM call and response, configurable per regulation.
 
## Problem
 
Clinical decision support agents process sensitive health information that must comply with HIPAA, GDPR, and PCI regulations. PII must be redacted before data enters an LLM (ingress) and again before responses are returned to users (egress), ensuring no protected health information (PHI) or personally identifiable information is leaked.
 
## Architecture
 
```
User Input → Ingress Guardrail Chain → LLM → Egress Guardrail Chain → User Output
                 │                          │                          │
          PIIRedaction (mask/remove)   PIIScan (verify redacted)   Redacted response
```
 
Ingress: `PIIRedaction` guardrail redacts PII using regulation-specific patterns (mask or remove strategy).
Egress: `PIIScan` guardrail verifies no PII leaked through and redacts any remaining matches.
Both chains are built with `ChainBuilder` from `@reaatech/guardrail-chain`, with configurable latency/token budgets and retry handling.
 
## Quick Start
 
```bash
pnpm install
pnpm dev
```
 
### Redact PII (ingress + egress)
 
```bash
curl -X POST http://localhost:3000/api/redact \
  -H "Content-Type: application/json" \
  -d '{"text": "Contact john@example.com or call 555-123-4567", "regulation": "hipaa", "strategy": "mask"}'
```
 
### Ingress-only redaction
 
```bash
curl -X POST http://localhost:3000/api/redact/ingress \
  -H "Content-Type: application/json" \
  -d '{"text": "My email is jane@example.com", "regulation": "gdpr", "strategy": "remove"}'
```
 
### Egress-only scan
 
```bash
curl -X POST http://localhost:3000/api/redact/egress \
  -H "Content-Type: application/json" \
  -d '{"text": "Patient email was [REDACTED]", "regulation": "hipaa"}'
```
 
### View configuration
 
```bash
curl http://localhost:3000/api/redact/config
```
 
### Query audit log
 
```bash
curl "http://localhost:3000/api/redact/audit?eventType=tool.executed&limit=10"
```
 
### Health check
 
```bash
curl http://localhost:3000/api/status
```
 
## Configuration
 
| Variable | Default | Description |
|---|---|---|
| `REGULATION` | `hipaa` | Regulation profile: `hipaa`, `gdpr`, or `pci` |
| `REDACTION_STRATEGY` | `mask` | Redaction strategy: `mask` or `remove` |
| `GUARDRAIL_CHAIN_BUDGET_MAX_LATENCY_MS` | `500` | Max latency budget for guardrail chain (ms) |
| `GUARDRAIL_CHAIN_BUDGET_MAX_TOKENS` | `4000` | Max token budget for guardrail chain |
| `GUARDRAIL_CHAIN_BUDGET_SKIP_SLOW` | `false` | Skip non-essential slow guardrails when under pressure |
| `AUDIT_LOG_PATH` | `./audit.json` | Path for file-based audit logging |
 
## Regulation Profiles
 
- **HIPAA**: SSN (XXX-XX-XXXX), MRN (medical record numbers), DOB, phone numbers, email addresses, patient names
- **GDPR**: Email addresses, phone numbers, physical addresses, IP addresses, personal ID numbers
- **PCI**: Credit card numbers (with Luhn check), CVV codes, card expiry dates
 
## API Reference
 
### `POST /api/redact`
 
Full ingress + egress pipeline. Body: `{ text, regulation?, strategy? }`. Returns `PIIRedactionResponse`.
 
### `POST /api/redact/ingress`
 
Ingress-only PII redaction. Body: `{ text, regulation?, strategy? }`. Returns `{ originalText, redactedText }`.
 
### `POST /api/redact/egress`
 
Egress-only PII scanning. Body: `{ text, regulation?, strategy? }`. Returns `{ originalText, redactedText }`.
 
### `GET /api/redact/config`
 
Returns current runtime configuration (env vars with defaults).
 
### `GET /api/redact/audit`
 
Query audit log. Query params: `eventType`, `limit`, `startDate`, `endDate`. Returns `{ events, total }`.
 
### `GET /api/status`
 
Health check. Returns `{ status: "ok" }`.
 
## Tech Stack
 
- **Next.js 16** (App Router, Turbopack)
- **TypeScript** (strict mode, NodeNext module resolution)
- **@reaatech/guardrail-chain** — Guardrail chain orchestration, budget management
- **@reaatech/guardrail-chain-guardrails** — PIIRedaction and PIIScan guardrails
- **@reaatech/guardrail-chain-config** — Configuration loading and validation
- **@reaatech/guardrail-chain-observability** — ConsoleLogger, setLogger
- **@reaatech/mcp-gateway-audit** — Audit trail logging (ConsoleAuditLogger, MemoryAuditStorage)
- **@reaatech/mcp-gateway-validation** — Schema validation
- **Zod 4.4.3** — Runtime type validation
- **Vitest** — Test runner with V8 coverage
 
## Development
 
```bash
pnpm install         # Install dependencies
pnpm dev             # Start dev server
pnpm typecheck       # TypeScript type checking
pnpm lint            # ESLint
pnpm test            # Run tests with coverage
pnpm build           # Production build
```
 
## License
 
MIT — see [LICENSE](./LICENSE).