Legal Chatbot
AI-powered legal assistance and a virtual courtroom for Indian practice, built as an agentic RAG system: retrieval and grounding before the model ever answers.
Architecture
Four entry points — a typed question, voice, an uploaded document, or the virtual courtroom itself — all funnel into one retrieval-and-reasoning pipeline. Legal text is retrieved and ranked before Llama 3.3 70B ever sees it, so answers are grounded in the actual corpus rather than the model's memory.
User Interaction
Multiple ways to interact
Text Query
Voice Input
Document Upload
Virtual Courtroom
Input Processing
Convert and prepare input
Deepgram STT
Query Processing
Document Processing
Chunking
Legal Knowledge & Retrieval
Find the most relevant legal text
Legal Corpus
Vector / Retrieval Index
Retriever
Retrieval Ranking
AI Reasoning
Generate a grounded response
Context Construction
Llama 3.3 70B (Groq)
Output
Deliver the result
Legal Explanation
Document / Clause Analysis
Virtual Courtroom Response
Response delivered to user
As text, voice, or inside the virtual courtroom
How it works
- 01 — User interaction: a text query, voice input, an uploaded document, or the virtual courtroom interface — four entry points into the same backend.
- 02 — Input processing: voice goes through Deepgram speech-to-text first; documents are processed and chunked; everything else becomes a normalised query.
- 03 — Legal retrieval: the query is matched against the indexed legal corpus, and a retriever ranks the chunks that actually matter.
- 04 — Context construction: the query and the ranked legal chunks are assembled into one grounded prompt — the model never sees the raw corpus directly.
- 05 — LLM reasoning: Llama 3.3 70B, served through Groq, generates the answer from that grounded context.
- 06 — Response: delivered back as a legal explanation, a document/clause analysis, or a reply inside the virtual courtroom interface.
- Three pipelines share this one engine: a research pipeline (about six agents that retrieve, draft and check), a courtroom pipeline (speaker diarisation with PyAnnote and live contradiction alerts), and a simplifier that turns legalese into plain language.
Model evolution
Development iteration — one model replacing the last as limits showed up, not several models running together in production.
My contribution
Key features
- RAG-based legal query answering
- Document upload and clause analysis
- Voice interaction via Deepgram STT
- Virtual courtroom interface
- Grounded, citation-aware responses
Team
- Legal Chatbot was built by a 3-person team as a group project, not solo.
- Retrieval, agent orchestration, speech integration and the virtual courtroom interface were built together across the team.
What I worked on
- RAG architecture and the retrieval workflow — the query-to-context path described in the architecture above.
- Legal query processing and retrieval ranking.
- Grounding and context construction for the LLM.
- Model experimentation and the move from local models to Llama 3.3 70B on Groq.
Results
- Phi-3 could not hold the agentic flow. A smaller local Llama worked but took minutes per answer. Moving heavy reasoning to Groq's 70B brought it down to 90 to 180 seconds, fast enough for a real session.
- The team measured roughly a 70% cut in legal-research time on the research pipeline.
In code
ctx = retrieve(query, k=8) # local store, 500-char chunks
draft = llm(prompt(query, ctx)) # Groq Llama 3.3 70B, heavy reasoning
for claim in split_claims(draft):
tag = "[FROM RAG]" if grounded_in(claim, ctx) else "[FROM WEB]"
claim.annotate(tag)
answer = verifier_agent(draft, acts=ctx) # conflict -> statute text wins▊ Grounding pass: every claim is tagged by source, then a verifier agent resolves conflicts.
Slides
The full project deck. You can read it right here.
Comments
Thoughts or questions on this project? Leave a note below.
Loading comments…