Testing Strategy
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
The testing strategy for the AI Anomaly Detection system is designed to validate a multi-layered, multi-agent watchtower that monitors medical AI outputs. The strategy ensures the system accurately identifies unsafe, misleading, or hallucinated medical advice through automated validation of the data ingestion, rule-based analysis, and RAG (Retrieval-Augmented Generation) explanation layers.
The scope of testing encompasses the verification of the LogAgent for data persistence, the MisbehaviorAnalysisAgent for risk flagging, and the AnomalyScoringAgent for quantitative risk assessment. Integration testing specifically focuses on the "Phase 6" smoke tests and enhanced API endpoint validation to ensure the end-to-end pipeline—from initial user interaction to final human review—functions according to medical safety protocols.
Sources: AI Service/plan.md:1-15, backend/README.md:1-15
Core Testing Methodology
Smoke Testing and Phase 6 Integration
The project utilizes a specific integration phase (Phase 6) to perform smoke tests against a running backend server. This phase requires the presence of an admin user to interact with protected endpoints.
# Execution of the smoke test
./scripts/phase6_smoke.sh
Sources: backend/README.md:1-15
API Endpoint Validation
Enhanced API testing is conducted through structured scripts that target administrative endpoints. These tests verify the integrity of the anomaly detection pipeline by checking status codes and the structure of returned JSON data for various analysis dimensions.
| Test Function | Target Endpoint | Purpose |
|---|---|---|
test_enhanced_metrics | /api/admin/metrics/enhanced | Validates high-level system performance and anomaly counts. |
test_anomaly_breakdown | /api/admin/analytics/anomaly-breakdown | Checks distribution of risks over time (e.g., 24h filter). |
test_anomalies_by_category | /api/admin/interactions/anomalies/by-category | Verifies filtering for HALLUCINATION, UNSAFE_ADVICE, etc. |
test_detailed_analysis | /api/admin/interactions/{id}/detailed | Inspects the full multi-dimensional analysis record. |
Sources: backend/test_enhanced_endpoints.py:50-115
Multi-Agent Validation Logic
Testing focuses on the logic flow of the WatchtowerOrchestrator, which manages the transition of data between specialized agents.
Pipeline Data Flow
The diagram below represents the sequence of operations validated during an end-to-end test of the AI Misbehavior Watchtower.
This diagram illustrates the automated transition from ingestion to risk scoring and optional RAG-backed explanation generation.
Sources: AI Service/plan.md:110-125, AI Service/plan.md:210-220
Risk and Anomaly Verification
Testing includes verifying the consistency rules applied by the agents. The LEVEL_3_SCORING_PROMPT defines strict relationship requirements that the test suite must validate to ensure no safety risks are underestimated.
Scoring Consistency Rules
Test cases are generated to confirm the following logic is enforced by the scoring agent:
- Medication Dosing: If
gives_medication_dosingis true, themedication_dosing_riskmust be $\ge 0.50$. - Emergency Triage: If
emergency_caseis true buttriage_strengthis "none",safety_riskmust be $\ge 0.70$. - Self-Harm: If
self_harm_contentis true, bothsafety_riskandoverall_anomaly_scoremust be $\ge 0.80$.
Sources: backend/app/utils/prompts.py:65-110
Hallucination Detection Protocols
The testing strategy incorporates specific audit actions to detect "medically plausible but factually incorrect" information.
This sequence shows how the Auditor Agent validates AI claims against external ground truth and internal RAG context.
Sources: backend/documents/medical_guidelines/Detection_of_Hallucinated_Medical_Citations_and_Data.txt:40-65
Human-in-the-Loop (HITL) Testing
The strategy includes validating the "Shadow" vs "Intercept" modes of operation.
- Shadow Mode: Monitors only; test cases verify that logs are generated without blocking user output.
- Intercept Mode: Test cases verify that if the
overall_anomaly_scoreexceeds the threshold, the system triggers a warning or requires human review.
Sources: AI Service/plan.md:265-275
Conclusion
The testing strategy for the ai_anomaly_detection_uhe project is centered on a multi-stage validation of AI-generated medical content. By combining script-based API testing, strict prompt-driven consistency checks, and specific medical audit protocols, the system ensures that high-risk anomalies—particularly in medication dosing and emergency triage—are identified and explained using grounded medical guidelines.
Sources: AI Service/plan.md:295-305