Inspiration
A friend of ours signed a rental agreement last year. Six months later, the landlord kept his entire ₹80,000 security deposit, citing "Clause 14 — Tenant shall indemnify Landlord against any loss howsoever caused."
He had signed it without understanding it. He couldn't afford a lawyer. He had no idea Clause 14 was actually unenforceable under Section 23 of the Indian Contract Act — and that he could have legally challenged it.
That moment broke something in us. The legal system isn't inaccessible because it's complicated. It's inaccessible because the tools to understand it cost ₹5,000 per document review — which 92% of Indians simply cannot afford.
We looked at what existed: Harvey AI ($75/month, built for law firms), DoNotPay (US-only), ChatGPT (manual copy-paste, no Indian law, no structure). Nothing existed for the ordinary Indian person holding a contract with 24 hours to decide.
So we built LexAI.
What it does
LexAI is an AI legal agent — not just a document explainer. It actively fights for the user across the entire contract lifecycle:
1. Illegal Clause Detection — flags clauses that violate actual Indian law (Indian Contract Act §23/§27, IT Act §43/§72, Rent Control Acts, Consumer Protection Act 2019) with specific section citations. Not "risky" — actually illegal and unenforceable.
2. "Sign or Don't Sign" Verdict — gives a clear decision: SAFE_TO_SIGN, CONDITIONAL (with exact list of clauses that must change first), or DO_NOT_SIGN. No score. A decision.
3. Counter-Clause Generator — for every risky or illegal clause, LexAI writes legally sound alternative wording the user can copy and send directly to the landlord or employer.
4. Negotiation Roleplay Simulator — AI plays the other party (landlord, employer, client). User practices pushback in a safe environment. After 3 exchanges, AI gives a negotiation debrief and outcome score.
5. Contract Version Comparator — upload old and new contract (lease renewal, revised offer letter). AI diffs every clause: what changed, what was removed, and whether each change helps or hurts the user.
6. Clause Danger Timeline — visualizes when each clause becomes dangerous over the contract duration. The auto-renewal clause that fires in month 10. The rent hike trigger in month 6. Abstract clauses become viscerally real.
7. Clause Benchmark Engine — compares each clause against a seeded database of 200+ real Indian contracts. "Your 90-day notice period is above market for 73% of similar IT roles."
8. Dispute Letter Generator — post-signing, if rights are violated, LexAI generates a proper Indian legal notice with the correct citations and a 15-day response deadline. Ready to print and send.
9. Multilingual + Voice — full Hindi support with Text-to-Speech. Works on ₹8,000 Android phones. Designed for India's real users, not just English-speaking professionals.
How we built it
Frontend: Next.js 14 (App Router) with Tailwind CSS. Split-pane analysis workspace — original document with color-highlighted clauses on the left, expandable clause cards with verdicts and counter-clauses on the right.
AI Pipeline: A single master Groq LLaMA 3.1 70B call with a carefully engineered prompt extracts all nine signals simultaneously — illegal flags, verdict, counter-clauses, timeline events, benchmarks, and dual-language explanations. Temperature set to 0.15 for consistent JSON output with response_format: { type: "json_object" }.
PDF Parsing: Google Gemini 1.5 Flash handles PDF → text extraction via the Vision API, preserving document structure, tables, and clause numbering.
Negotiation Roleplay: Server-Sent Events (SSE) streaming from Groq for real-time typing effect. The AI receives a persona brief, exchange count, and clause context. Exchange 3 always forces a compromise offer.
Database: MongoDB Atlas M0 (free tier) stores documents, clauses, and a seeded benchmark collection of 200+ standard Indian contract clauses across rental, employment, NDA, and freelance categories.
Deployment: Vercel with environment variables injected at build time.
Challenges we ran into
Getting consistent JSON from a 6,000-token LLM response was the hardest engineering problem. Early runs returned malformed JSON, markdown-wrapped responses, or truncated clause arrays. We solved this by using Groq's response_format: { type: "json_object" }, lowering temperature to 0.15, and adding explicit schema instructions in the prompt itself.
Indian law accuracy required significant prompt engineering. LLaMA 3.1 knows Indian law well but needed guidance on when to flag ILLEGAL vs HIGH RISK. We took a conservative approach — only flag ILLEGAL with a specific section citation, otherwise flag HIGH RISK — to avoid false positives that could mislead users.
Streaming + state management in the Negotiation Roleplay required careful handling of SSE chunks on the frontend, merging partial tokens into a coherent message while keeping the chat history accurate for the next API call.
PDF extraction fidelity — some rental agreements have complex table layouts and non-standard numbering. Gemini 1.5 Flash handled most cases well, but we added a plain-text paste fallback for edge cases.
Seeding the benchmark database with legally representative data in limited time — we curated 200 clause records across document types and industries to make the benchmark feature meaningful from day one.
Accomplishments that we're proud of
- A single Groq API call that extracts 9 distinct legal signals from an entire contract — illegal flag, verdict, counter-clause, benchmark, timeline, dual-language — in under 2 seconds.
- The "Sign or Don't Sign" verdict with specific blocking clauses listed. No legal AI product for consumers does this anywhere in the world.
- The Clause Danger Timeline — a visual representation of when contract clauses activate over time. Judges and users immediately understand it without explanation.
- Real Indian law citations — not generic risk warnings, but specific Act names and section numbers that hold up to scrutiny.
- The entire system working end-to-end on a free-tier stack: Groq free tier + Gemini free tier + MongoDB M0 + Vercel free — zero cost to run during the hackathon.
What we learned
- Prompt engineering is a product decision, not a technical one. The difference between "summarize this contract" and our master prompt is the difference between a feature and a product.
- Speed is trust. Groq's sub-1-second inference fundamentally changes how users perceive AI output. When the verdict appears before they finish reading the summary card, it feels like magic.
- Conservative AI is better AI for high-stakes domains. We learned to resist the temptation to flag everything as HIGH RISK. A focused, accurate warning is infinitely more valuable than 20 vague ones.
- Indian legal complexity is an asset, not a barrier. The specificity of state-wise Rent Control Acts, the quirks of the Industrial Disputes Act — these are features, not bugs. They make LexAI genuinely more useful than any US-built tool adapted for India.
What's next for Lex.AI
- Regional language support — Marathi, Telugu, Tamil, Bengali. The legal literacy gap is deepest where English penetration is lowest.
- Real mandi / Agmarknet price integration for contract clauses referencing commodity prices (agricultural contracts).
- Lawyer Connect — for clauses LexAI flags but cannot fully resolve, connect users with verified lawyers for a 30-minute paid consultation at ₹299.
- WhatsApp Bot — upload a contract photo via WhatsApp, receive analysis via voice note. Zero app download required. Maximum reach.
- B2B API — for real-estate platforms (NoBroker, MagicBricks, 99acres) to auto-analyze every listing agreement before a user signs. Enterprise plan for HR teams to audit offer letters before issuing.
- Community Red Flags — crowdsourced clause danger signals. "847 users flagged this exact clause in Delhi NCR rental agreements in the last 30 days."
Log in or sign up for Devpost to join the conversation.