Hallucination Detector
by @charlie-morrison
Detect and flag hallucinations in LLM outputs by cross-referencing claims against source documents, code, and verifiable data. Essential for RAG pipelines an...
clawhub install cm-hallucination-detectorπ About This Skill
name: hallucination-detector description: Detect and flag hallucinations in LLM outputs by cross-referencing claims against source documents, code, and verifiable data. Essential for RAG pipelines and AI content review. metadata: tags: ["ai", "llm", "hallucination", "rag", "quality", "factcheck"]
Hallucination Detector
Detect and flag hallucinations in LLM-generated content by cross-referencing claims against source documents, codebase facts, API documentation, and verifiable data. Use when reviewing AI-generated documentation, code comments, summaries, or any content that needs factual accuracy.
Usage
"Check this AI-generated summary for hallucinations against the source docs"
"Verify the code documentation matches the actual implementation"
"Detect hallucinations in this RAG pipeline output"
"Fact-check this AI-generated API reference"
"Review these generated release notes for accuracy"
How It Works
1. Claim Extraction
Parse the LLM output and identify verifiable claims:
processOrder() function handles refunds", "Uses AES-256 encryption"2. Source Grounding
For each claim, identify and query the ground truth source:
Code verification:
# Verify function exists and has claimed signature
grep -rn "function processOrder\|def processOrder\|processOrder(" src/
Verify parameter count
ast-grep --pattern 'function processOrder($$$)' src/
Verify dependency relationship
grep -rn "import.*from.*moduleB\|require.*moduleB" src/moduleA/
Documentation verification:
# Check if referenced section exists
grep -rn "## Configuration" docs/
Verify version claims
git log --oneline --all --grep="processOrder" | head -5
git tag --contains $(git log --format=%H -1 --all -- src/processOrder.ts)
API verification:
# Verify endpoint exists and returns claimed schema
grep -rn "router\.\(get\|post\|put\|delete\)" src/routes/ | grep "orders"
Check response schema
grep -A 20 "res.json\|res.send" src/routes/orders.ts
3. Hallucination Classification
Each detected issue is classified:
calculateTax() function" when no such function exists
4. Confidence Scoring
Each claim gets a confidence score:
5. RAG Pipeline Analysis
When used in RAG context, also check:
6. Pattern Detection
Identify common hallucination patterns:
Output
## Hallucination Analysis ReportContent reviewed: AI-generated API documentation (2,400 words)
Claims extracted: 47
Verification results:
| Status | Count | % |
|--------|-------|---|
| β
Verified | 31 | 66% |
| π’ Likely correct | 6 | 13% |
| π‘ Uncertain | 3 | 6% |
| π΄ Hallucinated | 7 | 15% |
π΄ Confirmed Hallucinations
1. "The /api/users endpoint supports bulk operations via POST /api/users/bulk"
- Reality: No bulk endpoint exists in routes/users.ts
- Type: Fabrication
- Fix: Remove bulk operations section entirely
2. "Authentication uses OAuth 2.0 with PKCE flow"
- Reality: Uses session-based auth (express-session + passport-local)
- Type: Contradiction
- Fix: Replace with actual auth mechanism description
3. "Rate limited to 1000 requests per minute per API key"
- Reality: No rate limiting configured (no rate-limit middleware found)
- Type: Fabrication
- Fix: Remove rate limiting claims or implement the feature
4. "Response includes pagination metadata with total_count, page, and per_page"
- Reality: API returns raw arrays without pagination
- Type: Fabrication
- Fix: Document actual response format
[3 more...]
π‘ Uncertain Claims (need human review)
5. "Handles up to 5,000 concurrent connections"
- No load testing data found β may be true but unverified
π Hallucination Hotspots
Performance claims: 3/4 hallucinated (75%)
Feature descriptions: 2/18 hallucinated (11%)
Security section: 2/8 hallucinated (25%) π‘ Recommendations
Performance section needs complete rewrite with actual benchmarks
Security section should be reviewed by the auth team
Consider adding integration tests that validate API documentation accuracy
Integration
π‘ Examples
"Check this AI-generated summary for hallucinations against the source docs"
"Verify the code documentation matches the actual implementation"
"Detect hallucinations in this RAG pipeline output"
"Fact-check this AI-generated API reference"
"Review these generated release notes for accuracy"