Feat/haloguard pro scaffolding 1 #31
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🧩 How HaloGuard Pro Controls Hallucinations
1. Knowledge Bases as Source of Truth
All truths are stored in structured JSON (
facts/*.json).Each entry contains:
correct: the verified factincorrect_patterns: regex/string matches for common hallucinationsauto_correct: whether to automatically replacealert_to_admin: whether to escalate👉 Instead of semantic understanding, the framework relies on string and regex pattern detection. This is deterministic and avoids model drift.
2. Verification Flow
LLM generates output
Example:
"Einstein died in 1950"HaloGuard checks output against KB
Regex finds
"Einstein died in 1950"Mapped to
"einstein"entry ingeneral.jsonSystem auto-corrects (if enabled)
→
"Albert Einstein died on April 18, 1955, in Princeton, New Jersey"Audit logs record both original and corrected versions
3. Framework Design Choices
FastAPI + Pydantic → lightweight API wrapper.
Regex entity extraction → for detecting names, years, currencies, percentages.
No embeddings/vector DB → avoids high compute and fuzzy matches.
Audit log pipeline →
logs/haloguard.logstores every correction (compliance-ready).Configurable via
.env→ admin can turn auto-correct on/off by domain.🔄 Comparison to Other Hallucination-Reduction Frameworks
HaloGuard’s philosophy = “less is more”: instead of trying to eliminate all hallucinations, it catches only the high-risk, known ones.
⚙️ Production Integrations
Middleware: Wrap HaloGuard between user and LLM API.
Multi-turn support: Feed
prev_messagesif you want conversational context.Domain toggle: Use different KBs (
medical.json,finance.json, etc.) depending on chatbot type.Monitoring: Health checks via
scripts/health_check.sh, fact updates viascripts/update_facts.sh.🚀 Extending the Framework
Add new
facts/*.jsonentries per domain.Example:
climate.json,history.json.Improve regex/entity extraction (names, dates, numbers).
Build a UI dashboard for:
Viewing flagged hallucinations
Adding new truth entries
Monitoring logs in real time
(Optional) Hybrid Mode: Use HaloGuard for hard rules + fallback to RAG/LLM-as-Judge for gray areas.
✅ Bottom line:
HaloGuard Pro isn’t aiming to “understand” like RAG/LLM evaluators — it’s a firewall against known dangerous hallucinations (medical, legal, financial, compliance-critical). Its strength lies in being predictable, cheap, and production-hardened.