Skip to content

Latest commit

Β 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” TruthLens

Real-Time AI Hallucination Detector

Stop trusting AI blindly. Start verifying instantly.

Chrome Extension TypeScript Node.js PostgreSQL License


The Problem

Every AI β€” ChatGPT, Claude, Gemini, Copilot β€” confidently says things that are completely wrong.

  • πŸ₯ Doctors get wrong drug dosages
  • πŸ“š Students get fake citations
  • βš–οΈ Lawyers get invented case law
  • πŸ”¬ Researchers get fabricated statistics

Nobody knows when AI is lying until it's too late.

The Solution

TruthLens is a Chrome extension that sits on top of any AI chatbot and automatically verifies every factual sentence in real time.

A coloured dot appears next to each sentence:

Dot Meaning Example
🟒 Green Verified by trusted sources "Water boils at 100°C at sea level"
🟑 Yellow Could not verify β€” use caution "About 70% of the ocean is unexplored"
πŸ”΄ Red (pulses) Contradicts known facts β€” do not trust "Aspirin is safe for children under 12"
βšͺ Grey Not a factual claim "Hello, how are you?"

✨ Features

Core Verification

  • Real-Time Streaming Detection β€” Reads AI output as it streams, sentence by sentence
  • Multi-Source Cross-Checking β€” Verifies against Wikipedia, PubMed (medical research), and Wikidata simultaneously
  • AI-Powered Claim Detection β€” Uses Groq Llama 3.3 70B to classify claims and compare with sources
  • Dual-Prompt System β€” Separate medical-expert and general fact-checker prompts for accurate verdicts

Smart Performance

  • PostgreSQL Caching β€” Previously verified claims return instantly from the database
  • Intelligent PubMed Routing β€” Only queries PubMed for medical/scientific claims, saving API calls
  • Source Relevance Filtering β€” Keyword and AI-based pre-checks prevent false verdicts from unrelated sources
  • Request Queue & Rate Limiting β€” Handles Groq API limits gracefully with debounced processing

UI & UX

  • Polished Click Popups β€” Click any dot to see the reason, sources, and a colour-coded top bar
  • Red Dot Pulse Animation β€” Contradicted claims pulse to draw immediate attention
  • Floating Sidebar Panel β€” Real-time stats (Checked / Verified / Uncertain / Contradicted) on every page
  • Extension Popup β€” Professional popup with session stats, enable/disable toggle, and dot legend
  • SPA-Resilient β€” WeakMap-based caching ensures dots persist across DOM re-renders (Gemini, Claude)

Platform Support

Platform Status
ChatGPT (chatgpt.com) βœ… Full Support
Claude (claude.ai) βœ… Full Support
Gemini (gemini.google.com) βœ… Full Support
Copilot (copilot.microsoft.com) βœ… Full Support

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    CHROME EXTENSION                          β”‚
β”‚                                                              β”‚
β”‚  content.ts ──► MutationObserver detects AI sentences        β”‚
β”‚       β”‚                                                      β”‚
β”‚       β–Ό                                                      β”‚
β”‚  background.ts ──► Forwards to backend via fetch             β”‚
β”‚       β”‚             (bypasses CSP restrictions)               β”‚
β”‚       β–Ό                                                      β”‚
β”‚  popup.ts ──► Stats display + enable/disable toggle          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό  HTTPS
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    BACKEND (Render)                           β”‚
β”‚                                                              β”‚
β”‚  POST /api/check                                             β”‚
β”‚       β”‚                                                      β”‚
β”‚       β”œβ”€β”€β–Ί PostgreSQL Cache ──► HIT? Return instantly         β”‚
β”‚       β”‚                                                      β”‚
β”‚       β”œβ”€β”€β–Ί Groq Llama 3.3 ──► Is this a factual claim?       β”‚
β”‚       β”‚                                                      β”‚
β”‚       β”œβ”€β”€β–Ί Wikipedia API ──┐                                 β”‚
β”‚       β”œβ”€β”€β–Ί PubMed API ────────► Source Relevance Filter       β”‚
β”‚       β”‚                    β”‚                                 β”‚
β”‚       β”œβ”€β”€β–Ί Groq Comparison ◄──► Medical or General Prompt     β”‚
β”‚       β”‚                                                      β”‚
β”‚       └──► Cache Result + Return Verdict                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Node.js 20+
  • pnpm
  • Chrome browser
  • Groq API key (get one free)

Backend Setup

cd backend
pnpm install
cp .env.example .env
# Edit .env: add GROQ_API_KEY and DATABASE_URL (optional)
pnpm run dev

Extension Setup

cd extension
pnpm install
pnpm run build

Then:

  1. Open chrome://extensions/ in Chrome
  2. Enable Developer Mode (top right toggle)
  3. Click Load unpacked
  4. Select the extension/dist folder

πŸ“ Project Structure

truth-lens/
β”œβ”€β”€ extension/                    # Chrome Extension (Manifest V3)
β”‚   β”œβ”€β”€ manifest.json             # Extension configuration
β”‚   β”œβ”€β”€ popup.html                # Popup UI with stats & toggle
β”‚   β”œβ”€β”€ popup.css                 # Popup styles
β”‚   β”œβ”€β”€ icons/                    # Extension icons (16/48/128px)
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ content.ts            # MutationObserver + dot injection + sidebar
β”‚   β”‚   β”œβ”€β”€ background.ts         # Service worker + API routing + storage
β”‚   β”‚   └── popup.ts              # Popup logic + toggle state
β”‚   β”œβ”€β”€ store-assets/             # Chrome Web Store listing
β”‚   β”‚   └── description.txt       # Store description (short + full)
β”‚   β”œβ”€β”€ PRIVACY_POLICY.md         # Privacy policy for store submission
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   └── vite.config.ts
β”œβ”€β”€ backend/                      # Fact-checking Node.js API
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ index.ts              # Express server + CORS + rate limiting
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   └── check.ts          # /api/check + /api/cache/clear endpoints
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   β”œβ”€β”€ groq.ts           # Claim detection + dual-prompt comparison
β”‚   β”‚   β”‚   β”œβ”€β”€ wikipedia.ts      # Wikipedia REST API integration
β”‚   β”‚   β”‚   └── pubmed.ts         # PubMed NCBI API (medical claims only)
β”‚   β”‚   └── db/
β”‚   β”‚       └── cache.ts          # PostgreSQL connection + MD5 caching
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tsconfig.json
β”‚   β”œβ”€β”€ Procfile
β”‚   └── .env.example
└── README.md

πŸ”Œ API Reference

POST /api/check

Verify a factual claim.

// Request
{ "sentence": "The human body has 206 bones" }

// Response
{
  "result": "green",
  "reason": "Claim confirmed by Wikipedia source",
  "sources": ["Wikipedia"],
  "cached": false
}

POST /api/cache/clear

Clear cached verdict for a specific sentence.

// Request
{ "sentence": "The human body has 206 bones" }

// Response
{ "cleared": true }

GET /health

Health check endpoint.

{ "status": "ok", "timestamp": "2026-05-13T04:45:07.355Z" }

πŸ›‘οΈ How False Positives Are Prevented

TruthLens uses a 4-layer defense system to ensure correct facts never get red dots:

Layer Where What It Does
1. Smart Search wikipedia.ts Extracts keywords from claims instead of raw sentence search
2. Keyword Filter check.ts Removes sources that don't share β‰₯2 key words with the claim
3. AI Relevance Check groq.ts Asks "is this source about the same topic?" before comparison
4. Strict Prompts groq.ts RED only for direct, explicit contradictions with evidence

Medical claims bypass layers 2 & 3 β€” dangerous misinformation like "Aspirin is safe for children" must always reach the medical-expert prompt to get a proper RED verdict.


πŸ› οΈ Tech Stack

Component Technology
Extension TypeScript, Vite, Chrome Manifest V3
Backend Node.js, Express, TypeScript
AI Model Groq Llama 3.3 70B Versatile
Databases PostgreSQL (claim caching)
APIs Wikipedia REST, PubMed NCBI, Wikidata
Deployment Render (backend), GitHub (source)
Security CORS, express-rate-limit (30 req/min)

πŸ”’ Privacy

TruthLens respects your privacy:

  • βœ… Only sentence text is sent for verification
  • ❌ No personal information collected
  • ❌ No browsing history tracked
  • ❌ No login credentials accessed
  • ❌ No cookies used

Full privacy policy: extension/PRIVACY_POLICY.md


πŸ—ΊοΈ Development Timeline

Week Milestone Status
1 Project setup, extension scaffold, backend API βœ… Complete
2 MutationObserver, Groq integration, Wikipedia/PubMed βœ… Complete
3 Request queue, rate limiting, streaming detection βœ… Complete
4 Railway deployment, CORS, CSP bypass via service worker βœ… Complete
5 PostgreSQL caching, smart PubMed routing, MD5 hashing βœ… Complete
6 UI polish, sidebar, popup stats, store assets, Render migration βœ… Complete

🀝 Contributing

Contributions are welcome! This is a student open-source project.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is open source and available under the MIT License.


Built with ❀️ by Logesh Murugan

Powered by Groq Β· Wikipedia Β· PubMed Β· PostgreSQL

About

πŸ” Real-time AI hallucination detector β€” Chrome extension that fact-checks every sentence from ChatGPT, Claude, Gemini & Copilot using Wikipedia, PubMed, and Groq AI

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages