GROUNDING LEGAL GUIDANCE IN STATUTE: A RETRIEVAL-AUGMENTED GENERATION SYSTEM FOR ACCESS TO JUSTICE IN PAKISTAN
Abstract
Pakistan's justice system carries an estimated 2.26 million pending cases, and the World Justice Project ranks the country near the bottom of its civil-justice and delay indices. For ordinary citizens, the binding obstacle is rarely the law itself but the cost and opacity of obtaining reliable first-line legal guidance. General-purpose large language models appear to fill this gap, yet the legal-hallucination literature shows they fabricate citations and misstate doctrine at alarming rates, which makes their unguarded use in a legal setting unsafe. We present the AI Justice Assistant, a retrieval-augmented generation (RAG) platform that answers lay legal questions by grounding a large language model in a curated corpus of Pakistani statutes rather than in its parametric memory. The system classifies a described problem into Civil, Criminal, or Family law, retrieves the most relevant statutory passages through pgvector similarity search, generates a grounded answer with source attribution, and recommends jurisdiction-appropriate courts and specialization-matched lawyers. It is built as a three-tier serverless application using React, Supabase edge functions, and PostgreSQL with the pgvector extension, with Google Gemini accessed through OpenRouter for embedding and generation. Acceptance testing exercised the full functional surface registration, authentication, grounded chat, classification, court and lawyer recommendation, history, and logout with all eight defined test cases passing. Non-functional measurements met or exceeded every target: a 3.2-second mean response time against a four-second budget, 420-millisecond recommendation latency, 92% case-classification accuracy, and 99.6% availability. We are explicit that these are system-acceptance results rather than a benchmarked study of answer quality, and we specify a reference-free RAGAS protocol faithfulness, answer relevancy, context precision, and context recall as the appropriate next-stage measurement. The work contributes a fully localized, end-to-end RAG architecture for Pakistani legal guidance; an integration of classification, retrieval-grounded consultation, and recommendation in a single platform; and a candid evaluation and responsible-AI discussion that situates the system against current legal-AI reliability evidence and marks the boundary between legal information and legal advice.
Keywords : access to justice; retrieval-augmented generation; legal NLP; large language models; case classification; pgvector; semantic search; responsible AI; Pakistan.












