Contract-review RAG platform
BriefPilot
Contract review that cites the exact clause, reconciles amendments and grades every contract against your playbook.
My role: Lead AI engineer and full-stack architect: design, backend, frontend, AI pipeline and deployment
- RAG
- FastAPI
- pgvector
- Claude + GPT-4o
- Stripe

Overview
BriefPilot is a full-stack document intelligence platform for contract analysis. A FastAPI backend runs a RAG pipeline — PDF/OCR ingestion, legal-aware chunking, pgvector embeddings — and streams LLM answers that cite their source clauses. On top sit a multi-document reconciliation engine, a batch liability auditor and a playbook checker.
The challenge
Contract review is slow because the answer to a simple question, such as "what is our liability cap?", is often spread across a base agreement, two amendments and a rider. Generic chatbots make this worse: they answer confidently, cite nothing, and cannot tell which version of a clause still applies.
The goal was a tool a lawyer or procurement lead could trust: every answer tied to the exact clause it came from, a clear statement of which document governs when versions conflict, and checks that compare each new contract against the company's own standard positions.
How it works
- 1Upload PDF / scan
- 2OCR + legal chunking
- 3Embed → pgvector
- 4Retrieve clauses
- 5Claude / GPT-4o
- 6Cited answer (SSE)
Architecture
Documents enter through an ingestion service that extracts text with pdfplumber and PyPDF2, falling back to Tesseract OCR for scanned pages. The text is split with a splitter configured on legal delimiters (Section, Article, Clause), so each chunk is a unit a lawyer would recognise. Chunks are embedded with OpenAI's text-embedding-3-small and stored in PostgreSQL with pgvector, next to the relational data for users, documents and plans.
At question time the FastAPI backend retrieves the closest clauses by cosine distance, builds a grounded prompt and streams the answer token by token over Server-Sent Events, with clause-level citations. A model router sends requests to Claude or GPT-4o and fails over automatically. Before any model call, a semantic cache checks whether a question with cosine similarity of 0.94 or higher has already been answered.
The reconciliation engine uses Pydantic-validated structured output to decide which clause governs across a base agreement, amendments and riders, and logs every superseded clause with the reason. The batch auditor and playbook checker reuse the same retrieval layer. Around it sit Supabase Auth with Google and GitLab OAuth and row-level security, Stripe subscriptions with a reconciliation path, plan-based daily quotas, a span-level request tracer, and n8n workflows for multi-step ingestion and notifications.
What I built
End-to-end RAG pipeline
PDF extraction with OCR fallback, chunking on Section / Article / Clause delimiters, embeddings in Postgres + pgvector, token-streamed answers with clause-level citations.
Reconciliation engine
Pydantic-validated structured output decides which clause governs across a base agreement, amendments and riders. Every superseded clause is logged and explained.
Multi-model routing
Claude and GPT-4o with automatic failover, plus a semantic query cache (cosine ≥ 0.94) that cuts repeat inference cost.
Playbook checker
Users save their standard negotiating positions; each incoming contract is graded per rule with quoted evidence and severity-based verdicts.
Batch liability auditor
Risk audits across many contracts at once, with branded PDF audit certificates produced by a CSS paged-media print engine.
Billing, auth, tracing
Stripe subscriptions with signature-verified webhooks and a reconciliation path, Supabase Auth with Google/GitLab OAuth and RLS, and a custom span-level request tracer.
Engineering decisions
- Chunk on legal structure, not character count, so a retrieved chunk is a whole clause a lawyer would recognise.
- Use schema-validated structured output for reconciliation so the result can be audited, not just read.
- Cache by meaning, not by string: a 0.94 cosine threshold catches rephrased repeat questions without serving wrong answers.
- Treat Stripe webhooks as unreliable and reconcile against Stripe on login, so a missed event never strands a paying user.
Results
- Live product at briefpilot.in with a free tier and paid plans.
- Every answer cites the clause it came from; superseded clauses are logged with a reason.
- Repeat questions served from a semantic cache (cosine ≥ 0.94) instead of a new model call.
- Automatic failover between Claude and GPT-4o keeps answers flowing during a provider outage.
Stack
- Frontend
- React 18, Vite, Tailwind CSS
- Backend
- Python 3.11, FastAPI, Uvicorn
- AI / LLM
- Claude, GPT-4o, text-embedding-3-small, LangChain (LCEL), Pydantic v2
- Documents
- Tesseract OCR, pdfplumber, PyPDF2, python-docx
- Data
- PostgreSQL + pgvector, SQLAlchemy, Alembic
- Platform
- Supabase Auth (JWT, RLS), SSE streaming, Stripe, n8n
Related services
Need something like this?
I can build a version of this for your product, your data and your stack.
Start a project