LegalBot PH
LegalBot PH is a chatbot that turns a G.R. number, case title or legal topic into a structured Supreme Court case digest. It was built as our undergraduate capstone thesis at Ateneo de Davao University (accepted November 2025), over Philippine Supreme Court decisions from 2005 to 2025.
- Role
- Researcher, Backend Developer
- Status
- Completed
- Timeline
- Aug 2025 – Nov 2025
- Stack
- Django, Django REST, Hugging Face, Python, Qdrant, BM25, Llama 3.3 70B via Together AI, SBERT legal embeddings, BERTScore, ROUGE, HHEM
The Problem
Philippine law students are assigned around 50 or more Supreme Court cases per course and must recite them by Facts, Issues and Ruling. One consulted student described preparing 54 cases for a single 3-hour recitation. The existing tools left a gap:
- E-libraries (SC E-Library, LawPhil) give free full text but no digests.
- General chatbots like ChatGPT write digests, but students said they were too broad and had to double-check every one against the source. That double-checking is the real cost. A digest that invents a ruling is worse than no digest, because a student may recite it in class or use it in legal writing. The problem was not summarization alone. It was summarization a student could trust.
My Role
Co-author and proposal lead on a three-person thesis team. I wrote the initial proposal and set the team's direction, then owned the data pipeline at the start of the system and the evaluation at the end of it.
Team: Chris Maynard Ampon, Mae Angela Espera, and me. Adviser: Adrian D. Ablazo, MSIT.
What I Owned
- Jurisprudence crawler. Built the scraper that collected decisions from authorized public sources and produced the gzipped JSONL corpus every other component depends on. It extracts case titles, G.R. and special numbers (A.M., A.C., OCA, B.M.), ponente, promulgation date and division, and strips site boilerplate while keeping the decision's paragraph structure.
- Deterministic routing design. Designed the regex-based routing so that exact identifiers (G.R. numbers, special numbers, ponente queries) go to an exact metadata lookup instead of semantic search or the model's memory.
- Requirements from users. Led the consultations with law students and graduates that defined what a usable digest must contain: procedural and substantive facts, issues framed as yes-or-no questions, both parties' contentions, the ruling with its reasoning, and the doctrine.
- Evaluation framework. Chose BERTScore as the primary semantic-similarity metric over n-gram-only metrics like BLEU, since a good digest paraphrases rather than copies. The harness pairs it with ROUGE and HHEM hallucination checks.
- Test set. Wrote the 100-query test set spanning 2005 to 2025 used to compare the LLM-only baseline against the full system.
- Model decision. Part of the call to drop the planned Law-LLM for hosted Llama 3.3 70B, after finding it was tuned for American law and could not fit a full case in its context window.
- Proposal and direction. Wrote the thesis proposal and set the research objectives the team built toward.
Technical and Product Decisions
The core decision was to route by query type: exact identifiers get an exact lookup, topics get hybrid search, and only then does an LLM write. Decisions marked (mine) are ones I made; the rest were team decisions. No LangChain is used: chunking, rank fusion and routing are written directly in Python on the Qdrant client.
Every query passes the LLM classifier first, except ponente queries. Case queries then hit the regex router: an ID found means an exact lookup and a digest from the full text; no ID means hybrid search.
Constraints
- Team and timeline: three undergraduates. Expert consultations ran from August to October 2025, and the final evaluation ran on November 5, 2025.
- Hardware: processing limits narrowed the corpus to decisions from 2005 to 2025 instead of the full archive back to 1901.
- No legal training on the team: the digest format came from consultations I led with law students and graduates, who defined what Facts, Issues, Ruling and Doctrine must contain.
- Public sources only: the corpus is limited to publicly accessible decisions, with no confidential records or personal data.
- Not legal advice: the tool is scoped as a study and research aid, and users were told so.
Result and Impact
Giving the model the actual case text cut detected hallucinations from 98.89% to 63.33% on the same 100 queries. That is a 35.56-point drop (about 36% relative), and 63% is still too high for anything beyond a study aid.