HIPAA-Aligned LLM Firewall with Graph-Based Authorization
AegisGraph is a production-ready security-first LLM gateway that enforces HIPAA compliance through a four-agent pipeline with Neo4j-powered authorization, real-time threat detection, automatic PHI redaction, self-healing security escalation, and comprehensive Datadog observability.
- Intent Agent: Classifies request intent (TREATMENT, DIAGNOSIS, ADMIN, EMERGENCY)
- Graph Policy Agent: Neo4j relationship validation for doctor-patient access control
- Safety Agent: Real-time threat detection (prompt injection, jailbreak, PII exfiltration)
- Response Agent: Context-aware clinical responses with automatic PHI redaction
- HIPAA Compliance: Complete audit trails, access controls, and PHI protection
- Automatic PHI Redaction: Real-time detection and redaction of sensitive information (SSN, credit cards, emails, phone numbers, addresses)
- Break-Glass Emergency Access: One-click emergency mode with full audit logging
- VIP Patient Protection: Enhanced monitoring for high-profile patients
- Risk Scoring: Real-time patient risk assessment based on access patterns
- Self-Healing Security: Automatic escalation to STRICT_MODE after threshold breaches
- Attack Pattern Analytics: Real-time categorization of threats (prompt injection, PHI exfiltration, keyword blocks)
- Security Mode Management: NORMAL → STRICT_MODE → LOCKDOWN with automatic reversion
- Datadog MCP Integration: Intelligent threat detection with configurable thresholds
- Datadog APM: Full distributed tracing with ddtrace integration
- LLM Observability: All prompts, responses, and costs tracked
- Custom Dashboards: Pre-built dashboard with 10+ widgets
- Real-Time Metrics: Live security alerts, attack patterns, and compliance scores
- Cost Tracking: Token usage and LLM costs monitored per request
- Three-Panel Layout: Patient list with risk badges, chat interface, live metrics dashboard
- Emergency Mode UI: Visual indicators and one-click emergency access
- Live Security Alerts: Real-time security event stream
- Attack Pattern Visualization: Bar charts showing threat distribution
- HIPAA Compliance Score: Live compliance percentage display
- Text-to-Speech: MiniMax TTS integration for voice alerts and response playback
- MiniMax TTS Integration: Convert responses to speech with high-quality voices
- Speak Response Button: Click to hear any assistant response
- Security Voice Alerts: Automatic voice notifications for critical security events
- Daily Security Summaries: Automated voice reports of security metrics
┌─────────────────────────────────────────────────────────────┐
│ UI Layer │
│ (Doctor Login → Patient Selection → Chat + Voice) │
│ • Risk Badges • Live Metrics • Attack Analytics │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Security Pipeline │
│ │
│ 1. LOCKDOWN Gate → Immediate refusal if locked │
│ 2. Intent Agent → Classify request intent │
│ 3. Graph Policy → Neo4j authorization + emergency │
│ 4. Deny Gate → Block unauthorized access │
│ 5. Safety Agent → Threat detection & scanning │
│ 6. Block Gate → Stop malicious requests + TTS alert │
│ 7. Response Agent → LLM generation + PHI redaction │
│ 8. Datadog Metrics → Log everything │
│ 9. Self-Heal Check → Auto-escalate if threshold hit │
│ 10. Save History → Neo4j audit trail │
│ │
└─────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────┐
│ Data & Monitoring │
│ │
│ • Neo4j: Relationships, chat history, audit logs │
│ • Datadog: APM traces, logs, metrics, dashboards │
│ • AWS Bedrock: Claude 3.5 Sonnet for LLM inference │
│ • MiniMax: Text-to-speech for voice alerts │
│ • PHI Redactor: Real-time sensitive data detection │
│ │
└─────────────────────────────────────────────────────────────┘
- Python 3.10+
- Neo4j Aura account (or local Neo4j instance)
- Datadog account (for monitoring)
- AWS Bedrock access (optional - mock mode available)
- Clone the repository
git clone <repository-url>
cd AegisGraph- Create virtual environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies
pip install -r requirements.txt- Configure environment
cp .env.example .env
# Edit .env with your credentials:
# - NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD
# - DD_API_KEY, DD_APP_KEY (Datadog)
# - AWS credentials (optional if using mock mode)- Seed Neo4j database
python backend/seed_data/seed.py- Start the backend
./start_backend.sh
# Or manually: uvicorn backend.main:app --reload- Access the UI
open http://localhost:8000- All doctor passcodes:
1234 - Doctors: D1 (Cardiology), D2 (Neurology), D3 (Orthopedics)
- Patients: P101, P102, P103, P104, P105, P106
Create a .env file with the following:
# Neo4j Configuration
NEO4J_URI=neo4j+s://your-instance.databases.neo4j.io
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=your-password
NEO4J_DATABASE=neo4j
# Datadog Configuration
DD_API_KEY=your-datadog-api-key
DD_APP_KEY=your-datadog-app-key
DD_AGENT_HOST=localhost
DD_STATSD_PORT=8125
DD_DASHBOARD_URL=https://app.datadoghq.com/dashboard/your-dashboard-id
# AWS Bedrock Configuration
AWS_REGION=us-west-2
AWS_DEFAULT_REGION=us-west-2
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-key
AWS_SESSION_TOKEN=your-session-token # Optional for temporary credentials
# MiniMax TTS (Optional - for voice features)
MINIMAX_API_KEY=your-minimax-api-key
# Mock Mode (set to false to use real AWS Bedrock)
USE_MOCK_BEDROCK=falseAegisGraph supports three security modes:
- NORMAL: Standard authorization checks
- STRICT_MODE: Enhanced security (auto-triggered after threshold breaches)
- LOCKDOWN: All requests blocked (emergency shutdown)
Change mode via API:
curl -X POST http://localhost:8000/mode \
-H "Content-Type: application/json" \
-d '{"mode": "NORMAL"}'POST /chat
{
"user_id": "D1",
"role": "Cardiologist",
"doc_id": "D1",
"patient_id": "P101",
"message": "What is the patient's blood type?",
"emergency_mode": false
}POST /tts/speak
{
"text": "Security alert: Unauthorized access detected",
"voice_id": "English_Trustworth_Man"
}GET /metrics # Current system metrics
GET /mode # Current security mode
POST /mode # Change security mode
GET /security/alerts # Recent security alerts (last 20)
GET /security/attack-patterns # Attack pattern analytics
POST /security/daily-summary # Generate daily security summary with TTSGET /doctors # List all doctors
GET /patients?doctor_id=D1 # List patients for doctor (with risk scores)
GET /chat/history?patient_id=P101&doctor_id=D1 # Get chat historyPOST /datadog/create-dashboard # Create Datadog dashboard programmaticallyPOST /activity/log
{
"doctor_id": "D1",
"type": "EMERGENCY_ACCESS",
"description": "Accessed all patients in emergency mode",
"timestamp": "2024-02-20T12:00:00Z"
}curl -X POST http://localhost:8000/datadog/create-dashboardReturns:
{
"success": true,
"dashboard_url": "https://app.datadoghq.com/dashboard/xxx-xxx-xxx",
"message": "Dashboard created successfully"
}- Total Requests: Live count of all requests
- Blocked Requests: Security blocks and denials
- Token Usage: LLM input/output tokens over time
- Cost Tracking: Cumulative LLM costs
- Log Stream: Real-time prompts and responses
- Security Metrics: Authorization rates, PHI risk scores
Logs appear in Datadog after 2-5 minutes of indexing:
- Logs Explorer: https://app.datadoghq.com/logs?query=source:aegisgraph
- Dashboard: Created via
/datadog/create-dashboardendpoint
# Run all tests
pytest tests/
# Run with coverage
pytest tests/ --cov=backend --cov-report=html
# Run specific test file
pytest tests/test_orchestrator.py
# Run with verbose output
pytest tests/ -v# Integration tests
pytest tests/test_integration.py
# Agent tests
pytest tests/test_intent_agent.py
pytest tests/test_graph_policy_agent.py
pytest tests/test_safety_agent.py
pytest tests/test_response_agent.py
# Feature tests
pytest tests/test_phi_redactor.py
pytest tests/test_tts.py
# Connectivity tests
python tests/test_connectivity.pyAegisGraph/
├── backend/
│ ├── agents/ # Four-agent security pipeline
│ │ ├── intent_agent.py
│ │ ├── graph_policy_agent.py
│ │ ├── safety_agent.py
│ │ └── response_agent.py
│ ├── models/ # Pydantic schemas
│ │ └── schemas.py
│ ├── tools/ # External integrations
│ │ ├── neo4j_client.py
│ │ ├── bedrock_client.py
│ │ ├── mock_bedrock_client.py
│ │ ├── minimax_client.py # TTS integration
│ │ ├── phi_redactor.py # PHI detection & redaction
│ │ └── datadog_mcp_tool.py # Self-healing security
│ ├── telemetry/ # Observability
│ │ ├── datadog_integration.py
│ │ ├── ddtrace_setup.py
│ │ └── metrics.py
│ ├── seed_data/ # Database seeding
│ │ ├── seed.py
│ │ └── seed.cypher
│ ├── orchestrator.py # Pipeline coordinator
│ └── main.py # FastAPI application
├── ui/
│ ├── app.html # Modern web interface
│ └── index.html # Landing page
├── tests/ # All test files
│ ├── test_orchestrator.py
│ ├── test_integration.py
│ ├── test_main.py
│ ├── test_intent_agent.py
│ ├── test_graph_policy_agent.py
│ ├── test_safety_agent.py
│ ├── test_response_agent.py
│ ├── test_phi_redactor.py
│ ├── test_tts.py
│ └── test_connectivity.py
├── .env.example # Environment template
├── .env # Your configuration (gitignored)
├── requirements.txt # Python dependencies
├── start_backend.sh # Backend startup script
├── start_ui.sh # UI startup script
└── README.md # This file
- QUICK_START.md: Step-by-step setup guide
- DEMO_GUIDE.md: Demo walkthrough
- DATADOG_SETUP.md: Datadog configuration
- DATADOG_LIVE_INTEGRATION.md: Live monitoring details
- DATADOG_TROUBLESHOOTING.md: Common issues
- NEW_UI_FEATURES.md: UI feature documentation
Automatically detects and redacts sensitive information:
- SSN: 123-45-6789 → [REDACTED_SSN]
- Credit Cards: 4532-1234-5678-9012 → [REDACTED_CREDIT_CARD]
- Emails: john@example.com → [REDACTED_EMAIL]
- Phone Numbers: 555-123-4567 → [REDACTED_PHONE]
- Addresses: 123 Main St, City, ST 12345 → [REDACTED_ADDRESS]
Redaction count tracked per response and displayed in UI with badge.
Real-time categorization of security threats:
- Prompt Injection: Attempts to manipulate system behavior
- PHI Exfiltration: Unauthorized data access attempts
- Keyword Blocks: Sensitive term detection
Dashboard shows:
- Bar charts with threat distribution
- Most common attack type
- Total blocked requests by category
Automatic security escalation based on threat patterns:
- Monitoring Window: 60 seconds
- Threshold: 3 auth denials or safety blocks
- Action: Auto-escalate to STRICT_MODE
- Cooldown: 10 minutes before auto-revert to NORMAL
- Manual Override: Admin can change mode anytime
MiniMax TTS integration for audio feedback:
- Speak Response: Click 🔊 button to hear any response
- Security Alerts: Automatic voice notifications for critical events
- Daily Summaries: Automated voice reports of security metrics
- Voice Selection: Multiple voice options (English_Trustworth_Man, etc.)
Automatically categorizes requests:
TREATMENT: Treatment plans, medicationsDIAGNOSIS: Diagnostic queriesADMIN: Administrative tasksEMERGENCY: Critical situationsUNKNOWN: Unclassified requests
Neo4j relationships enforce access control:
MATCH (d:Doctor {id: $docId})-[:TREATS]->(p:Patient {id: $patId})
RETURN authorizedEmergency mode override:
- Bypasses relationship checks
- Full audit trail maintained
- Break-glass access logged
Detects security threats:
- Prompt injection attempts
- Jailbreak patterns
- PII leakage risks
- Unauthorized data access
- Malicious intent
Risk scoring (0-100):
- 0-30: Low risk (allow)
- 31-70: Medium risk (allow with monitoring)
- 71-100: High risk (block)
Maintains chat history:
- Last 10 messages per doctor-patient session
- Chronological ordering
- Context-aware responses
- Session management
- Redaction count tracking
All actions logged to Neo4j:
- Doctor logins
- Patient access
- Emergency mode activations
- Chat interactions
- Authorization denials
Emergency mode features:
- Access all patients
- Full audit logging
- Activity tracking
- Datadog alerts
Automatic security escalation:
- Monitors auth denials and safety blocks
- Auto-escalates to STRICT_MODE after threshold
- Auto-reverts after cooldown period
- Configurable thresholds
- Total Requests: Live count with trend
- Blocked Requests: Security blocks over time
- HIPAA Compliance Score: Real-time percentage
- Security Mode: Current mode indicator
- Token Usage: Input/output tokens tracked
- Cost Tracking: Cumulative LLM costs
- Log Stream: Real-time prompts and responses
- Attack Patterns: Threat distribution chart
- Top 5 Attacked Patients: Most targeted patients
- PHI Redactions: Redaction count metrics
- Total requests
- Blocked requests
- Authorization success rate
- Token usage (input/output)
- LLM costs per request
- Response times
- PHI exposure risk
- Security mode changes
- Redaction counts
- Attack pattern distribution
- Patient risk scores
- All LLM prompts and responses
- Authorization decisions
- Safety scan results
- PHI redaction events
- Security mode changes
- Emergency access events
- Error traces with stack traces
- Activity logs
- Attack pattern classifications
Full distributed tracing with ddtrace:
llm.generate- Response generation spanminimax.text_to_speech- TTS conversion spanminimax.tts_alert- Voice alert span- Custom tags for request_id, security_mode, doc_id, patient_id
- Error tracking and performance monitoring
- Create agent class in
backend/agents/ - Implement required methods
- Add to pipeline in
orchestrator.py - Update tests
- Modify Neo4j schema in
seed_data/seed.cypher - Update
graph_policy_agent.pyqueries - Add new relationship types
- Test authorization logic
- Add metrics in
telemetry/metrics.py - Update Datadog dashboard config
- Add log fields in
datadog_integration.py
Dashboard shows no data:
- Wait 2-5 minutes for log indexing
- Check Logs Explorer first
- Verify DD_API_KEY and DD_APP_KEY in .env
Neo4j connection errors:
- Verify NEO4J_URI, username, password
- Check network connectivity
- Ensure database is seeded
Chat not working:
- Check backend logs for errors
- Verify mock mode is enabled if no AWS access
- Ensure Neo4j has doctor-patient relationships
Authorization always fails:
- Run seed script to create relationships
- Check doctor_id and patient_id are correct
- Verify Neo4j query in logs
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
[Add your license here]
For issues and questions:
- Check documentation in
/docs - Review troubleshooting guides
- Open an issue on GitHub
Built with:
- FastAPI
- Neo4j
- Datadog
- AWS Bedrock
- Python 3.10+