Kirthis/TraceMind
๐ฉบ TraceMind
Neurosymbolic AI-Driven Pediatric Triage โ Research Prototype
A research-grade neurosymbolic system demonstrating secure LLM integration with symbolic reasoning, knowledge graphs, and comprehensive security hardening. Originally a UC Berkeley final project, significantly enhanced post-graduation with production-grade architecture, enterprise-level security practices, and audit logging capabilities.
License: MIT Python 3.9+ Security: Hardened Status: Research Prototype
๐ฏ Overview
TraceMind demonstrates a neurosymbolic approach to clinical triage, combining:
- Natural language processing via LLM for parent/caregiver communication
- Symbolic reasoning using PyDatalog rule engine for explicit logic
- Knowledge graphs (SNOMED-CT) for evidence-based decision support
- Comprehensive audit trails for transparency and compliance
Scope: Pediatric triage across 4 clinical conditions:
- ๐ก๏ธ Fever + GI symptoms + dehydration (NIH/Seattle Children's CPG)
- ๐ซ Asthma Exacerbation with severity stratification (NIH NAEPP CPG)
- ๐ด Allergic Reaction / Anaphylaxis with multi-system assessment (AAP/AAAAI)
- ๐ Croup (Laryngotracheobronchitis) with airway assessment (AAP CPG)
Ages: 3 months - 12 years Purpose: Research demonstration showcasing secure, explainable neurosymbolic AI in healthcare Origins: UC Berkeley final project, enhanced post-graduation with production-grade security & architecture
What it demonstrates:
- โ Modular CPG architecture (4 conditions, expandable for more)
- โ Secure LLM integration (jailbreak & injection resistant)
- โ Transparent decision logic (rule traces & audit logs)
- โ Production-grade architecture (LangGraph, audit trails, validation)
- โ Clinical safety patterns (medication flags, antibiotic stewardship)
Key Technical Features
๐ฉบ Supported Clinical Conditions
1. ๐ก๏ธ Fever (Pediatric Fever Management)
- CPG: NIH/Seattle Children's Hospital CPG
- Assessment: Temperature, alertness, breathing, fluid intake, urination, dehydration risk
- Dispositions: Home Management, Urgent Same-Day, ER Now
- Special Rules: Infant <3mo fever rule, seizure monitoring, antibiotic stewardship
Extended Usecases:
2. ๐ซ Asthma Exacerbation (Respiratory Emergency)
- CPG: NIH NAEPP (National Asthma Education & Prevention Program)
- Assessment: Wheeze, oxygen saturation, speech ability, retractions, respiratory rate
- Severity: Mild (home) โ Moderate (urgent) โ Severe (ER)
- Special Rules: Hypoxia alert, altered mental status, prior intubation history
3. ๐ด Allergic Reaction / Anaphylaxis (Immune Emergency)
- CPG: AAP/AAAAI (American Academy of Pediatrics / American Academy of Allergy)
- Assessment: Urticaria, angioedema, breathing, GI symptoms, cardiovascular signs
- Discrimination: Mild hives (home) vs significant reaction (urgent) vs anaphylaxis (ER/CALL 911)
- Special Rules: Multi-system assessment, biphasic reaction monitoring, epinephrine alert
4. ๐ Croup (Laryngotracheobronchitis - Airway Emergency)
- CPG: AAP Croup Management (Westley scoring concept)
- Assessment: Barky cough, stridor type (inspiratory/biphasic), retractions, oxygen, vocal ability
- Severity: Mild (home) โ Moderate (dexamethasone+urgent) โ Severe (ER)
- Special Rules: Epiglottitis alert (high fever + stridor + drooling), racemic epinephrine for ER
Test Scenarios
Each condition includes 3 preset scenarios (12 total):
- โ Home Management: Mild presentation, safe for home care
- โ Urgent Same-Day: Moderate severity, needs same-day evaluation
- โ ER Now: Severe presentation or red flags, emergency transport
๐ See [Docs/PRESET_SCENARIOS.txt](Docs/PRESET_SCENARIOS.txt) for all 12 scenarios with turn-by-turn examples.
๐ Security & Quality
Comprehensive Security Testing:
- โ 6 LLM prompt injection vectors โ all blocked
- โ 19 adversarial attack cases โ all defended
- โ 100+ attack scenario catalog โ thoroughly tested
- โ Input validation suite โ range & format checking
- โ Contradiction detection โ multi-turn consistency
๐ See [security_tests/reports/](security_tests/reports/) for detailed findings and proof of hardening.
๐๏ธ Architecture
User Input (natural language)
โ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Interpretation โ LLM or heuristics โ CaseFields
โ (tracemind/agents) โ (age, temp, alertness, fluids, urine)
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Knowledge Graph โ SNOMED-CT retrieval
โ (tracemind/graph) โ Neo4j mini-KG for fever CPG
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Safety Logic โ PyDatalog rules
โ (tracemind/logic) โ Triage rules (R_CPG_SEIZURE, etc.)
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Explanation โ Clinical rationale + safety netting
โ (tracemind/agents) โ Medication flags & guidance
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
Disposition (ER_NOW, URGENT_SAME_DAY, HOME_MANAGEMENT)
+ Explanation + Audit LogSee [Docs/ARCHITECTURE.md](Docs/ARCHITECTURE.md) for detailed control flow.
๐ Project Structure
tracemind/
โโโ README.md (this file)
โโโ requirements.txt (dependencies)
โโโ .env.example (configuration template)
โ
โโโ ๐ tracemind/ (Python package)
โ โโโ main.py (CLI entry point)
โ โโโ ui_streamlit.py (Web UI)
โ โโโ config.py (settings & env handling)
โ โโโ state.py (case state management)
โ โ
โ โโโ ๐ agents/ (LLM & heuristic agents)
โ โ โโโ interpretation.py (natural language โ CaseFields)
โ โ โโโ explanation.py (decision rationale)
โ โ โโโ medication.py (safety flags)
โ โ
โ โโโ ๐ graph/ (Knowledge graph retrieval - condition-aware)
โ โ โโโ neo4j_client.py (Neo4j driver)
โ โ โโโ snomed_retrieval.py (SNOMED-CT lookups)
โ โ โโโ fever_cpg_mentions.py (fever CPG mapping)
โ โ โโโ kg_loader.py (load SNOMED-CT + CPG concepts for all conditions)
โ โ โโโ condition_kg_mappings.py (asthma/anaphylaxis/croup KG integration)
โ โ
โ โโโ ๐ logic/ (Symbolic reasoning & CPG rules)
โ โ โโโ triage_rules.py (condition routing + PyDatalog fever rules)
โ โ โโโ cpg_asthma.py (NIH NAEPP asthma severity assessment)
โ โ โโโ cpg_anaphylaxis.py (AAP/AAAAI anaphylaxis logic)
โ โ โโโ cpg_croup.py (AAP croup (Westley) assessment)
โ โ โโโ contradiction_detector.py (consistency checking)
โ โ โโโ multiturn_consistency.py (conversation tracking)
โ โ
โ โโโ ๐ orchestration/ (LangGraph workflow)
โ โ โโโ graph.py (interpret โ KG โ safety โ explain)
โ โ
โ โโโ ๐ audit/ (Compliance & logging)
โ โ โโโ postgres_logger.py (Neon Postgres audit trail)
โ โ
โ โโโ ๐ evaluation/ (Testing & benchmarking)
โ โโโ scenarios.csv (test case catalog)
โ โโโ harness.py (evaluation runner)
โ โโโ ragas_test_harness.py (RAGAS metric evaluation)
โ
โโโ ๐ security_tests/ (Security testing)
โ โโโ README.md (security suite documentation)
โ โโโ ๐ test_scripts/ (runnable tests)
โ โ โโโ test_adversarial.py (19 adversarial cases)
โ โ โโโ test_prompt_injection_llm.py (6 injection tests)
โ โ โโโ debug_llm_extraction.py (diagnostic tools)
โ โโโ ๐ reports/ (security findings - SHOWCASE)
โ โโโ SECURITY_AUDIT_SUMMARY.md
โ โโโ ADVERSARIAL_TEST_CASES.md
โ โโโ LLM_PROMPT_INJECTION_REPORT.md
โ โโโ VULNERABILITY_FINDINGS.md
โ โโโ PHASE1_TEST_RESULTS.md
โ
โโโ ๐ Docs/ (Documentation)
โ โโโ ARCHITECTURE.md (detailed architecture)
โ โโโ CPG Fever - Seattle Children's.pdf
โ โโโ screenshots/
โ
โโโ ๐ KG_implementation/ (Knowledge graph setup)
โ โโโ Pediatric_Fever_KG_*.ipynb (Jupyter notebooks)
โ
โโโ ๐ scripts/ (Utility scripts)
โโโ extract_cpg_pdf.py (PDF extraction)๐ Quick Start
Prerequisites
- Python 3.9+
- pip or conda
Installation
# Clone and navigate
cd TraceMind/tracemind
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate # macOS/Linux
# or
.venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .envRun Interactive CLI
# Mock mode (no LLM or Neo4j required)
TRACEMIND_MOCK_LLM=1 TRACEMIND_SKIP_NEO4J=1 python -m tracemind.main
# With OpenAI + Neo4j (set .env first)
python -m tracemind.mainRun Web UI (Streamlit)
# Mock mode
TRACEMIND_MOCK_LLM=1 TRACEMIND_SKIP_NEO4J=1 streamlit run tracemind/ui_streamlit.py
# With OpenAI + Neo4j
streamlit run tracemind/ui_streamlit.pyOpen browser to http://localhost:8501
๐งช Testing
Run Security Tests
# All tests
python -m security_tests.test_scripts.test_adversarial
python -m security_tests.test_scripts.test_prompt_injection_llm
python -m security_tests.test_scripts.debug_llm_extraction
# View security reports
ls -lh security_tests/reports/Run Scenario Evaluation
TRACEMIND_MOCK_LLM=1 TRACEMIND_SKIP_NEO4J=1 python -m tracemind.evaluation
# Custom scenario file
python -m tracemind.evaluation path/to/scenarios.csvExpected: Exit code 0 when all scenarios match expected disposition.
๐ง Configuration
Environment Variables
# LLM Configuration
OPENAI_API_KEY=sk-... # OpenAI API key
OPENAI_MODEL=gpt-4 # Model name
# Neo4j Graph Database
NEO4J_URI=neo4j+s://instance.databases.neo4j.io
NEO4J_USER=neo4j
NEO4J_PASSWORD=...
NEO4J_DATABASE=neo4j # Leave unset for default
# Audit Logging
DATABASE_URL=postgresql://user:password@host/dbname
# Feature Flags
TRACEMIND_MOCK_LLM=1 # Use mock LLM (no API key needed)
TRACEMIND_SKIP_NEO4J=1 # Skip graph retrieval
TRACEMIND_EXIT_ON_COMPLETE=1 # Exit CLI after disposition
TRACEMIND_USE_LAG=1 # Use Logic-Augmented Generation๐ Documentation
- [ARCHITECTURE.md](Docs/ARCHITECTURE.md) โ Detailed control flow & module interactions
- [SECURITY AUDIT](security_tests/reports/SECURITY_AUDIT_SUMMARY.md) โ Security findings & hardening proof
- [CPG Reference](Docs/CPG_Fever_Seattle_Childrens_reference.md) โ Fever CPG mapping
- [Demo Video](https://youtu.be/OlysHYbYaqU) โ Interactive system walkthrough. (not included in huggingface portal. Refer back to portfolio page)
โ๏ธ Status & Scope
What This Is
- Original: UC Berkeley final project for pediatric fever triage
- Enhancement: Significantly improved post-graduation with security hardening, architecture refinement, and production-grade practices
- Purpose: Research demonstration of secure, explainable neurosymbolic AI in healthcare
- Current Status: Research prototype with enterprise-level security
- Not intended for: Direct clinical use without comprehensive validation
Scope Limitations
- Clinical scope: Fever + GI symptoms + dehydration (limited bundle)
- Age range: Pediatric only (3 months - 12 years)
- Data: Limited to Seattle Children's CPG (not comprehensive)
- Validation: No clinical validation in real-world settings
- Deployment: Requires additional clinical testing before any patient-facing use
Medical Disclaimer
RESEARCH USE ONLY. TraceMind is not a substitute for licensed clinical decision support or medical advice. This system:
- โ Is not FDA approved or cleared
- โ Has not been validated in clinical practice
- โ Should not be used for actual patient care without physician oversight
- โ Does not replace clinical judgment
Use only for research, demonstration, and proof-of-concept purposes under appropriate supervision.
Technical Compliance Features
While not clinically validated, the system demonstrates compliance-minded patterns:
- โ Immutable audit trail logging
- โ No sensitive data exposed in UI
- โ All decisions traceable to rules & evidence
- โ Input validation & sanitization
- โ Jailbreak & injection resistance
Future Enhancements (for actual deployment)
To prepare for real clinical use, would require:
- Clinical validation โ Testing against real patient data
- Expanded scope โ Additional symptoms, age groups, conditions
- Regulatory approval โ FDA clearance or equivalent
- Integration testing โ EHR systems, clinical workflows
- Clinician validation โ Review by practicing pediatricians
- Continuous monitoring โ Real-world performance tracking
๐จโ๐ป Development
Adding a New Rule
- Edit
tracemind/logic/triage_rules.py - Define predicate and rule trace ID:
def R_CUSTOM_RULE(case_fields):
# Rule logic
return disposition, rule_ids, med_flags- Add test case in
security_tests/test_scripts/test_adversarial.py - Run tests:
python -m security_tests.test_scripts.test_adversarial
Adding LLM Support
- Update extraction patterns in
tracemind/agents/interpretation.py - Test with
debug_llm_extraction.py:
python -m security_tests.test_scripts.debug_llm_extraction- Add test scenario to
tracemind/evaluation/scenarios.csv
๐ References
- Seattle Children's Fever CPG โ Integrated in
Docs/ - SNOMED-CT โ Knowledge graph foundation
- LangGraph โ Orchestration framework
- Neo4j โ Graph database backend
- PyDatalog โ Logic programming engine
๐ License
MIT License โ See LICENSE file for details.
๐ Support
For questions or issues:
- Check
[Docs/ARCHITECTURE.md](Docs/ARCHITECTURE.md) - Review
[security_tests/reports/](security_tests/reports/)for security findings - Check test cases in
security_tests/test_scripts/
Last Updated: June 2026 Status: Research Prototype (UC Berkeley โ Enhanced) โ Security: Comprehensively Tested & Hardened โ Clinical Use: Not validated for production deployment โ ๏ธ
