Inspiration
Access to justice is expensive and slow. Friends facing urgent legal issues got wrong answers from generic chatbots. We set out to build a system that reads the law, cites it verbatim, and routes users to the right tools or professionals.
What it does
- Answers legal questions with cited passages from official statutes.
- Retrieves official forms (e.g., Ontario LTB N5) and lawyer referral options.
- Keeps conversations stateful and structured, never “winging it.”
- Generates clean PDFs from the final guidance.
How we built it
Tech Stack
- Frontend: Next.js 14 + Tailwind (RSC, dark premium UI).
- Backend: FastAPI with CORS for Vercel/Edge.
- Orchestration: LangGraph state machine (Router → Research → Generator).
- Model: Google Gemini 2.0 Flash with structured output (Pydantic schemas).
- Embeddings: text-embedding-004 (768‑dim).
- Memory: 16,170 official legal document chunks in MongoDB Atlas Vector Search (HNSW).
- Querying: Jurisdiction pre-filter → vector search → synthesis with citations.
- Endpoints: POST /chat (thread_id), POST /generate-pdf, GET /health.
- Infra: Vercel (frontend), Railway (backend), MongoDB Atlas (data).
Architecture
- Router classifies intent, topic, jurisdiction.
- Research runs Atlas similarity_search with pre_filter to eliminate cross‑jurisdiction noise.
- Generator returns structured JSON: explanation, citations, options (buttons for forms/referrals).
- Tools: Official Form Finder and Lawyer Referral integrated into the graph
Challenges we ran into
- Production DB/TLS connectivity and IP allowlisting.
- Consistent npm/python tooling across machines (lockfiles, pyenv).
- Designing prompts that force citations and avoid hallucinations.
- Jurisdiction bleed in vector search — solved via strict pre_filter by jurisdiction, better chunking/metadata, and tuned HNSW params. -Reliable structured outputs with citations — enforced Pydantic schemas, validators, and “cite-only-from-context” prompts.
Accomplishments that we're proud of
- End‑to‑end deployed demo with sub‑second retrieval (~0.4s).
- Deterministic state graph routing and structured outputs.
- Clean UX with citation rendering and PDF export. ## What we learned
- LangGraph enables reliable multi‑step reasoning vs. linear chains.
- MongoDB Atlas HNSW with pre‑filters beats naive RAG on jurisdictional precision.
- Strict output schemas are key to trust in legal contexts ## What's next for MikeRoss
- “Saul Goodman” educational mode.
- Voice calling workflow (“Call my lawyer”).
- DocuSign-style auto‑fill for retrieved PDFs.
Built With
- fastapi
- google-gemini-2.0-flash
- langgraph
- mongodb-atlas-vector-search
- next.js
- pydantic
- python-3.11
- railway
- tailwind-css
- text-embedding-004
- vercel
Log in or sign up for Devpost to join the conversation.