Inspiration
Small businesses and freelancers often spend hours and money drafting NDAs, service agreements, or rental contracts—or worse, sign poorly-written templates that expose them to legal risk. We set out to create a one-click, lawyer-in-the-loop experience that produces tailored contracts and explains what each clause means.
What ContractGen does
- Generate – Pick a template (NDA, Service Agreement, Employment, or Rental). Add parties, jurisdiction, tone, and any custom clauses.
- Analyse – Upload any PDF or DOCX contract to receive an instant summary, risk assessment, and improvement suggestions.
- Iterate – Accept or reject suggestions, chat with the model (“Shorten clause 4… add arbitration under Indian law”), and export the polished DOCX.
- Context Boost – When a user’s question requires external references (for example, “Is this arbitration clause valid in California?”), ContractGen automatically calls the Google Custom Search API, retrieves the top three authoritative snippets, appends them to the prompt, and returns a citation-rich answer.
- One-stop Canvas – All interactions (generation → analysis → edits → export) happen on a single, streamlined interface.
How we built it
- Backend: Python and Flask handle generation, analysis, chat, export, and context search routes.
- GenAI: Google Gemini 2.0 Flash for clause drafting, risk detection, and plain-English explanations.
- Dynamic Context Enrichment: A small
search_context()helper hits the Google Custom Search API wheneverFORCE_WEB_SEARCHis on or the user prefixes a message with “search context: …”. The returned snippets are injected into the prompt to improve factual accuracy without inflating tokens. - File parsing:
PyPDF2andpython-docxextract text;html2docxconverts rich HTML back to DOCX. - Front-end: Vanilla JavaScript and Tailwind CSS for fast, responsive loading.
- Deployment: Render.com (free tier) with persistent uploads on AWS S3.
Challenges faced
- Balancing legal accuracy and hallucination: we chain model calls (clause-level → contract-level) and use Google Search snippets as real-world anchors.
- Handling large PDFs: chunked reading and batching keep memory low on a 512 MB dyno.
- Bidirectional editing: ensuring chat-driven edits stay in sync with the on-screen canvas and final DOCX export.
What we learned
- Prompt engineering for legal language is subtle; small punctuation changes can alter meaning.
- Context injection via Google Search significantly reduces hallucinations for niche jurisdictions.
- Users appreciate plain-language explanations (“explain this clause like I’m five”) on dense legal text.
Next steps
- Integrate electronic signature blocks (DocuSign API).
- Fine-tune a clause-risk classifier on public court documents.
- Add multilingual support (Hindi, Spanish, French).
Log in or sign up for Devpost to join the conversation.