⚖️ AI Legal Contract Analyzer

An intelligent contract review platform built with LangGraph, OpenAI, and modern web technologies. Automatically analyzes contracts, identifies risks, researches unclear terms, and delivers comprehensive summaries.

🚀 Production Ready 🤖 LangGraph Powered 📧 Automated Delivery

📘 Project Overview

This system revolutionizes contract review by leveraging state-of-the-art AI technology. Built on LangGraph and OpenAI GPT-5-mini, it provides intelligent analysis tailored for both general legal contracts and creator/influencer brand deals.

🎯 Dual Mode

Legal & Creator modes for different contract types

🧠 Intelligent Research

AI identifies & researches unclear terms automatically

📅 Calendar Integration

Auto-creates Google Calendar events for deliverables

📧 Email Summaries

Professional summaries delivered to your inbox

🛠️ Technology Stack

Backend: Python, Flask
AI Framework: LangGraph, LangChain
LLM: GPT-5-mini
PDF Processing: pdfplumber
Web Search: DuckDuckGo Search API
Email: Resend API
Calendar: Google Calendar API
Deployment: Railway
Frontend: HTML, CSS, JavaScript

🏗️ System Architecture

LangGraph Workflow Pipeline

1
Extract Company Name

Uses LLM + regex fallback to identify the primary company/brand for email subject line

2
Parse Contract

Extracts clauses, deliverables, payment terms, legal flags, and key obligations

3
Analyze Risks

Identifies content ownership, exclusivity, usage rights, and payment risks with severity scoring

4
Research Unclear Terms

AI identifies complex legal terms → web search → generates creator-friendly explanations

5
Extract Deliverables (Creator Mode)

Identifies due dates, times, timezones for Google Calendar integration

6
Write Summary

Generates markdown summary with risk highlights and research explanations

7
Send Notifications

Emails summary + creates calendar invites with deliverable reminders

🧩 Intelligent Node System

Each node in the LangGraph workflow performs a specialized function with robust error handling and state management:

🏢 Company Extraction

Dual-approach extraction using LLM with regex fallback. Identifies company name for personalized email subjects.

📄 Contract Parser

Extracts structured data from contracts with JSON validation. Handles malformed responses gracefully.

⚠️ Risk Analyzer

Evaluates legal and business risks specific to creators. Rates severity and provides recommendations.

🔍 Intelligent Research

LLM identifies unclear terms → web search → summarization. Adapts to any contract language.

📅 Deliverables Extraction

Parses dates, times, and timezones. Creates structured calendar-ready data.

✍️ Summary Generator

Creates creator-friendly summaries with risk highlights and term explanations in markdown.

📧 Notification System

Resend API email delivery + Google Calendar API integration for cloud-native hosting.

🔄 CrewAI → LangGraph Migration

The system was migrated from CrewAI to LangGraph for better production reliability and control:

Aspect CrewAI (Original) LangGraph (Current)
Architecture Agent-based orchestration State machine with explicit flow
Telemetry Interactive prompts causing hangs No telemetry issues
Error Handling Opaque agent failures Per-node error handling with fallbacks
Performance Slower agent orchestration 30-50% faster execution
Debugging Difficult to trace state Clear state flow, easy debugging
Production Required workarounds Production-ready out of box

✨ Key Features

🎭 Dual Mode Analysis

Legal Mode: General contract analysis
Creator Mode: Brand deal focus with deliverables and calendar integration

🔒 Secure Authentication

Password-protected interface with session management. Hashed credentials via Werkzeug.

🧠 Contextual Research

AI identifies which terms need clarification per contract. No predefined lists, fully adaptive.

📊 Robust JSON Parsing

Multi-method extraction handles malformed LLM responses. Graceful fallbacks ensure continuity.

🌐 Web Integration

DuckDuckGo search for legal definitions. Google Calendar API for deliverable tracking.

📱 Responsive UI

Clean interface with loading states, toast notifications, and mode switching.

💻 User Interface

Frontend Screenshot

Simple Flask-based web interface with mode switching between Legal and Creator analysis. Users upload PDF contracts, enter email, and receive comprehensive analysis within minutes.

📬 Sample Output

Email Output Example

Users receive professionally formatted email summaries with:

🚀 Production Deployment

Deployed on Railway with the following considerations:

🔧 Environment Variables

OPENAI_API_KEY, SENDER_EMAIL, RESEND_API_KEY, GOOGLE_CALENDAR_TOKEN_JSON, SECRET_KEY, APP_PASSWORD_HASH

📧 Email Configuration

Resend API for reliable cloud-native email delivery. No SMTP port restrictions.

🔐 Security

Werkzeug password hashing, session management, HTTPS endpoints.

⚡ Performance

Gunicorn with 500s timeout and 2 workers for long-running LLM workflows.