Anomaly Visualization
Relevant source files
The following files were used as context for generating this wiki page:
Anomaly Visualization is a critical component of the AI Misbehavior Watchtower, providing administrators and auditors with a multi-layered interface to inspect, analyze, and verify AI-generated medical responses. It translates complex, multi-dimensional anomaly scores and risk flags into actionable visual insights, ranging from high-level dashboard metrics to granular, stage-by-stage pipeline breakdowns.
The system is designed to expose "Safety Anomalies" such as medical hallucinations, undertriage of emergency symptoms, and missing legal disclaimers. By providing RAG-grounded explanations alongside visual risk scores, the visualization layer enables effective human-in-the-loop (HITL) oversight to ensure medical safety and alignment with scientific consensus.
Sources: AI Service/plan.md, frontend/src/pages/admin/InteractionDetail.jsx:136-290
Multi-Stage Pipeline Visualization
The visualization architecture follows the logical flow of the ML processing pipeline. Each interaction is analyzed through a sequential 5-level or 6-level hierarchy, where each level adds a layer of depth to the anomaly detection.
This diagram shows the standard flow of data through the visualization components, where raw logs are transformed into scores, explanations, and finally human verification.
Sources: frontend/src/components/admin/InteractionDetail.jsx:87-340
Level 1: Interaction Log
The base layer captures the raw data ingestion. It displays the original user prompt and the AI's response in a "Message Exchange" format, including metadata such as timestamps and the specific model used.
Sources: frontend/src/components/admin/InteractionDetail.jsx:111-155
Level 2: Multi-Dimensional Detection & Analysis
This section visualizes feature extraction and enhanced detection. It utilizes AnalysisRecord data to display extracted medical topics and specific risk context flags. Enhanced analysis provides a summary of five key dimensions:
- Quality: Response completeness and specificity.
- Hallucination: Risk score based on claim verification.
- Alignment: Intent match and topic relevance.
- Safety: Assessment of physical harm potential.
- Confidence: Calibration between expressed and appropriate confidence levels.
Sources: frontend/src/pages/admin/InteractionDetail.jsx:138-290, backend/app/schemas/enhanced_detection.py:90-112
Anomaly Scoring and Breakdown
The system quantifies risks through standardized scoring records. These scores are visualized using progress bars and color-coded cards to indicate risk severity.
Score Severity Levels
Scores are normalized between 0.0 and 1.0, and visualized based on specific thresholds:
| Score Range | Severity Level | Visual Representation |
|---|---|---|
| < 0.3 | Low | Green / "Safe" |
| 0.3 - 0.7 | Medium | Yellow / "Borderline" |
| > 0.7 | High | Red / "Flagged" |
Sources: frontend/src/pages/admin/InteractionDetail.jsx:75-79, frontend/src/components/admin/InteractionDetail.jsx:236-240
Category Distribution
The AnomalyBreakdown component provides a statistical view of detected anomalies by category. It uses a color-dot system to distinguish between various misbehavior types.
| Category | Description | Color Code |
|---|---|---|
UNSAFE_ADVICE | Direct physical risk or lethal dosing | #dc2626 |
HALLUCINATION | Fabricated medical citations or data | #ea580c |
CONTEXT_MISMATCH | Failure to address user intent | #d97706 |
POOR_QUALITY | Incomplete or incoherent responses | #ca8a04 |
CONFIDENCE_ISSUE | Overconfident or under-hedged claims | #2563eb |
Sources: frontend/src/components/admin/AnomalyBreakdown.jsx:20-30, backend/app/schemas/enhanced_detection.py:127-140
Explainability and Grounding
The "Explainability Layer" (Level 4) is critical for transparency. It visualizes the output of the RAG (Retrieval-Augmented Generation) system, showing exactly why an interaction was flagged.
This sequence illustrates how the UI retrieves and displays grounded explanations to the auditor.
Sources: AI Service/plan.md: Phase 3, frontend/src/components/admin/InteractionDetail.jsx:277-330
Citation Visualization
Citations are rendered as interactive cards containing:
- Document ID: Reference to the source guideline (e.g.,
NHS_EMERGENCY_Triage). - Chunk ID: Specific segment of the document used.
- Relevance Score: A percentage indicating how closely the guideline matches the detected anomaly.
Sources: frontend/src/components/admin/InteractionDetail.jsx:311-325, AI Service/plan.md: 3.1
Human Feedback Loop
The final stage of visualization is the Human Review component. This facilitates the "Intercept Mode" or "Shadow Mode" of the watchtower by allowing expert auditors to provide verification.
The ER diagram shows the relationship between an automated anomaly detection and the human corrective action.
Sources: AI Service/plan.md: 1.1 (E), frontend/src/components/admin/InteractionDetail.jsx:340-379
The review interface displays the final "Human Label" alongside any corrected responses or comments provided by the medical reviewer, closing the loop between AI detection and human expertise.
Sources: frontend/src/pages/admin/InteractionDetail.jsx:340-385
Conclusion
Anomaly Visualization in this project serves as a sophisticated monitoring interface that bridges the gap between raw LLM outputs and clinical safety standards. By organizing data into distinct pipeline levels and providing clear visual cues for risk scores and RAG-based grounding, the system enables technical auditors to identify and mitigate AI misbehavior effectively.