Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Contract Analysis Agent - Legal Review

Production-grade AI agent for analyzing legal contracts with full governance.

🎯 Overview

This agent reviews contracts for risky clauses with:

  • Attorney-client privilege protection - Strict access controls
  • Risky clause detection - 7+ clause types analyzed
  • Verification - Legal accuracy across GPT-4, Claude, LegalBERT
  • Conflict of interest checking - Matter-based conflict tracking
  • Tamper-evident audit logging - 7-year retention compliance
  • PII redaction - Auto-redact sensitive info in outputs

Benchmark: "Analyzed 500 contracts, flagged 847 risky clauses, 0 privilege breaches"

🚀 Quick Start

# Install dependencies
pip install -r requirements.txt

# Run the demo
python main.py

📊 Clause Types Analyzed

Clause Type Risk Indicators Severity
Indemnification Unlimited, sole negligence, third-party CRITICAL
Liability Limitation No cap, below contract value CRITICAL
IP Assignment Broad assignment, work for hire HIGH
Non-Compete Worldwide, perpetual, >2 years CRITICAL
Termination Immediate, no refund MEDIUM
Arbitration Jury waiver, class action waiver HIGH
Governing Law Foreign jurisdiction HIGH

🔒 Access Control

Privilege Levels

  • PUBLIC - General information
  • CONFIDENTIAL - Client matters
  • PRIVILEGED - Attorney-client communications
  • WORK_PRODUCT - Attorney work product

Role Permissions

{
    "attorney": ["analyze", "review", "export"],
    "paralegal": ["analyze", "review"],
    "client": ["view_summary"],
    "admin": ["audit"]
}

📈 Risk Assessment

The agent calculates overall contract risk:

CRITICAL: Any critical clause OR 2+ high-risk clauses
HIGH:     1 high-risk clause OR 3+ medium-risk clauses
MEDIUM:   Any medium-risk clauses
LOW:      Only informational findings

🔧 Configuration

Adding Custom Clause Patterns

RISKY_CLAUSE_PATTERNS[ClauseType.CUSTOM] = {
    "patterns": [r"my\s+pattern"],
    "risk_indicators": [
        (r"critical\s+indicator", RiskLevel.CRITICAL, "Description"),
    ]
}

Conflict Management

agent.conflict_checker.add_conflict("Opposing Corp")

# Will block access to matters involving Opposing Corp
result = await agent.analyze_contract(doc_id, user)
# PermissionError: Conflict of interest: Opposing Corp

🏗️ Architecture

┌─────────────────────────────────────────────────────────┐
│                    Contract Document                     │
└─────────────────────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────┐
│                  AccessController                        │
│       (Authorization + Conflict Check)                   │
└─────────────────────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────┐
│                  ClauseAnalyzer                          │
│         (Pattern Matching + Risk Scoring)                │
└─────────────────────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────┐
│                  LegalVerifier (CMVK)                    │
│      (Verification for accuracy)             │
└─────────────────────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────┐
│                  RedactionEngine                         │
│              (PII removal for outputs)                   │
└─────────────────────────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────┐
│                  ContractReview                          │
│           (Findings + Recommendations)                   │
└─────────────────────────────────────────────────────────┘

📋 Sample Output

CONTRACT REVIEW SUMMARY
======================
Document: Master Services Agreement - Tech Corp & Vendor Inc
Type: MSA
Parties: Tech Corp, Vendor Inc

OVERALL RISK: CRITICAL

KEY FINDINGS:
- Total issues identified: 8
- Critical issues: 3
- High-risk issues: 4

⛔ CRITICAL ISSUES (Must address before signing):
  • Unlimited indemnification (Section 4)
  • No liability cap (Section 5)
  • Worldwide non-compete for 5 years (Section 7)

⚠️ HIGH-RISK ISSUES (Strongly recommend addressing):
  • Broad IP assignment (Section 3)
  • Jury trial waiver (Section 8)
  • Immediate termination right (Section 6)

📝 Audit Trail

[09:45:12] ATT001 | analyze | success
[09:45:13] ATT001 | complete_analysis | success
[09:46:00] PAR001 | analyze | denied (conflict)

🔌 Integration

NetDocuments

from netdocuments import NetDocsClient

ndocs = NetDocsClient(api_key=os.getenv("NETDOCS_KEY"))
agent = ContractAnalysisAgent()

doc = ndocs.get_document(doc_id)
contract = Contract(
    doc_id=doc_id,
    matter_id=doc.matter_id,
    content=doc.content
)
review = await agent.analyze_contract(doc_id, user)

iManage

from imanage import iManageClient

client = iManageClient(credentials)
# Similar integration pattern

⚖️ Compliance

  • ABA Model Rules: Rule 1.6 (Confidentiality)
  • GDPR: Data minimization, PII redaction
  • State Bar Requirements: Varies by jurisdiction
  • SOC 2: Audit logging, access controls

📋 License

MIT License - Use freely with attribution.