Skip to content

noamrazbuilds/contract-playbook-engine

Repository files navigation

Contract Playbook Enforcement Engine

Review incoming contracts against your negotiation playbook. Upload a contract, select a playbook, and get a deviation report with traffic-light risk ratings, fallback suggestions, and escalation flags.


Getting Started

Option 1: Run Locally (Recommended)

git clone https://github.com/your-org/contract-playbook-engine.git
cd contract-playbook-engine
./start.sh        # macOS/Linux
start.bat         # Windows

This will install dependencies, start the API and frontend, and open your browser. You'll need Python 3.11+ installed.

Option 2: Docker

cp .env.example .env
# Add your ANTHROPIC_API_KEY to .env
docker compose up

Then open http://localhost:8501 in your browser.

Option 3: Hosted Version

Coming soon.


What You'll Need

  • An Anthropic API key (enter it in the app sidebar or set ANTHROPIC_API_KEY in .env)
  • A .docx contract to analyze

The app comes with two sample playbooks pre-loaded (SaaS and Vendor agreements) and sample contracts in data/sample/ so you can test immediately.


How It Works

  1. Upload a .docx contract
  2. Select a negotiation playbook (or upload your own as JSON)
  3. Analyze — the tool extracts clauses, compares each against your playbook, and flags deviations
  4. Review the results with traffic-light risk ratings (green/yellow/red)
  5. Download the deviation report as HTML or Word

Risk Tiers

  • Green — Clause aligns with your approved position
  • Yellow — Deviation detected, but a fallback position is available. Negotiation recommended.
  • Red — Red-line violation or no acceptable fallback. Escalation required.

Features

  • Ingest structured negotiation playbooks (JSON format) with approved positions, fallback language, red lines, and escalation triggers
  • Parse incoming .docx contracts and extract clauses using AI
  • Compare each clause against the corresponding playbook position
  • Traffic-light risk rating per clause (green/yellow/red)
  • Red-line violation and escalation flags
  • Suggested fallback language for deviations
  • Formatted deviation reports (HTML and Word)
  • Multiple playbook profiles (e.g., SaaS, vendor)
  • Analysis history with downloadable reports

For Developers

Project Structure

contract-playbook-engine/
├── api/                        # FastAPI backend
│   ├── main.py                 # App entry point
│   ├── database.py             # SQLAlchemy setup
│   ├── dependencies.py         # DI (DB sessions)
│   ├── models/                 # SQLAlchemy ORM models
│   │   ├── playbook.py
│   │   ├── contract.py
│   │   └── analysis.py
│   ├── schemas/                # Pydantic schemas
│   │   ├── playbook.py
│   │   ├── contract.py
│   │   ├── analysis.py
│   │   └── report.py
│   ├── routers/                # API routes
│   │   ├── playbooks.py
│   │   ├── contracts.py
│   │   ├── analysis.py
│   │   └── reports.py
│   ├── services/               # Business logic
│   │   ├── document_parser.py
│   │   ├── llm_client.py
│   │   ├── clause_extractor.py
│   │   ├── deviation_analyzer.py
│   │   └── report_generator.py
│   └── templates/
│       └── report.html         # Jinja2 report template
├── cpe_frontend/
│   └── app.py                  # Streamlit UI
├── data/sample/                # Sample playbooks and contracts
├── tests/                      # pytest tests
├── start.sh / start.bat        # One-command launchers
├── Dockerfile                  # API container
├── docker-compose.yml          # Multi-service compose
├── pyproject.toml              # Dependencies
└── README.md

API Documentation

Start the API and visit http://localhost:8000/docs for interactive Swagger documentation.

Key endpoints:

Method Endpoint Description
POST /api/v1/playbooks/ Create a playbook
GET /api/v1/playbooks/ List playbooks
POST /api/v1/contracts/upload Upload a .docx contract
POST /api/v1/contracts/{id}/extract Extract clauses (requires API key)
POST /api/v1/analyses/ Run deviation analysis (requires API key)
GET /api/v1/reports/{id}/html Download HTML report
GET /api/v1/reports/{id}/docx Download Word report

Running Tests

source .venv/bin/activate
pytest tests/ -v

All LLM calls are mocked in tests — no API key needed to run the test suite.

Tech Stack

  • Python 3.11+, FastAPI
  • Anthropic API (Claude) for clause analysis
  • python-docx for document parsing
  • SQLAlchemy 2.0 + SQLite
  • Pydantic v2
  • Streamlit
  • pytest
  • Docker + Railway

License

MIT

About

Review incoming contracts against your negotiation playbook. Flags deviations from approved positions, suggests fallback clauses, and generates risk-tiered deviation reports with traffic-light ratings.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors