KI-Vertragsanalyse by Gemdynamics
Inspiration
The construction and real estate industries grapple with immensely complex contracts. Manually reviewing these documents is a time-consuming, error-prone, and costly endeavor, leading to hidden pitfalls, unclear formulations, missed opportunities, and potential legal disputes. Billions of Euros are lost annually due to suboptimal contracts. This project is to automate the examination of GTCs and construction contracts—aiming to tackle these real-world challenges with AI. Our motivation is to provide a tool that brings precision, efficiency, and a competitive edge to contract management.
What it does
KI-Vertragsanalyse is an advanced prototype that revolutionizes contract analysis using Next-Generation AI. It leverages a symbiosis of modern AI technology (specifically Google Gemini models) and embedded legal expertise to:
- Rapidly Analyze Contracts: Processes entire contracts in minutes, not days.
- Identify Risks: Pinpoints critical clauses and potential issues.
- Provide Actionable Insights: Offers clear, color-coded risk assessments (🔴 Red - High Risk, 🟡 Yellow - Caution, 🟢 Green - Low Risk, ℹ️ Info) with justifications.
- Suggest Optimizations: Generates alternative, legally sound phrasings for problematic clauses.
- Empower Negotiations: Provides a solid, data-driven foundation for stronger contract negotiations.
Ultimately, it transforms text chaos into clear, actionable recommendations, significantly reducing risks and improving efficiency.
How we built it
Our system employs a sophisticated multi-stage process, orchestrated by a robust tech stack:
1. The 5-Step Core Process: * UPLOAD & ANALYSE: User uploads the contract; AI ingests and structures the text. * INTELLIGENTE SEGMENTIERUNG: The contract is divided into logical clauses for precise analysis. * KLAUSELBEWERTUNG IM KONTEXT: Clauses are rated using an intuitive traffic light system (🔴🟡🟢ℹ️) cross-referenced with a comprehensive knowledge base. * FORMULIERUNGSVORSCHLÄGE: AI generates optimized, legally sound alternative clauses. * INTERAKTIVE OPTIMIERUNG: Users can refine analyses with direct AI support.
2. Deep Dive - The 3-Stage AI Pipeline:
* **Stage 1: Global Contract Cartography (Gemini Pro):**
* **Input:** Full raw contract text.
* **Process:** Gemini Pro identifies the main global structure (e.g., §-sections, articles) and intelligently divides the contract into 4-6 large, logical, contextually coherent chunks. This ensures no critical section is overlooked and preserves the integrity of main sections.
* **Stage 2: Micro-Structuring & Markdown (Gemini Pro):**
* **Input:** Each large chunk from Stage 1 (processed in parallel).
* **Process:** Detailed hierarchical breakdown of each chunk (H2, H3 levels, clauses, sub-clauses). Gemini Pro generates H3 headings for thematic blocks (even if not originally present) and converts all content to formatted Markdown.
* **Output:** A rich JSON structure mapping the contract hierarchy, with Markdown for each element, tagged with its global chunk number. This creates a highly readable and programmatically accessible version of the contract.
* **Stage 3: Clause Analysis & RAG (Gemini Flash & Convex Vector Search):**
* **Input:** Individual structured elements (clauses, paragraphs) from Stage 2 (processed in parallel).
* **RAG Magic:**
1. Clause text is embedded into a vector.
2. Convex Vector Search queries our knowledge base (laws, VOB/B, ÖNORM, court decisions, best practices).
3. The retrieved context + original clause are fed to Gemini Flash.
* **Analysis Process:** Gemini Flash analyzes the clause considering the specific expert context from the knowledge base.
* **Output (per element):** 🔴🟡🟢ℹ️ rating, clear justification (based on retrieved knowledge), and an actionable recommendation. This goes beyond pattern matching, offering context-sensitive risk assessment.
3. System Prompts: The Soul of the System: Expertly crafted system prompts guide each AI agent (Agent 1 for chunking, Agent 2 for structuring, Agent 3 for analysis). These detailed, unambiguous instructions specify output formats (e.g., JSON), emphasize consistency, and account for legal nuances, ensuring high-quality, predictable AI behavior.
4. Knowledge Base: Our AI's effectiveness is rooted in a meticulously curated knowledge base, encompassing: * German & Austrian contract law. * Industry-specific clause evaluations (Construction & Real Estate). * Current court decisions and legislative changes. * Expert knowledge and recognized best practices. * Semantic understanding for precise context analysis. * Continuous updates and expansion.
5. Technology Stack & Architecture:
* **Core AI Engine:**
* **Google Gemini Pro:** For deep analysis and structuring.
* **Google Gemini Flash:** For rapid analysis and RAG.
* **Google Text Embedding:** For semantic understanding.
* **Backend Powerhouse (Convex Platform):**
* **Serverless Backend & Real-time DB:** For storing contracts, chunks, analyses, vectors.
* **Actions & Mutations:** For AI calls and business logic.
* **Vector Search:** For the RAG knowledge base.
* **Intuitive Frontend:**
* **Next.js:** Frontend framework and API layer.
* **React:** For UI components.
* **Tailwind CSS:** For styling.
This architecture is designed to be scalable, robust, and real-time capable, flowing from Frontend -> API Layer -> Convex Backend -> Google Gemini API.
Challenges we ran into
- Structuring Diverse Contracts: Handling the varied and often inconsistent formatting of real-world legal documents.
- Ensuring AI Accuracy: Fine-tuning prompts and the RAG system to ensure the AI's interpretation and contextual understanding were legally sound and precise.
- Prompt Engineering: Developing highly specific and effective system prompts for each stage of the AI pipeline was an iterative and complex process.
- Knowledge Base Curation: Building and maintaining a comprehensive, accurate, and up-to-date legal knowledge base suitable for RAG is an ongoing challenge.
- Integration Complexity: Seamlessly integrating the various technologies (Gemini models, Convex, Next.js) into a cohesive and performant system.
Accomplishments that we're proud of
- The 3-Stage Deep Dive Process: This structured approach allows for both a holistic understanding and granular analysis of contracts.
- Effective RAG Implementation: Successfully leveraging Retrieval Augmented Generation to provide contextually rich and legally relevant insights, moving beyond simple AI analysis.
- Intuitive Ampelsystem: Creating a clear, at-a-glance risk assessment tool that is immediately understandable and actionable for users.
- End-to-End Prototype: Developing a functional prototype that demonstrates the entire workflow from document upload to actionable insights.
What we learned
- Power of Advanced AI: Gained deep insights into applying cutting-edge AI models like Google Gemini Pro and Flash, along with RAG techniques, to solve complex real-world legal tech problems.
- Criticality of Prompt Engineering: Reinforced the understanding that well-crafted system prompts are paramount for achieving desired AI behavior and output quality.
- System Design for AI Applications: Learned valuable lessons in designing scalable and robust architectures for AI-driven applications, particularly the interplay between AI services, databases, and frontend interfaces.
- Iterative Development: The importance of an iterative approach in refining AI models, prompts, and the user experience based on testing and feedback.
- Domain Expertise Integration: The necessity of deeply embedding domain-specific (legal) knowledge into the AI system, both in the knowledge base and in the design of the AI's analytical tasks.
What's next for KI-Vertragsanalyse
We are committed to evolving KI-Vertragsanalyse into the leading platform for intelligent contract management in the construction and real estate sectors. Our future plans include:
- Expanding Legal Jurisdictions: Integrating support for other legal systems (e.g., Switzerland, EU law).
- AI Model Finetuning: Continuously refining our AI models for even more precise and nuanced analyses.
- Comprehensive Contract Management Features: Adding functionalities for full lifecycle contract management.
- Real-time Collaborative Editing: Enabling teams to work on contracts together within the platform.
- Predictive Analytics: Developing capabilities to forecast potential contract risks.
Contact Us: Ready for the AI revolution in your business? Discover how tailored AI solutions can transform your processes. Contact Gemdynamics - Your journey to an AI-powered future starts here.
Built With
- convex
- nextjs
Log in or sign up for Devpost to join the conversation.