Inspiration
Legal contracts are everywhere — from apartment leases to freelance agreements — yet creating or understanding them remains expensive and inaccessible. A simple sales agreement can cost hundreds of dollars in legal fees, and most people sign contracts they don't fully understand simply because legal language is designed for lawyers, not everyday people.
We asked ourselves: what if getting legal help was as easy as having a conversation? Not typing into a chatbot, not filling out a form — but actually talking, the way you'd speak to a real lawyer sitting across the table. When we saw the Gemini Live API's ability to handle natural, interruptible, real-time voice conversations, we knew this was the technology to make that vision a reality.
What it does
LegalLease is a multimodal AI legal partner with two core capabilities:
🎤 Create Contracts — Users have a natural voice conversation with the AI assistant. They describe what they need, answer clarifying questions, and receive a comprehensive, professionally-formatted legal contract in seconds. The entire interaction is voice-to-voice — no typing required. The agent supports 50+ contract types across 5 jurisdictions.
📄 Analyze Contracts — Users upload a PDF or photo of any existing contract. The AI provides a detailed 8-section analysis covering: contract overview, key terms, obligations, important clauses, risks & red flags, missing elements, a plain-language summary, and actionable recommendations.
Both features are designed to break the "text box" paradigm — the experience feels alive, context-aware, and natural rather than turn-based.
How we built it
Backend: Python FastAPI server deployed on Google Cloud Run. The live voice agent is built using the Google ADK (Agent Development Kit), which manages the bidirectional audio session with the Gemini Live API. We chose to separate concerns — the Live API handles real-time conversation, while a standard Gemini 2.5 Flash API call (via the Google GenAI SDK) handles contract text generation and document vision analysis. This architecture lets each component do what it does best.
Frontend: Next.js 15 with React 19 and TypeScript. Features real-time audio streaming over WebSockets, custom audio visualization, drag-and-drop document upload, and a premium dark-themed UI.
Persistence: Cloud Firestore stores all generated contracts with session tracking, enabling users to retrieve their documents later.
Key architectural decision: The live agent collects contract details through conversation, then a separate non-live Gemini call generates the full document. This was critical because the Live API is optimized for real-time audio, not for producing long-form text output.
Challenges we ran into
Live API timeout with long text: Our first approach had the agent generate the entire contract as spoken text. This caused the session to freeze — the Live API isn't designed to speak 1000+ word documents. We solved this by decoupling: the agent triggers a standard API call for document generation, keeping each component focused on its strength.
Audio transcription accuracy: Partial transcription events from the SDK needed careful accumulation logic. Early versions would truncate user input or create duplicate messages. We built custom handling to preserve full utterances without duplicates.
WebSocket lifecycle management: Managing the triple-layer connection (browser ↔ backend ↔ Gemini Live API) required careful error handling and graceful shutdown procedures across all three layers. Disconnections at any point needed to cascade cleanly without crashing the other components.
Grounding contracts in reality: Legal documents can't afford hallucinations. We explicitly instructed the model to never fabricate legal citations, grounded contract generation entirely in the conversation transcript, and added attorney-review disclaimers to every output.
Accomplishments that we're proud of
- Truly breaking the text box — the voice interaction feels natural, with full interruption support and context awareness across the conversation
- Separation of concerns architecture — using the Live API for what it excels at (conversation) and the standard API for what it excels at (document generation) was a key insight that made everything work
- Multimodal coverage — voice input/output for creation, vision for analysis, text for document generation — all in one cohesive application
- Comprehensive error handling — WebSocket disconnections, API failures, invalid uploads, and edge cases are all handled gracefully with meaningful user feedback
- Production-ready deployment — fully containerized and running on Google Cloud Run with Firestore persistence
What we learned
- The Gemini Live API excels at natural conversation with its native interruption handling, but has constraints with very long text output in audio mode — designing around this was key
- Google ADK provides powerful abstractions for building agent-based applications, handling session management and audio streaming efficiently
- Combining multiple Gemini modalities (live audio + vision + text generation) in one application creates a much richer experience than any single modality alone
- WebSocket architecture is essential for real-time AI applications — REST polling simply can't match the responsiveness
- Legal AI requires extra care around grounding and hallucination prevention — the stakes are higher when users rely on the output for real decisions
What's next for LegalLease
We're focused on dramatically improving contract accuracy and legal reliability:
- RAG (Retrieval-Augmented Generation) — Integrate a legal knowledge base with jurisdiction-specific statutes, case law, and regulatory requirements. Contracts would be grounded in actual legal precedent, not just the model's training data
- Fine-tuning — Train specialized Gemini models on verified legal contract datasets to improve clause accuracy, jurisdiction-specific formatting, and legal terminology usage
- Legal MCP Services — Connect to Model Context Protocol servers that provide access to real-time legal databases, regulatory updates, and compliance frameworks — giving the agent live access to authoritative legal sources
- Web Search Tool Integration — Enable the agent to search for current legal requirements, recent regulatory changes, and jurisdiction-specific rules during contract generation, ensuring documents reflect the latest legal standards
- Multi-language support — The Live API already supports multiple languages, enabling legal assistance globally
- Contract comparison — Upload two contracts and highlight differences, conflicts, or missing clauses
- Clause-by-clause voice editing — Modify specific sections through voice commands after generation
- Digital signature integration — Complete the contract lifecycle from creation to execution
Built With
- fastapi
- firebase
- gemini
- google-adk
- google-cloud
- javascript
- nextjs
- python
Log in or sign up for Devpost to join the conversation.