Inspiration
During Nigerian election cycles, viral misinformation—ranging from doctored polling unit notices and misleading claims about BVAS or IReV transmission to false rules on PVC collection and candidate substitution—spreads faster across messaging groups than official clarifications can reach citizens. At the same time, trusting an unguarded AI chatbot to pronounce political "truth" introduces unacceptable risks: hallucinated legal citations, prompt injection from malicious links, and partisan bias.
ElectionTruth AI was inspired by a core civic principle: AI should act as a fast, traceable research assistant—never an automated judge. We set out to build a non-partisan, evidence-grounded platform where citizens can verify electoral claims in English, Nigerian Pidgin, Yoruba, Hausa, and Igbo, while every public assessment remains gated behind traceable primary law and authorised human fact-checkers.
What It Does
- Multi-Modal Claim Investigation (
/verify): Citizens can submit suspicious electoral claims via pasted text, a public webpage URL, or an uploaded screenshot/flyer image (processed with Gemini Vision OCR and editable before re-running). - Clean & Structured Link Extraction: Submitted URLs pass through an SSRF-guarded fetcher that strips navigation bars, scripts, and footer clutter, decodes entities, and structures the page into a headline, publisher, summary, key points, and clean article body.
- Cross-Lingual RAG & Grounded Civic Assistant (
/assistant): Users can submit claims or ask electoral questions in English (en), Nigerian Pidgin (pcm), Yoruba (yo), Hausa (ha), or Igbo (ig). Non-English queries are normalised into English for retrieval against curated primary Nigerian sources (Electoral Act 2022, INEC Guidelines, Constitution, and accredited fact-checks) and answered in the user's selected language. - Human-in-the-Loop Reviewer Studio (
/admin): Every AI output enters adraft_readyqueue. Authorised reviewers inspect retrieved passages, verify OCR accuracy, adjust evidence relationships, and executeapprove,revise,request_more_evidence,reject, orunpublishactions with a persistent audit log.
How We Built It
Architecture & Tech Stack
- Frontend: React 19, TypeScript, React Router 7, Tailwind CSS v4, Motion (
reducedMotion="user"), and custom editorial Nigerian civic photography with frosted glassmorphism and responsive card interactions. - Backend & Persistence: Node.js (
v22+), Express 4, and zero-native-dependency built-innode:sqlite(DatabaseSyncwith WAL mode and foreign keys) managing 13 relational tables across submissions, claims, curated source versions, evidence passages, assessments, review actions, corrections, and audit logs. - AI Engine:
@google/genai(gemini-4-hydrogen) for structured Vision OCR, multilingual claim normalisation, webpage briefing extraction, grounded assessment drafting, and civic Q&A.
Hybrid Electoral Evidence Scoring
To rank curated passages while prioritizing primary electoral statutes over secondary commentary, each candidate passage $d$ is scored against the domain-expanded query token set $T_q$ (expanding Nigerian electoral terms such as BVAS, IReV, PVC, CVR, and EC8A) and extracted entities $E$:
$$ S(q, d) = \min!\left(0.99,\; 0.65 \cdot \frac{c(q, d)}{\max!\left(4,\; \sqrt{4|T_q|}\right)} + 0.25 \cdot B_{\text{phrase}}(q, E, d) + A(d)\right) $$
where:
- $c(q, d)$ is the count of overlapping query tokens in passage $d$ (requiring $c(q, d) \ge 2$ and $S(q, d) \ge 0.24$ to qualify),
- $B_{\text{phrase}}(q, E, d)$ adds $+0.15$ per exact query term substring match and $+0.40$ per matched named entity, and
- $A(d) \in {0.12,\; 0.04}$ applies an authority weight distinguishing primary statutory/INEC sources ($0.12$) from secondary fact-checking reports ($0.04$).
Deterministic Citation Validation Gate
Every AI-generated draft passes through a strict server-side citation filter before reaching the reviewer queue:
$$ \mathcal{C}{\text{valid}} = \left{ p \in \mathcal{C}{\text{draft}} \;\middle|\; p \in \mathcal{E}_{\text{retrieved}} \right} $$
If any cited evidence_passage_id is fabricated or if no valid supporting/contradicting passage survives ($\left|\mathcal{C}_{\text{valid}}\right| = 0$ for decisive verdicts), the pipeline rejects the hallucinated reference and automatically downgrades the draft label:
$$ \text{label}{\text{draft}} \in {\texttt{supported}, \texttt{contradicted}} \;\land\; \mathcal{C}{\text{valid}} = \emptyset \implies \text{label}_{\text{final}} \leftarrow \texttt{insufficient_evidence} $$
Challenges We Faced
- Preventing AI Hallucinations & Prompt Injection: Untrusted links, screenshots, and social posts can contain adversarial instructions or missing context. We wrapped all untrusted inputs and retrieved passages inside strict XML delimiters (
<untrusted_submission>,<untrusted_webpage>) and paired structured JSON outputs with deterministic post-generation citation checks. - Extracting Clean Content from Messy News & Civic Links: Raw HTML scraping initially pulled navigation menus, cookie banners, and broken entities into the claim pipeline. We built a two-stage cleaner: deterministic HTML boilerplate stripping (
<nav>,<footer>,<aside>,<script>) with<article>/<main>prioritization, followed by AI/fallback structuring into clean summaries and key points. - Cross-Lingual Verification Against English Legal Statutes: Nigerian citizens often discuss elections in Nigerian Pidgin, Yoruba, Hausa, or Igbo, while the Electoral Act 2022 and INEC manuals are written in English. Designing an intermediate English normalisation step allowed local-language queries to accurately match statutory passages before generating responses back in the citizen's preferred language.
- Cross-Platform Local Environment Portability: Resolving native optional dependency conflicts between
esbuild,vite, and Windows Node.js toolchains while keeping SQLite persistent via built-innode:sqliterequired careful dependency alignment so the full-stack app runs out of the box locally and in the cloud.
What We Learned
- Guardrails beat prompts alone: Separating LLM reasoning from deterministic code validation (citation ID matching, SSRF IP/DNS blocking, magic-byte file checks, and RBAC publication gates) makes civic AI dramatically more trustworthy.
- Saying "Insufficient Evidence" is a feature, not a bug: In electoral verification, refusing to guess on unverified local polling-unit rumours protects public trust far more than forcing a confident verdict.
- Human accountability completes the loop: Giving reviewers side-by-side access to original screenshots, cleaned URL briefings, OCR confidence notes, and re-retrievable evidence passages turns AI from a black box into a transparent editorial workbench.
Built With
- css3
- express.js
- gemini-api
- google-ai-studio
- google-cloud-run
- google-gemini
- google-genai
- html5
- motion
- node.js
- ocr
- rag
- react
- react-router
- rest-api
- sqlite
- tailwindcss
- typescript
- vite