Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Contract Processing Pipeline

Enterprise-Grade Contract Analysis System - MVP Prototype

⚠️ DEMONSTRATION SOFTWARE - EVALUATION ONLY
This is a proprietary prototype. Commercial use requires licensing.

Created by: Your Name | your.email@example.com
Copyright Β© 2025 - All Rights Reserved


🚨 IMPORTANT NOTICE

This is a DEMONSTRATION/PROTOTYPE for evaluation purposes only.

╔══════════════════════════════════════════════════════════════════╗
β•‘                        ⚠️  LEGAL NOTICE                          β•‘
β•‘                                                                  β•‘
β•‘  This software is licensed for EVALUATION ONLY.                 β•‘
β•‘                                                                  β•‘
β•‘  ❌ Commercial use PROHIBITED without written permission        β•‘
β•‘  ❌ Production deployment PROHIBITED                            β•‘
β•‘  ❌ Building upon this code commercially PROHIBITED             β•‘
β•‘                                                                  β•‘
β•‘  βœ… For commercial licensing and collaboration:                 β•‘
β•‘     Contact: your.email@example.com                             β•‘
β•‘                                                                  β•‘
β•‘  See LICENSE file for complete terms.                           β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

A production-ready AI-powered contract analysis system that extracts structured data from PDF contracts using Google Document AI and OpenAI GPT-4.


πŸ“’ About This MVP

This is a Minimum Viable Product (MVP) demonstrating enterprise-grade contract analysis capabilities.

Created and maintained by: Your Name

Want to Use This Commercially?

You MUST contact the creator for:

  • πŸš€ Commercial licensing for your organization
  • 🎯 Custom feature development and expansion
  • πŸ’Ό Enterprise production deployment
  • πŸ”§ Integration with your existing systems
  • 🀝 Partnership to build the complete solution

πŸ“§ Required for commercial use: your.email@example.com


🎯 What This Demo Does

This pipeline performs comprehensive contract analysis:

  1. Ingests PDF contracts into a database
  2. OCR Extraction using Google Document AI (layout-aware, high accuracy)
  3. AI Field Extraction using GPT-4 (extracts structured fields like dates, parties, values)
  4. AI Clause Extraction using GPT-4 (identifies and extracts key legal clauses)
  5. Analysis & Reporting generates comprehensive HTML reports with:
    • Field commonality analysis
    • Clause similarity grouping (semantic comparison)
    • Timeline analysis
    • Quantitative and qualitative insights
    • Side-by-side contract comparison

πŸ“‹ Prerequisites

Required Accounts & APIs

  1. Google Cloud Platform (for Document AI OCR)

    • Active GCP project with billing enabled
    • Document AI API enabled
    • Service account with Document AI permissions
    • Document AI processor created
  2. OpenAI API (for GPT-4 extraction)

    • OpenAI account with API access
    • Active API key with GPT-4 access

System Requirements

  • Python: 3.11 or higher
  • Operating System: Windows, macOS, or Linux
  • RAM: 4GB minimum (8GB recommended)
  • Disk Space: 500MB for dependencies + contract storage

πŸš€ Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Configure Environment Variables

Create a .env file in the root directory:

# OpenAI Configuration
OPENAI_API_KEY=sk-your-openai-api-key-here

# Google Cloud Document AI Configuration
GCP_PROJECT_ID=your-gcp-project-id
GCP_PROCESSOR_ID=your-processor-id
GCP_LOCATION=us
GOOGLE_APPLICATION_CREDENTIALS=./gcloud.json

# Database
DATABASE_URL=sqlite:///contracts.db

# Model Settings
DEFAULT_MODEL=gpt-4o
DEFAULT_TEMPERATURE=0.1

3. Add Google Cloud Credentials

Place your Google Cloud service account JSON file as gcloud.json in the root directory.

How to get this file:

  1. Go to Google Cloud Console
  2. Navigate to IAM & Admin > Service Accounts
  3. Create or select a service account with Document AI permissions
  4. Create a key (JSON format)
  5. Save as gcloud.json in this folder

4. Add Your PDF Contracts

Place your PDF contracts in the contracts/ folder. The demo includes 3 sample contracts (test.pdf, test1.pdf, test2.pdf).

5. Run the Pipeline

python run_full_pipeline.py

This single command will:

  • Clean any existing data
  • Initialize a fresh database
  • Ingest all PDF contracts
  • Run Google Document AI OCR
  • Extract fields and clauses with GPT-4
  • Generate a comprehensive HTML report

Execution time: Approximately 2-5 minutes for 3 contracts


πŸ“Š Output Files

After running the pipeline, you'll find:

  • comprehensive_report.html - Full analysis report (open in browser)
  • contracts.db - SQLite database with all extracted data
  • data/uploads/ - Stored PDF files
  • data/thumbnails/ - PDF thumbnails

πŸ” Viewing Results

Open the Report

# Windows
start comprehensive_report.html

# macOS
open comprehensive_report.html

# Linux
xdg-open comprehensive_report.html

View Raw Data

python view_extraction.py

This displays all extracted fields and clauses in the terminal.


πŸ“– Understanding the Playbook

The system uses a playbook to define what to extract from contracts. The default playbook extracts:

Fields

  • effective_date - When the contract becomes effective
  • expiration_date - When the contract expires
  • contract_value - Total monetary value
  • party_a - First contracting party name
  • party_b - Second contracting party name
  • jurisdiction - Governing law jurisdiction
  • termination_notice_days - Notice period for termination
  • renewal_term - Automatic renewal terms

Clauses

  • confidentiality - Confidentiality obligations
  • liability_limitation - Limitation of liability
  • termination_conditions - Termination procedures
  • payment_terms - Payment schedule and methods
  • indemnification - Indemnification obligations
  • intellectual_property - IP rights and ownership

You can customize the playbook by editing app/extract/playbook.py or creating a custom JSON playbook file.


πŸ› οΈ Troubleshooting

"Failed to initialize Google Document AI"

Solution:

  1. Check that gcloud.json exists in the root folder
  2. Verify the file contains valid JSON credentials
  3. Ensure Document AI API is enabled in your GCP project
  4. Confirm your service account has Document AI permissions
  5. Check that GOOGLE_APPLICATION_CREDENTIALS in .env points to ./gcloud.json

"Rate limit reached for GPT-4"

Solution:

  • Wait 1-2 minutes and run the report generation step separately:
    python generate_comprehensive_report.py
  • Consider upgrading your OpenAI API tier for higher limits

"No module named 'app'"

Solution:

  • Ensure you're running commands from the A.I-Processing-Demo directory
  • Install all dependencies: pip install -r requirements.txt

Database errors

Solution:

  • Delete contracts.db and run python run_full_pipeline.py again
  • This will recreate the database with a fresh schema

πŸ“ Project Structure

A.I-Processing-Demo/
β”œβ”€β”€ app/                          # Core application code
β”‚   β”œβ”€β”€ api/                      # API routes (if running web server)
β”‚   β”œβ”€β”€ core/                     # Settings, logging, types
β”‚   β”œβ”€β”€ extract/                  # Extraction logic and playbooks
β”‚   β”œβ”€β”€ ingest/                   # PDF ingestion
β”‚   β”œβ”€β”€ insights/                 # Analysis algorithms
β”‚   β”œβ”€β”€ llm/                      # LLM client and prompts
β”‚   β”œβ”€β”€ ocr/                      # Document AI integration
β”‚   β”œβ”€β”€ storage/                  # Database models
β”‚   └── cli.py                    # Command-line interface
β”œβ”€β”€ contracts/                    # Input PDF files (put your PDFs here)
β”œβ”€β”€ data/                         # Generated data
β”‚   β”œβ”€β”€ uploads/                  # Stored PDF files
β”‚   └── thumbnails/               # PDF thumbnails
β”œβ”€β”€ config/                       # Configuration templates
β”œβ”€β”€ .env                          # Environment variables (YOU CREATE THIS)
β”œβ”€β”€ gcloud.json                   # GCP credentials (YOU ADD THIS)
β”œβ”€β”€ run_full_pipeline.py          # Main pipeline script
β”œβ”€β”€ generate_comprehensive_report.py  # Report generator
β”œβ”€β”€ view_extraction.py            # Data viewer
β”œβ”€β”€ requirements.txt              # Python dependencies
└── README.md                     # This file

πŸŽ“ Key Features

1. Context-Aware Extraction

The system supports optional background and goal fields in playbooks to give the AI context about the legal matter, improving extraction accuracy.

2. Human Review Flags

AI automatically flags low-confidence extractions with explanations for human review:

  • needs_human_review - Boolean flag
  • review_reason - Explanation of why review is needed
  • alternative_values - Possible alternative values found

3. Semantic Clause Grouping

Uses embeddings to group similar clauses across contracts, even when worded differently. Helps identify commonality vs. variations.

4. Source Tracking

Every extracted field and clause includes:

  • Source page numbers
  • Confidence scores
  • Extraction method (llm, ocr, fallback)
  • Model used (gpt-4o, etc.)
  • Timestamps

5. Timeline Analysis

Automatically tracks when contract terms changed over time based on effective dates.


πŸ’‘ Use Cases

This pipeline is ideal for:

  • Legal Discovery - Analyze thousands of contracts for litigation
  • Due Diligence - Extract key terms from acquisition targets
  • Compliance Review - Identify non-standard clauses across contract portfolio
  • Contract Migration - Extract data for migration to new systems
  • Risk Analysis - Find outlier terms and potential liabilities

πŸ”’ Security & Privacy

  • All processing happens locally or in your own cloud accounts
  • No data sent to third parties except:
    • Google Document AI (for OCR)
    • OpenAI (for GPT-4 extraction)
  • Database is stored locally (SQLite)
  • Credentials stored in .env file (add to .gitignore)

πŸ“ž Support

For questions or issues:

  1. Check the Troubleshooting section above
  2. Review error messages in the terminal
  3. Check that all prerequisites are met
  4. Verify .env configuration is correct

πŸ“„ License & Usage

⚠️ IMPORTANT: This is a DEMONSTRATION/PROTOTYPE for evaluation purposes only.

License: Proprietary - Evaluation/Demonstration License
Created by: Your Name
Copyright Β© 2025 - All Rights Reserved

Permitted Use:

βœ… Evaluation and testing
βœ… Proof-of-concept demonstrations
βœ… Academic research

Commercial Use PROHIBITED Without Permission:

❌ Production deployment in business operations
❌ Building commercial features on this codebase
❌ Integration into existing business systems

Need Commercial License?

You MUST obtain written permission and licensing for:

  • Production deployment
  • Commercial use within your organization
  • Building upon this prototype
  • Enterprise integration

πŸ“§ Contact for commercial licensing: your.email@example.com

See LICENSE file for complete terms.


πŸš€ Want to Scale This Solution?

This is a Minimum Viable Product (MVP) demonstrating enterprise capabilities.

Need to scale this for your organization?

Contact the creator for:

  • πŸ“ˆ Enterprise deployment and scaling
  • πŸ”§ Custom feature development
  • πŸ”’ Security and compliance features
  • 🌐 System integrations
  • πŸ’Ό Ongoing support and maintenance

πŸ“§ Get in touch: your.email@example.com
πŸ“„ More info: See CREATOR.md


πŸ™ About the Creator

Your Name
your.email@example.com | LinkedIn | GitHub

Specializing in AI-powered document processing, enterprise software architecture, and legal tech solutions.


Built with ❀️ for efficient contract analysis
Created by Your Name | Β© 2025


πŸš€ Next Steps

After running the demo successfully:

  1. Customize the playbook - Edit fields/clauses for your specific contract types
  2. Add more contracts - Place additional PDFs in the contracts/ folder
  3. Scale up - Consider switching to PostgreSQL for larger datasets
  4. Deploy - Set up as a web service using the included API routes

Enjoy the demo! πŸŽ‰

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages