⚖️ AI Contract Risk Analyzer
AI-Powered Legal Document Intelligence for Faster, Smarter Contract Review
Upload a contract. Get clause-level risk analysis in minutes, not hours.
Features • Workflow • Architecture • Installation • Skills Demonstrated
📖 Introduction
AI Contract Risk Analyzer is an AI-powered legal document analysis platform that automates the first-pass review of commercial contracts. It extracts and classifies key legal clauses, flags missing protections, scores overall contract risk, and generates AI-driven legal analysis — all through a clean, interactive Streamlit interface, powered by a locally hosted Llama 3.2 model via Ollama.
Built by a practicing corporate lawyer, the tool reflects how contract review actually happens in practice — not a generic document-summarization demo, but a workflow modeled on real due diligence and transactional review.
🏢 In production use: Formally adopted by Ch. Jehangir Law Firm to support real client contract review work.
🧩 Problem Statement
Manual contract review is one of the most time-intensive, expensive parts of legal and transactional work:
- A single commercial contract can take a lawyer 30–90 minutes to review manually for key clauses and risk exposure
- Junior lawyers and paralegals spend significant billable time on repetitive, first-pass review rather than higher-value analysis
- Manual review is prone to inconsistency — different reviewers catch different issues, and missing clauses (e.g., no indemnity provision, no governing law clause) are easy to overlook under time pressure
- Clients and deal teams need fast turnaround, especially during active M&A due diligence, when dozens of contracts must be reviewed against a tight timeline
This creates a clear bottleneck: legal review that should take minutes often takes hours, and cost scales linearly with document volume.
💡 Solution
AI Contract Risk Analyzer addresses this bottleneck by automating the first-pass review layer:
- Extracts text from PDF and DOCX contracts automatically
- Detects the presence and content of key legal clauses
- Identifies gaps — clauses a well-drafted contract should have but doesn't
- Scores risk using a rules-based and AI-assisted engine
- Generates legal reasoning using a locally hosted LLM (Llama 3.2), so no contract data ever leaves the local environment
- Produces a report a lawyer can review, verify, and act on in minutes
The result: lawyers spend their time on judgment and negotiation, not on manually scanning for clauses that a first pass can catch automatically.
✨ Features
| Category | Capability |
|---|---|
| 📄 Document Ingestion | Upload contracts in PDF or DOCX format |
| 🔍 Text Extraction | Automatic, structure-aware text extraction |
| 🏷️ Clause Detection | Identifies and classifies key legal clauses |
| Flags standard clauses absent from the contract | |
| 📊 Contract Classification | Categorizes contract type based on content |
| 🎯 Risk Scoring Engine | Quantifies overall contract risk exposure |
| 🤖 AI Legal Reasoning | Locally hosted Llama 3.2 (via Ollama) generates contextual legal analysis |
| 📈 Executive Dashboard | KPI cards summarizing key contract metrics |
| 📉 Risk Visualization | Interactive charts of clause and risk statistics |
| 📥 Downloadable Reports | Exportable, shareable risk analysis reports |
| 🖥️ Clean Interface | Streamlit-based UI, no legal or technical background required to operate |
| ✅ Confidentiality | ✅ Termination | ✅ Indemnity |
| ✅ Liability | ✅ Force Majeure | ✅ Governing Law |
| ✅ Arbitration | ✅ Payment | ✅ Intellectual Property |
| ✅ Non-Compete |
🔄 Workflow
flowchart TD
A[📄 Upload Contract<br/>PDF / DOCX] --> B[🔤 Extract Text]
B --> C[🏷️ Detect Important Clauses]
C --> D[⚠️ Identify Missing Clauses]
D --> E[🎯 Calculate Risk Score]
E --> F[🤖 AI Legal Analysis<br/>Llama 3.2 via Ollama]
F --> G[📋 Generate Professional Report]
G --> H[📥 Download & Review]
style A fill:#3776AB,color:#fff
style F fill:#0467DF,color:#fff
style G fill:#FF4B4B,color:#fff
style H fill:#2E7D32,color:#fff
📸 Screenshots
Screenshots below illustrate the core application views.
| Dashboard | Upload | Report |
|---|---|---|
![]() |
![]() |
![]() |
flowchart LR
subgraph Client["🖥️ Streamlit Interface"]
UI[User Uploads Contract]
end
subgraph Core["⚙️ Processing Core"]
TE[text_extractor.py]
CD[clause_detector.py]
RE[risk_engine.py]
AA[ai_analyzer.py]
end
subgraph AI["🤖 AI Layer"]
OL[Ollama Runtime]
LM[Llama 3.2 Model]
end
subgraph Output["📊 Output Layer"]
DASH[Executive Dashboard]
REP[Downloadable Report]
end
UI --> TE --> CD --> RE
RE --> AA
AA <--> OL
OL <--> LM
AA --> DASH
AA --> REP
style Client fill:#FF4B4B,color:#fff
style AI fill:#0467DF,color:#fff
style Output fill:#2E7D32,color:#fff
Module Responsibilities
| Module | Responsibility |
|---|---|
text_extractor.py |
Parses PDF/DOCX files and extracts clean, structured text for downstream processing |
clause_detector.py |
Scans extracted text to identify, classify, and extract the content of key legal clauses |
risk_engine.py |
Applies scoring logic across detected clauses, missing clauses, and contract characteristics to produce a risk score |
ai_analyzer.py |
Sends structured clause and risk data to the locally hosted Llama 3.2 model via Ollama and returns contextual legal analysis and an executive summary |
| Layer | Technology |
|---|---|
| Frontend | Streamlit |
| Backend | Python |
| AI Runtime | Ollama |
| AI Model | Llama 3.2 |
| Data Handling | Pandas |
| Visualization | Plotly |
| PDF Parsing | pdfplumber |
| DOCX Parsing | python-docx |
⚙️ Installation
Prerequisites
- Python 3.10 or higher
- Ollama installed locally
- Git
git clone https://github.com/<your-username>/ai-contract-risk-analyzer.git
cd ai-contract-risk-analyzerStep 2 — Create a Virtual Environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activateStep 3 — Install Dependencies
pip install -r requirements.txtStep 1 — Install and Start Ollama
# Install Ollama (if not already installed)
# https://ollama.com/download
# Pull the Llama 3.2 model
ollama pull llama3.2
# Ollama runs automatically as a local service after installationStep 2 — Launch the Application
streamlit run app.pyStep 3 — Open in Browser
Navigate to http://localhost:8501 and upload a contract to begin analysis.
📁 Folder Structure
ai-contract-risk-analyzer/
│
├── app.py # Main Streamlit application entry point
├── requirements.txt # Python dependencies
├── README.md # Project documentation
│
├── utils/
│ ├── text_extractor.py # PDF/DOCX text extraction
│ ├── clause_detector.py # Clause detection and classification
│ ├── risk_engine.py # Risk scoring logic
│ └── ai_analyzer.py # Llama 3.2 / Ollama integration
│
├── screenshots/
│ ├── dashboard.png
│ ├── upload.png
│ └── report.png
│
└── LICENSE
- 🌐 Support for multi-language contracts
- 🖨️ OCR support for scanned/image-based contracts
- 📚 Multi-document simultaneous review
- 🔀 Clause-to-clause comparison across contract versions
- ✍️ AI-assisted redlining and clause suggestions
- ☁️ Cloud deployment with secure multi-user access
|
⚖️ Legal Skills
|
🤖 AI Skills
|
💻 Programming Skills
|
📈 Business Skills
|
🧭 Key Learning Outcomes
Building AI Contract Risk Analyzer required bridging legal domain expertise with applied software engineering — translating an informal, judgment-based legal review process into a structured, repeatable pipeline. Key outcomes included learning to design modular Python architecture that separates extraction, detection, scoring, and AI reasoning into independently maintainable components; integrating a locally hosted LLM into a production workflow, balancing analysis quality against latency and reliability; and developing product judgment around what a legal end user actually needs from an AI tool's output — clear, actionable, and verifiable, rather than a black-box result the user has to blindly trust.
This project is developed for educational and research purposes only. It is a portfolio and applied-learning project demonstrating the intersection of legal practice and artificial intelligence. It does not constitute legal advice, and its output should not be relied upon as a substitute for review by a qualified legal professional. Any use of this tool in a professional legal context should be treated as a supplementary review aid, subject to verification by a licensed lawyer.
📄 License
This project is licensed under the MIT License — see the LICENSE file for details.
Built by Ali Asad Ullah Junior Associate, Ch. Jehangir Law Firm | Corporate Law × AI × Finance


