Inspiration

I built this project to bridge the gap between raw legal text and actionable negotiation outcomes. Many freelancers and small companies can't afford a lawyer for every contract, yet they routinely sign agreements that affect cashflow and liability. The idea was inspired by real freelance pain points (late payments, scope creep) and by our work on automated contract review tools.

What it does

SynthLegal is an AI-powered platform that simulates contract negotiations. Users are presented with a contract scenario and engage in a negotiation with a dynamic AI opponent. This app ingests a contract (PDF / DOCX / pasted text), extracts clauses using an NLP pipeline, highlights high-risk language, and generates suggested redlines / counteroffers. It can simulate negotiation outcomes by scoring contract balance (risk vs. reward) and producing a short, negotiation-ready message the user can send to the counterparty.

The key features include:

  • Dynamic AI Opponent: The AI can adopt various personalities (e.g., Cooperative, Aggressive, Analytical), challenging users to adapt their strategies.
  • Real-time Contract Analysis: As users edit the contract, the AI provides instant feedback on clauses, assessing risks and summarizing potential impacts.
  • Advanced AI Tooling:
    • Clause Analysis: Users can select any clause to get an in-depth analysis of its risks, implications, and a suggested counter-proposal.
    • Contradiction Finder: The AI can scan the entire document to find conflicting terms and clauses.
    • AI Clause Assistant: The system provides intelligent suggestions for new clauses based on the context of the negotiation chat.
  • Personal Clause Library: Users can save, import, and quickly insert custom or standard clauses into their contracts.
  • Session Persistence: The application automatically saves the contract text and chat history, allowing users to resume their sessions at any time.

How I built it

SynthLegal is built as a modern, serverless web application. The frontend is a single-page application built with React and TypeScript, using Vite for the build tooling. This allows for a fast, modern, and type-safe development experience. The UI is composed of several key components: a ScenarioSelector, a ContractEditor for the legal text, and a NegotiationChat for interacting with the AI.

The backend logic is powered by the Google AI Studio API, leveraging two different Gemini models:

  • Gemini 2.5 Pro: Used for the core negotiation chat, providing a sophisticated and dynamic conversational partner.
  • Gemini 2.5 Flash: Used for real-time clause analysis and other tooling, providing speed and efficiency for instant feedback.

For session and clause library management, we used the browser's LocalStorage API, which simplifies the architecture by avoiding the need for a dedicated database for this prototype. The entire application is designed to be deployed as a containerized service on Google Cloud Run.

Ingestion: file upload + OCR for scanned PDFs (Tesseract).

Parsing & Clause Extraction: a combination of regex + transformer-based NER to identify clauses (termination, payment, liability).

Embeddings & Retrieval: contract clauses are embedded and stored for fast retrieval/precedent lookup (vector DB).

Reasoning & Generation: a LLM (fine-tuned or prompt-engineered) generates suggested clause edits and negotiation messages.

UI: single page React app with stepwise wizard: Upload → Review → Simulate → Export.

Ops: Dockerized backend, CI/CD, and usage monitoring.

Challenges we ran into

  1. Prompt Engineering: Crafting the prompts to give the AI opponent a consistent and believable personality was a significant challenge. It required extensive experimentation to ensure the AI was not just a passive chatbot but a dynamic participant in the negotiation.
  2. Real-time Performance: Providing instant clause analysis without degrading the user experience was a key requirement. We addressed this by using the faster Gemini 2.5 Flash model for analysis tasks and optimizing our API calls.
  3. State Management: The application state is complex, involving the contract text, chat history, analysis results, and user settings. Managing this state effectively in React, especially with real-time updates from the AI, required careful planning and implementation.
  4. Streaming AI Responses: To create a natural chat experience, we needed to stream the AI's responses word by word. Implementing this on the frontend required handling the response stream from the Gemini API and updating the UI in real-time.
  5. Handling noisy OCR output from scanned contracts required careful cleaning and heuristic repairs.
  6. Detecting subtle legal intent (e.g., indemnity scope) needs a mix of rules and model judgment — false positives were a problem early on.
  7. Rate-limiting LLM calls to control cost while keeping the interactive UX smooth.

Accomplishments that we're proud of

  • The Dynamic AI Opponent: We successfully created an AI that feels like a real negotiation partner, with distinct personalities that can challenge even experienced professionals.
    • The Real-time Analysis Engine: The ability to get instant, insightful feedback on legal clauses is a powerful tool that we believe is a game-changer for legal education and practice.
    • The Seamless User Experience: We managed to integrate a complex set of features into a clean, intuitive, and responsive user interface.
    • The Serverless Architecture: Building the application on a serverless architecture with Google Cloud Run and the Gemini API means it is highly scalable, cost-effective, and easy to maintain.
    • Built an end-to-end flow from upload → redline → downloadable negotiation message.
    • Reduced the average time-to-first-suggestion for new contracts from 20+ minutes (manual) to under 2 minutes in our tests.
    • High precision on payment & termination clause detection in internal evaluation (precision > 0.88).

What we learned

This project was a tremendous learning experience. Key takeaways include:

  • The Power of Specialized Models: Using different AI models for different tasks (Gemini 2.5 Pro for conversation, Gemini 2.5 Flash for analysis) is a highly effective strategy for balancing performance and cost.
  • The Importance of Prompt Engineering: The quality of the AI's output is directly proportional to the quality of the prompts. We learned that prompt engineering is as much an art as it is a science.
  • The Nuances of Streaming: We gained a deep understanding of how to handle streaming data in a modern web application to create a more engaging user experience.
  • The Future of Legal Tech: This project reinforced our belief that AI will play a transformative role in the legal industry, not by replacing professionals, but by augmenting their skills and providing powerful new tools for training and practice.
  • Hybrid systems (rules + models) outperform either approach alone for legal text.
  • Small UX details (clear risk highlight colors, short plain-English summaries) dramatically increase user trust and adoption.

What's next for SynthLegal - AI Contract Negotiation Simulator

I have a number of exciting ideas for the future of SynthLegal:

  • Multiplayer Mode: Allowing two human users to negotiate against each other with the AI acting as a coach or mediator.
  • Expanded Scenario Library: Adding a wider range of contract types and negotiation scenarios, covering different industries and legal domains.
  • Deeper Analytics: Providing users with a more detailed post-negotiation analysis of their performance, including metrics on their communication style, strategy, and outcomes.
  • Integration with Document Management Systems: Allowing users to import and export contracts from popular legal tech platforms.

Built With

Share this project:

Updates