Reference
System Architecture
CHAPAL operates on a dual-layer detection system to balance speed and semantic understanding.
High-Level Flow
User Query
⬇
[Layer 1] Deterministic Guard (Local)
- Spike Detection (DDoS)
- Regex / Pattern Matching (PII, Keywords)
⬇ (if Safe)
Gemini 1.5 Flash (Generation)
- Generates initial response buffer
⬇
[Layer 2] Semantic Auditor (Groq / Llama 3.1)
- Contextual Analysis (Hallucinations, Tone)
- Medical/Psychological Evaluation
⬇
Decision Gate
➡ Safe: Deliver to User
➡ Anomaly: Block & Route to Admin
Layer 1: Deterministic (The Shield)
This layer runs instantly on the server. It handles high-speed threats that don't require deep AI understanding to identify.
- Spike Detection: Blocks users sending >4 messages in rapid succession (Anti-DDoS).
- Pattern Matching: Uses strict Regex for SSNs, Credit Cards, and known malicious prompt injection strings.
Layer 2: Semantic (The Brain)
Powered by Llama 3.1 8B running on Groq LPU hardware. This layer "reads" the conversation like a human auditing the chat.
- Hallucination Check: Compares the Gemini response against known facts or internal context.
- Tone Analysis: Detects subtle hostility or manipulation that regex misses.
- Medical/Legal Safety: Identifies if the AI is giving advice it shouldn't (e.g., specific dosage instructions).
Technology Stack
Next.js 15
Framework
Gemini
Chat Model
Groq
Inference Engine
Prisma
ORM / DB