Skip to content

payal211/ContractAgent-Pro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Legal Contract Analyzer

πŸ›οΈ AI-Powered Legal Contract Analysis System

A comprehensive agentic AI system built with LangChain, RAG (Retrieval Augmented Generation), local Llama models, and LangGraph for automated legal contract analysis, risk assessment, and compliance checking.

🌟 Features

Core Analysis Capabilities

  • Contract Type Detection: Automatically identifies contract types (Service Agreement, Employment Contract, NDA, etc.)
  • Entity Extraction: Extracts key parties, dates, financial terms, and important clauses
  • Risk Assessment: Identifies potential legal, financial, and operational risks
  • Compliance Checking: Verifies contracts against legal and regulatory requirements
  • Recommendation Engine: Provides actionable suggestions for contract improvement

Advanced Features

  • Multi-format Support: Processes PDF, TXT, and DOCX files
  • Real-time Processing: Live status updates during analysis
  • Historical Analysis: Track and compare multiple contract analyses
  • Risk Dashboard: Visual analytics for risk trends and patterns
  • RAG-Enhanced Analysis: Leverages legal knowledge base for informed decisions

πŸ—οΈ Architecture

Technology Stack

  • LangChain: Core AI pipeline and document processing
  • LangGraph: Workflow orchestration and state management
  • Ollama: Local LLM deployment (Llama 3.1 8B)
  • ChromaDB: Vector database for RAG implementation
  • FastAPI: Backend API service
  • Streamlit: Interactive web interface
  • PyPDF: PDF document processing
  • Plotly: Data visualization and analytics

System Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Streamlit UI  │────│   FastAPI       │────│   LangGraph     β”‚
β”‚   (Frontend)    β”‚    β”‚   (Backend)     β”‚    β”‚   (Workflow)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   File Upload   β”‚    β”‚   Contract      β”‚    β”‚   Entity        β”‚
β”‚   & Processing  β”‚    β”‚   Analysis API  β”‚    β”‚   Extraction    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                       β”‚
                                β”‚                       β–Ό
                                β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                β”‚              β”‚   Risk          β”‚
                                β”‚              β”‚   Assessment    β”‚
                                β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                       β”‚
                                β”‚                       β–Ό
                                β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                β”‚              β”‚   Compliance    β”‚
                                β”‚              β”‚   Check         β”‚
                                β”‚              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚                       β”‚
                                β–Ό                       β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   ChromaDB      β”‚    β”‚   Ollama LLM    β”‚
                       β”‚   (Vector DB)   β”‚    β”‚   (Local)       β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • Ollama installed locally
  • Git

Installation

  1. Clone the repository
git clone https://github.com/payal211/ContractAgent-Pro.git
cd ContractAgent-Pro
  1. Create conda environment
conda create -n contract-analyzer python=3.9
conda activate contract-analyzer
  1. Install dependencies
pip install -r requirements.txt

Option 2: Using Virtual Environment

  1. Clone the repository
git clone https://github.com/payal211/ContractAgent-Pro.git
cd ContractAgent-Pro
  1. Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies
pip install -r requirements.txt
  1. Install and setup Ollama
# Install Ollama (visit https://ollama.ai for installation instructions)
# Pull the required model
ollama pull llama3.1:8b
  1. Initialize the knowledge base
python main.py  # This will create the legal knowledge base

Running the System

  1. Start the FastAPI backend
uvicorn api:app --reload --host 0.0.0.0 --port 8000

or

python api.py
  1. Launch the Streamlit UI
streamlit run st_app.py
  1. Access the application
  • Open your browser to http://localhost:8501
  • The API docs are available at http://localhost:8000/docs

πŸ“‹ Usage Guide

Contract Analysis Methods

1. Text Input

  • Paste contract text directly into the interface
  • Supports any plain text contract content
  • Ideal for quick analysis and testing

2. File Upload

  • Upload PDF, TXT, or DOCX files
  • Automatic text extraction and processing
  • Supports multi-page documents

Analysis Process

  1. Document Processing: Upload or paste contract text
  2. Entity Extraction: System identifies key parties, terms, and clauses
  3. Risk Assessment: Analyzes potential legal and business risks
  4. Compliance Check: Verifies against regulatory requirements
  5. Recommendations: Generates actionable improvement suggestions

Dashboard Features

  • Risk Dashboard: Visual analytics for risk patterns
  • Analysis History: Track and compare multiple analyses
  • Compliance Reports: Detailed compliance scoring
  • System Metrics: Performance and usage statistics

πŸ”§ Configuration

Environment Variables

# .env file
OLLAMA_MODEL=llama3.1:8b
CHROMA_DB_PATH=./chroma_db
KNOWLEDGE_BASE_PATH=./legal_knowledge_base
API_HOST=0.0.0.0
API_PORT=8000
LOG_LEVEL=INFO

Model Configuration

# In main.py
OLLAMA_MODEL = "llama3.1:8b"  # Change to your preferred model
EMBEDDING_MODEL = "nomic-embed-text"

πŸ“Š Analysis Output

Contract Analysis Results

{
  "contract_type": "Service Agreement",
  "key_parties": ["ABC Consulting LLC", "XYZ Corporation"],
  "financial_terms": {
    "amounts": ["$10,000 per month"],
    "payment_terms": "Net 30"
  },
  "risks": [
    "Payment terms not clearly specified",
    "Termination clauses may be unclear"
  ],
  "recommendations": [
    "Clearly define payment terms including amounts, due dates, and late payment penalties",
    "Add liability limitation clauses to cap potential damages"
  ],
  "compliance_issues": [],
  "analysis_confidence": 0.85
}

Risk Assessment Categories

  • High Risk: Critical issues requiring immediate attention
  • Medium Risk: Important concerns to address
  • Low Risk: Minor issues for consideration
  • Compliance Issues: Regulatory and legal compliance concerns

πŸ› οΈ Development

Project Structure

legal-contract-analyzer/
β”œβ”€β”€ main.py                 # Core analyzer logic
β”œβ”€β”€ api.py                  # FastAPI backend
β”œβ”€β”€ st_app.py              # Streamlit frontend
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ README.md              # This file
β”œβ”€β”€ legal_knowledge_base/  # Legal documents and rules
β”œβ”€β”€ chroma_db/            # Vector database storage
└── tests/                # Test files

Key Classes

  • LegalContractAnalyzer: Main analysis engine
  • ContractAnalyzerState: LangGraph state management
  • ContractAnalysis: Data structure for results
  • ContractAnalyzerUI: Streamlit UI controller

πŸ“ˆ Performance Optimization

Recommended Hardware

  • CPU: 8+ cores for optimal performance
  • RAM: 16GB+ (8GB minimum)
  • Storage: SSD recommended for vector database
  • GPU: Optional, but speeds up LLM inference

Scaling Considerations

  • Use GPU acceleration for large-scale processing
  • Implement caching for repeated analyses
  • Consider distributed processing for high-volume scenarios

πŸ”’ Security & Privacy

Data Handling

  • Local Processing: All analysis happens locally
  • No External APIs: Contracts never leave your environment
  • Secure Storage: Vector database encryption available
  • Audit Trail: Complete analysis history tracking

Best Practices

  • Regularly update the legal knowledge base
  • Monitor system logs for security events
  • Implement access controls for sensitive contracts
  • Regular backup of analysis results

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages