The Problem: Legal Access at Scale
Legal representation in Uganda — and across East Africa broadly — remains inaccessible to the majority. A single consultation with a qualified advocate can cost more than a week's income for the average Ugandan. Statutory laws are publicly available but practically inaccessible: dense PDFs, legal jargon, and documents spread across multiple government repositories.
The goal of **Legal Adviser** was simple in statement, complex in execution: give every Ugandan instant access to accurate, cited, legal guidance on their rights and obligations under Ugandan law.
The Technical Challenge: Zero Hallucination in High-Stakes Advice
The most dangerous failure mode in a legal AI system is confident hallucination — the model inventing a statute, fabricating a section number, or misquoting a clause. In legal contexts, a wrong citation can lead to catastrophic real-world consequences.
Standard LLM deployments — even with the most capable models — hallucinate in specialized legal domains because their training data contains relatively little Ugandan statutory text compared to common law jurisdictions.
The solution was a purpose-built RAG system with a citation verification layer: the model is not allowed to cite any statute unless that exact citation was retrieved from the verified index.
The Data Pipeline
We began by digitising and cleaning the core Ugandan legal corpus:
- **1995 Constitution of Uganda** — all 287 Articles with amendments - **Companies Act, 2012** — corporate registration, governance, dissolution - **Employment Act, 2006** — worker rights, termination, wages, leave entitlements - **Landlord and Tenant Act, 2022** — tenancy agreements, eviction procedures, rent disputes - **Land Act (Cap 227)** — land tenure, customary ownership, registration - Additional Statutory Instruments across commercial and family law
Documents were split into semantically coherent chunks using hierarchical chunking — respecting section and article boundaries rather than splitting at arbitrary character counts. Each chunk was tagged with metadata: Act name, year, section, article, and clause identifiers.
Hybrid Retrieval for Legal Precision
Legal queries are unusual compared to general knowledge questions. Users often know the approximate law they need ("something about employment termination") without knowing exact terminology. But when they do know terminology ("Section 64 of the Employment Act"), exact match is critical.
We implemented **hybrid retrieval** combining:
1. **Dense vector search** using Gemini text embedding models — captures semantic similarity even when phrasing differs. 2. **Sparse BM25 keyword matching** — critical for exact statute references, section numbers, and legal terminology.
Results from both retrievers are merged and re-ranked using reciprocal rank fusion before being passed to the generation model.
The Citation Verification Filter
Before the model composes any response, a verification step cross-checks every statutory reference in the proposed output against the retrieved chunks. If a reference cannot be confirmed in the retrieved context, the model is instructed to either omit it or explicitly note that it could not verify the source. This single step reduced hallucinated citations from approximately 8% (base Gemini with a generic prompt) to under 0.6% in internal testing.
Real-Time Voice Consultation
For users who find typing less natural than speaking — particularly in rural areas or for older users unfamiliar with text-based interfaces — we integrated Gemini Live API for real-time bidirectional voice consultation. Users can describe their legal situation in plain Luganda or English, hear the AI respond in natural speech, and ask follow-up questions in a fluid conversation.
The voice pipeline architecture: browser captures audio -> streams to Next.js API route via WebSocket -> forwarded to Gemini Live -> audio response streamed back and played immediately. End-to-end latency averages 380ms in East African network conditions.
Outcomes
Legal Adviser launched with 4,000 free consultation tokens per registered user — enough for approximately 15-20 substantive legal queries. Users are then invited to purchase token top-ups for continued access at a fraction of the cost of any human consultation.
The platform handles land disputes, employment rights, tenancy questions, company registration queries, and constitutional rights explanations — with cited sources users can verify themselves.