Skip to content

noamrazbuilds/contract-analytics

Repository files navigation

Contract Analytics & Benchmarking Engine

Analyze your executed contract portfolio to extract and benchmark key commercial terms. See how your liability caps, payment terms, warranty periods, and other positions compare to your targets and how they've trended over time.

Getting Started

Option 1: Hosted Version

Coming soon — a hosted version will be available at a public URL.

Option 2: Run Locally

./start.sh        # macOS / Linux
start.bat          # Windows

This automatically installs dependencies, generates sample contracts, starts both the API and frontend, and opens your browser.

Requirements: Python 3.11+ and an Anthropic API key.

Set your API key before running:

export ANTHROPIC_API_KEY=your-key-here   # macOS/Linux
set ANTHROPIC_API_KEY=your-key-here      # Windows

Option 3: Docker

ANTHROPIC_API_KEY=your-key-here docker compose up

Deploy Your Own

Railway (One-Click Cloud Deploy)

  1. Fork this repository
  2. Create a new project on Railway
  3. Connect your GitHub repo
  4. Add environment variable: ANTHROPIC_API_KEY
  5. Deploy — Railway uses Dockerfile.railway automatically

Features

  • Bulk contract ingestion — Upload PDF and Word contracts
  • AI-powered extraction — Claude extracts liability caps, indemnity scope, payment terms, warranty periods, termination provisions, SLA commitments, and contract value/duration
  • Source clause tracking — Every extracted term links back to the exact contract language
  • Distribution analysis — See how your terms are distributed across your portfolio
  • Trend analysis — Track how your negotiated positions have changed over time
  • Counterparty comparison — Compare terms across different counterparties
  • Playbook benchmarking — Set target positions and see which contracts deviate
  • Compliance scoring — Portfolio-wide compliance rate against your playbook
  • Exportable reports — Download portfolio and contract reports as CSV or JSON

For Developers

Project Structure

contract-analytics/
├── src/contract_analytics/    # FastAPI backend
│   ├── main.py                # App entry point
│   ├── config.py              # Settings
│   ├── database.py            # SQLAlchemy setup
│   ├── models/                # ORM models
│   ├── schemas/               # Pydantic schemas
│   ├── services/              # Business logic
│   └── api/v1/                # API routers
├── ca_frontend/app.py            # Streamlit UI
├── tests/                     # pytest tests
├── scripts/                   # Utilities
│   └── generate_sample_contracts.py
└── data/
    ├── sample/                # Synthetic sample contracts
    └── uploads/               # Uploaded contracts (gitignored)

API Documentation

With the server running, visit http://localhost:8000/docs for interactive Swagger docs.

Key endpoints:

Endpoint Description
POST /api/v1/contracts/upload Upload contracts
POST /api/v1/contracts/{id}/extract Extract terms from a contract
GET /api/v1/analytics/summary Portfolio summary stats
GET /api/v1/analytics/distributions/{term_type} Term distribution
GET /api/v1/analytics/trends/{term_type} Term trends over time
GET /api/v1/analytics/playbook-deviation Playbook compliance
GET /api/v1/reports/portfolio Export portfolio report

Running Tests

pip install -e ".[dev]"
pytest

Tech Stack

  • Backend: Python 3.11+, FastAPI, SQLAlchemy 2.0, Pydantic v2
  • AI: Anthropic Claude (Sonnet) via tool_use for structured extraction
  • Document parsing: PyMuPDF (PDF), python-docx (Word)
  • Frontend: Streamlit with Plotly charts
  • Database: SQLite (designed for PostgreSQL migration)
  • Deployment: Docker, Railway

License

MIT License. Copyright (c) 2026 Noam Raz and Pleasant Secret Labs.

About

AI-powered tool that extracts and benchmarks key commercial terms from executed contracts using Claude. Analyze liability caps, payment terms, SLAs, and more across your portfolio with distribution, trend, and playbook compliance views.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages