Skip to content

kennedyraju55/contract-clause-analyzer

Repository files navigation

⚖️ Contract Clause Analyzer

AI-powered contract analysis that identifies risks, obligations, deadlines, and red flags in legal agreements — 100% locally, protecting attorney-client privilege.

Python License Local LLM Privacy Docker

🎬 Demo

The Streamlit interface lets you paste a contract clause or full agreement, then displays a structured analysis with color-coded risk levels (🟢 Low → 🚨 Critical), extracted obligations, deadlines, red flags, and negotiation recommendations — all processed locally.

Add a screenshot of the Streamlit UI showing a contract analysis with risk ratings here.

🔥 Why This Exists

Reviewing contracts is expensive — lawyers charge hundreds per hour, and critical risks hide in dense legal language. Small businesses and individuals often sign agreements without fully understanding their obligations or exposure. This tool brings AI-powered contract analysis to everyone — identify one-sided terms, flag missing protections, compare clause versions, and get negotiation points — all without sending a single byte of your confidential contracts to the cloud.

✨ Features

  • 🔍 Single clause analysis — deep-dive into any individual clause with risk scoring
  • 📄 Full contract analysis — analyze an entire agreement, auto-identifying all major clauses
  • ⚖️ Clause comparison — compare two versions of the same clause to identify which favors which party
  • 🚨 Four-tier risk scoring — LOW 🟢, MEDIUM 🟡, HIGH 🔴, CRITICAL 🚨
  • 📋 Obligation extraction — list all duties imposed on each party
  • Deadline detection — surface all time-sensitive requirements
  • 🚩 Red flag identification — spot problematic, unusual, or one-sided terms
  • 💡 Negotiation recommendations — actionable suggestions for improving your position
  • 🏷️ 15 clause type categories — indemnification, termination, confidentiality, non-compete, IP, payment, warranty, force majeure, dispute resolution, and more
  • 📝 Sample clauses included — built-in examples for testing across 5 common clause types
  • 🖥️ Three interfaces — CLI, Streamlit Web UI, and FastAPI REST API
  • 🐳 Docker support — containerized deployment
  • 🔒 100% local processing — attorney-client privilege fully protected

🏗️ Architecture

┌──────────────────────────────────────────────────────────────┐
│                      User Interfaces                          │
│                                                               │
│  ┌─────────┐    ┌──────────────┐    ┌──────────────────┐     │
│  │   CLI   │    │ Streamlit UI │    │  FastAPI REST API │     │
│  │ (click  │    │ (risk-coded  │    │  (JSON responses) │     │
│  │  + rich)│    │  dashboard)  │    │                   │     │
│  └────┬────┘    └──────┬───────┘    └────────┬──────────┘     │
│       └───────────────┬┼─────────────────────┘                │
│                       ▼▼                                      │
│  ┌───────────────────────────────────────────────────────┐    │
│  │                    Core Engine                         │    │
│  │                                                        │    │
│  │  ┌──────────────┐  ┌──────────────┐  ┌─────────────┐  │    │
│  │  │ Analyze      │  │ Analyze Full │  │ Compare     │  │    │
│  │  │ Clause       │  │ Contract     │  │ Clauses     │  │    │
│  │  └──────────────┘  └──────────────┘  └─────────────┘  │    │
│  │                                                        │    │
│  │  Data Models: ClauseAnalysis, ContractAnalysis          │    │
│  │  Enums: RiskLevel, ClauseType (15 categories)          │    │
│  └──────────────────────┬────────────────────────────┘    │
│                         ▼                                 │
│              ┌──────────────────┐                         │
│              │  Common LLM      │                         │
│              │  Client Module   │                         │
│              └────────┬─────────┘                         │
│                       ▼                                   │
│              ┌──────────────────┐                         │
│              │  Ollama Server   │                         │
│              │  Gemma 4 model   │                         │
│              │  localhost:11434  │                         │
│              └──────────────────┘                         │
└──────────────────────────────────────────────────────────────┘

🚀 Quick Start

Prerequisites

  • Python 3.10+
  • Ollama installed and running
  • Gemma 4 model: ollama pull gemma4

Installation

git clone https://github.com/kennedyraju55/contract-clause-analyzer.git
cd contract-clause-analyzer
pip install -r requirements.txt
pip install -e .

Usage

CLI:

# Analyze a single clause
python -m src.contract_analyzer.cli analyze-clause --input examples/sample_clause.txt

# Analyze a full contract
python -m src.contract_analyzer.cli analyze-contract --input examples/sample_contract.txt

# Compare two clauses
python -m src.contract_analyzer.cli compare --clause-a clause_v1.txt --clause-b clause_v2.txt

Streamlit Web UI:

streamlit run src/contract_analyzer/web_ui.py

FastAPI REST API:

uvicorn src.contract_analyzer.api:app --reload
# POST /analyze-clause, /analyze-contract, /compare-clauses

Docker:

docker-compose up

📁 Project Structure

contract-clause-analyzer/
├── src/
│   └── contract_analyzer/
│       ├── __init__.py
│       ├── core.py          # Analysis engine, risk scoring, clause comparison
│       ├── cli.py           # Click + Rich CLI interface
│       ├── web_ui.py        # Streamlit dashboard with risk visualizations
│       ├── api.py           # FastAPI REST endpoints
│       └── config.py        # YAML configuration loader
├── common/
│   └── llm_client.py       # Shared Ollama API wrapper
├── examples/                # Sample contracts and clauses
├── tests/                   # pytest test suite
├── docs/                    # Documentation and images
├── config.yaml              # Model settings, risk thresholds
├── Dockerfile
├── docker-compose.yml
├── Makefile
├── requirements.txt
└── setup.py

🏷️ Supported Clause Types

Clause Type Description
Indemnification Hold harmless and defense obligations
Limitation of Liability Caps on damages and exclusions
Termination Exit conditions, notice periods, consequences
Confidentiality NDA terms and information protection
Non-Compete Competitive restrictions and scope
Intellectual Property IP ownership, licensing, work-for-hire
Payment Terms Pricing, invoicing, late fees
Warranty Representations and guarantees
Force Majeure Unforeseeable event provisions
Dispute Resolution Arbitration, mediation, jurisdiction
Governing Law Applicable legal jurisdiction
Assignment Transfer of rights and obligations
Severability Invalid clause handling
Amendment Contract modification procedures

⚖️ Disclaimer

This tool provides AI-assisted contract analysis for informational purposes only. It is NOT legal advice. Always consult with a qualified attorney before making legal decisions. All processing happens locally — no data ever leaves your machine. Attorney-client privilege is fully protected.

🤝 Contributing

Contributions welcome! Please open an issue or submit a PR. See CONTRIBUTING.md for guidelines.

📄 License

MIT License — see LICENSE

👨‍💻 Author

Nrk Raju Guthikonda

  • 🏢 Senior Software Engineer at Microsoft (Copilot Search Infrastructure)
  • 🔗 GitHub | LinkedIn
  • 🚀 Building 116+ open-source AI tools for real-world impact

⭐ If this helps you understand your contracts better, give it a star!

About

⚖️ Contract Clause Analyzer — Privacy-first legal AI tool powered by local Gemma 4 LLM via Ollama. 100% local, zero data leakage.

Topics

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors