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
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.
This is a Minimum Viable Product (MVP) demonstrating enterprise-grade contract analysis capabilities.
Created and maintained by: Your Name
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
This pipeline performs comprehensive contract analysis:
- Ingests PDF contracts into a database
- OCR Extraction using Google Document AI (layout-aware, high accuracy)
- AI Field Extraction using GPT-4 (extracts structured fields like dates, parties, values)
- AI Clause Extraction using GPT-4 (identifies and extracts key legal clauses)
- 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
-
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
-
OpenAI API (for GPT-4 extraction)
- OpenAI account with API access
- Active API key with GPT-4 access
- Python: 3.11 or higher
- Operating System: Windows, macOS, or Linux
- RAM: 4GB minimum (8GB recommended)
- Disk Space: 500MB for dependencies + contract storage
pip install -r requirements.txtCreate 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.1Place your Google Cloud service account JSON file as gcloud.json in the root directory.
How to get this file:
- Go to Google Cloud Console
- Navigate to IAM & Admin > Service Accounts
- Create or select a service account with Document AI permissions
- Create a key (JSON format)
- Save as
gcloud.jsonin this folder
Place your PDF contracts in the contracts/ folder. The demo includes 3 sample contracts (test.pdf, test1.pdf, test2.pdf).
python run_full_pipeline.pyThis 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
After running the pipeline, you'll find:
comprehensive_report.html- Full analysis report (open in browser)contracts.db- SQLite database with all extracted datadata/uploads/- Stored PDF filesdata/thumbnails/- PDF thumbnails
# Windows
start comprehensive_report.html
# macOS
open comprehensive_report.html
# Linux
xdg-open comprehensive_report.htmlpython view_extraction.pyThis displays all extracted fields and clauses in the terminal.
The system uses a playbook to define what to extract from contracts. The default playbook extracts:
effective_date- When the contract becomes effectiveexpiration_date- When the contract expirescontract_value- Total monetary valueparty_a- First contracting party nameparty_b- Second contracting party namejurisdiction- Governing law jurisdictiontermination_notice_days- Notice period for terminationrenewal_term- Automatic renewal terms
confidentiality- Confidentiality obligationsliability_limitation- Limitation of liabilitytermination_conditions- Termination procedurespayment_terms- Payment schedule and methodsindemnification- Indemnification obligationsintellectual_property- IP rights and ownership
You can customize the playbook by editing app/extract/playbook.py or creating a custom JSON playbook file.
Solution:
- Check that
gcloud.jsonexists in the root folder - Verify the file contains valid JSON credentials
- Ensure Document AI API is enabled in your GCP project
- Confirm your service account has Document AI permissions
- Check that
GOOGLE_APPLICATION_CREDENTIALSin.envpoints to./gcloud.json
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
Solution:
- Ensure you're running commands from the
A.I-Processing-Demodirectory - Install all dependencies:
pip install -r requirements.txt
Solution:
- Delete
contracts.dband runpython run_full_pipeline.pyagain - This will recreate the database with a fresh schema
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
The system supports optional background and goal fields in playbooks to give the AI context about the legal matter, improving extraction accuracy.
AI automatically flags low-confidence extractions with explanations for human review:
needs_human_review- Boolean flagreview_reason- Explanation of why review is neededalternative_values- Possible alternative values found
Uses embeddings to group similar clauses across contracts, even when worded differently. Helps identify commonality vs. variations.
Every extracted field and clause includes:
- Source page numbers
- Confidence scores
- Extraction method (llm, ocr, fallback)
- Model used (gpt-4o, etc.)
- Timestamps
Automatically tracks when contract terms changed over time based on effective dates.
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
- 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
.envfile (add to.gitignore)
For questions or issues:
- Check the Troubleshooting section above
- Review error messages in the terminal
- Check that all prerequisites are met
- Verify
.envconfiguration is correct
License: Proprietary - Evaluation/Demonstration License
Created by: Your Name
Copyright Β© 2025 - All Rights Reserved
β
Evaluation and testing
β
Proof-of-concept demonstrations
β
Academic research
β Production deployment in business operations
β Building commercial features on this codebase
β Integration into existing business systems
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.
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
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
After running the demo successfully:
- Customize the playbook - Edit fields/clauses for your specific contract types
- Add more contracts - Place additional PDFs in the
contracts/folder - Scale up - Consider switching to PostgreSQL for larger datasets
- Deploy - Set up as a web service using the included API routes
Enjoy the demo! π