AI Hallucination Detector

A
Documentation

How TruthGuard Works

Complete technical documentation for developers and recruiters

Overview

TruthGuard is an enterprise-grade AI safety platform that validates AI responses in real-time, detects hallucinations, ensures compliance, and provides complete audit trails for regulatory requirements.

Hallucination Detection

Real-time fact verification against Wikipedia, DuckDuckGo, and NewsAPI

Compliance Checking

Automated regulatory and policy violation detection

Audit Trails

Complete logging for regulatory compliance and explainability

Key Benefits

  • • Prevent false information from reaching customers
  • • Maintain regulatory compliance automatically
  • • Reduce legal exposure from AI-generated content
  • • Provide auditors with complete interaction history

System Architecture

Frontend Stack

Next.js 16React framework with App Router
React 19UI library with Server Components
TypeScriptType-safe development
Tailwind CSSUtility-first styling
RechartsData visualization

Backend Stack

FastAPIHigh-performance Python API
PydanticData validation
SupabasePostgreSQL database
spaCyNLP processing
Google GeminiAI model integration
┌────────────────┐     ┌────────────────┐     ┌────────────────┐
│   Customer     │────▶│   TruthGuard   │────▶│   External     │
│   AI System    │     │   Platform     │     │   APIs         │
└────────────────┘     └────────────────┘     └────────────────┘
                              │
                              ▼
                       ┌────────────────┐
                       │   Supabase     │
                       │   PostgreSQL   │
                       └────────────────┘

Detection Pipeline

Every AI response goes through a 5-step validation pipeline:

1

Claim Extraction

Uses spaCy NLP to extract factual claims from AI responses. Identifies nouns, numbers, dates, and verifiable assertions.

2

Fact Verification

Queries Wikipedia API, DuckDuckGo, and NewsAPI to verify claims. Uses semantic similarity to match claims with sources.

3

Compliance Checking

Validates against predefined compliance rules (financial advice, medical claims, etc.) and company-specific policies.

4

Consistency Analysis

Compares response with historical data to detect contradictions and ensure message consistency.

5

Decision & Correction

Generates confidence score, flags violations, and optionally auto-corrects responses using AI.

Status Outcomes

approved- Passed all checks
flagged- Minor issues found
blocked- Critical violations

API Reference

TruthGuard provides a RESTful API for integration with any AI system.

POST/api/v1/validate

Validate an AI response

{
  "query": "What is Python?",
  "ai_response": "Python is a programming language...",
  "organization_id": "your-org-id",
  "ai_model": "gpt-4"
}
GET/api/v1/audit/interactions

List all interactions

// Query parameters
?limit=20
&offset=0
&organization_id=your-org-id
&status=approved|flagged|blocked
GET/api/v1/audit/violations

List violations

// Query parameters
?severity=critical|high|medium|low
&violation_type=hallucination|compliance|policy
POST/api/v1/ai-test/generate

Generate AI response and validate

{
  "company_id": "company-uuid",
  "user_query": "Your question here",
  "ai_model": "gemini-pro"
}

Integration Guide

1. Basic Integration

// Send AI response for validation
const response = await fetch('https://api.truthguard.ai/api/v1/validate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    query: userQuery,
    ai_response: aiResponse,
    organization_id: 'your-org-id',
    ai_model: 'gpt-4'
  })
});

const result = await response.json();

if (result.status === 'blocked') {
  // Use corrected response or show warning
  return result.validated_response || "Unable to provide response";
}

return result.ai_response;

2. Python Example

import requests

def validate_ai_response(query: str, ai_response: str) -> dict:
    response = requests.post(
        "https://api.truthguard.ai/api/v1/validate",
        json={
            "query": query,
            "ai_response": ai_response,
            "organization_id": "your-org-id",
            "ai_model": "gpt-4"
        }
    )
    return response.json()

# Usage
result = validate_ai_response("What is Python?", ai_response)
if result["status"] == "approved":
    print("Response is valid!")
else:
    print(f"Issues found: {result['violations']}")