LexiVerify Pakistan — Empowering Access to Justice Through AI
Inspiration
Access to justice begins with access to understandable and reliable legal information. In Pakistan, legal judgments frequently contain complex terminology, lengthy judicial reasoning, statutory references, and extensive case histories. Understanding these documents can be challenging for ordinary citizens, law students, and individuals with limited access to professional legal assistance.
Furthermore, traditional legal document annotation is time-consuming, while conventional Large Language Models (LLMs) can generate inaccurate or unsupported legal information.
These challenges inspired us to develop LexiVerify Pakistan, an agentic retrieval-grounded legal document annotation framework that combines artificial intelligence, evidence verification, and incremental learning to make legal information more accessible, transparent, and trustworthy.
Our vision is to bridge the gap between artificial intelligence and the legal system while contributing to United Nations Sustainable Development Goal 16: Peace, Justice and Strong Institutions.
What It Does
LexiVerify Pakistan is an AI-powered web application designed to automate the annotation and analysis of legal judgments.
The framework combines Retrieval-Augmented Generation (RAG), coordinated AI agents, evidence verification, and human-in-the-loop incremental learning.
Its main features include:
- Automated legal document annotation.
- Retrieval of relevant Pakistani Supreme Court judgments.
- Identification of legal facts, issues, arguments, provisions, precedents, judicial reasoning, and final decisions.
- Verification of supporting evidence against original documents.
- Human-in-the-loop annotation review and correction.
- Incremental learning through persistent feedback memory.
- Interactive legal document analysis dashboard.
- Structured annotation export in JSON format.
- Offline processing with optional LLM integration.
Unlike conventional legal AI systems, LexiVerify Pakistan emphasizes documentary evidence, transparency, and human oversight rather than relying solely on generated responses.
How We Built It
We developed LexiVerify Pakistan using a modular, agent-based architecture in Python, supported by an interactive web interface built with HTML, CSS, and JavaScript.
1. Dataset Collection and Preprocessing
We utilized the Labeled Legal Cases for Supreme Court of Pakistan dataset available on Kaggle.
During dataset preprocessing:
- Total files processed: 2,809
- Successfully imported documents: 2,597
- Empty files excluded: 212
- Dataset download size: 22.3 MB
- Document retention rate: 92.45%
The successfully imported documents form the legal knowledge corpus for case retrieval. The original dataset's annotation schema remains to be confirmed before formal supervised evaluation.
2. Agentic AI Architecture
We designed the framework around six coordinated components:
- Preprocessing Agent: Processes and segments legal documents.
- Retrieval Agent: Retrieves relevant legal passages using BM25-based information retrieval.
- Annotation Agent: Categorizes legal information using an offline classification engine or optional LLM integration.
- Verification Agent: Checks whether supporting quotations exist in the original document.
- Human Review Agent: Enables users to approve or correct generated annotations.
- Incremental Learning Agent: Stores reviewed examples and retrieves them during future annotation tasks.
3. Evidence Verification
To address the problem of AI hallucinations, we implemented a source-grounding mechanism that checks generated supporting quotations against the original legal document.
This mechanism improves traceability and helps users distinguish source-supported annotations from unsupported quotations. Human review remains necessary to determine whether the evidence is legally relevant and correctly interpreted.
4. Incremental Learning
We implemented a persistent feedback memory using SQLite. When users review or correct an annotation, the framework stores the reviewed example for future retrieval.
This nonparametric incremental learning approach allows the system to incorporate new feedback without repeatedly retraining the entire language model.
5. Web Application Development
We developed a user-friendly web interface that enables users to search legal cases, analyze documents, inspect supporting evidence, review annotations, and export structured results.
Technologies Used
- Python
- HTML, CSS, and JavaScript
- Large Language Models (LLMs)
- Retrieval-Augmented Generation (RAG)
- Natural Language Processing (NLP)
- BM25 Information Retrieval
- OpenAI API (optional integration)
- SQLite
- Kaggle and KaggleHub
- Visual Studio Code
Challenges We Ran Into
Dataset Quality and Preprocessing
The legal dataset contained 212 empty files. We addressed this challenge by implementing an automated preprocessing mechanism that excludes empty documents while preserving usable legal text.
AI Hallucinations
LLMs can generate convincing but unsupported legal information. We addressed this risk through retrieval grounding, exact quotation verification, and human review.
Complex Legal Terminology
Pakistani legal judgments contain specialized terminology, statutory references, and complex sentence structures. Designing meaningful annotation categories and identifying relevant passages required careful consideration.
Incremental Learning
Continuously retraining an LLM requires significant computational resources. To overcome this limitation, we implemented a lightweight, retrieval-based feedback memory using SQLite.
Environment and Dependency Management
During development and setup, we encountered Python dependency installation warnings, command-line argument errors, and dataset configuration challenges. Resolving these issues helped us better understand software dependency management and application deployment.
Accomplishments That We're Proud Of
- Developing a functional legal document annotation prototype.
- Successfully importing 2,597 Pakistani Supreme Court legal documents.
- Designing a modular agentic AI architecture.
- Implementing documentary evidence verification.
- Developing persistent human-feedback memory.
- Creating a searchable legal knowledge corpus.
- Building an interactive web application.
- Passing eight automated prototype functionality tests.
- Designing an AI solution focused on responsible innovation and access to justice.
We are particularly proud of combining legal intelligence, explainable AI, information retrieval, and human oversight into a single practical framework.
What We Learned
Through this project, we gained practical knowledge of:
- Agentic artificial intelligence and multi-stage AI workflows.
- Large Language Models and Retrieval-Augmented Generation.
- Legal Natural Language Processing.
- Dataset collection, preprocessing, and indexing.
- Information retrieval and evidence-grounded AI.
- Human-in-the-loop machine learning.
- Incremental learning and persistent memory.
- Full-stack web application development.
- Software testing and debugging.
- Ethical and responsible AI development.
Most importantly, we learned that artificial intelligence should not simply generate information; it should enable users to understand, inspect, and verify the information it provides.
Social Impact
LexiVerify Pakistan aims to make legal information more accessible to:
- Ordinary citizens seeking legal information.
- Lawyers and paralegals.
- Law students and academic researchers.
- Legal-aid organizations.
- Individuals with limited access to professional legal resources.
By reducing repetitive legal research work and promoting transparent AI-generated annotations, our project seeks to contribute to a more accessible, informed, and inclusive legal environment.
What's Next for LexiVerify Pakistan
Our future development roadmap includes:
- Formal evaluation using real legal annotation benchmarks.
- Semantic vector retrieval and embedding-based search.
- Fine-tuning legal-domain language models.
- Advanced continual learning techniques.
- English and Urdu multilingual support.
- PDF document processing and OCR.
- Legal citation and precedent verification.
- Explainable confidence scoring.
- Collaboration with legal professionals and legal-aid organizations.
- Cloud deployment and public accessibility.
- Expansion to additional Pakistani courts and legal datasets.
Conclusion
LexiVerify Pakistan represents a step toward trustworthy, transparent, and socially responsible legal artificial intelligence.
By combining agentic AI, retrieval-grounded language models, evidence verification, and incremental learning, we aim to transform complex legal documents into accessible and structured knowledge.
Our goal is not to replace legal professionals but to empower them and the wider community with more accessible and verifiable legal information.
LexiVerify Pakistan — Making justice more accessible, one verified annotation at a time.
Built With
- agentic-ai
- artificial-intelligence
- bm25
- css3
- document-annotation
- evidence-verification
- explainable-ai
- html5
- human-in-the-loop
- incremental-learning
- information-retrieval
- javascript
- json
- kaggle
- kagglehub
- large-language-models
- legaltech
- machine-learning
- natural-language-processing
- openai-api
- rest-api
- retrieval-augmented-generation
- sqlite
- studio
- visual