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.
git clone https://github.com/your-org/contract-playbook-engine.git
cd contract-playbook-engine
./start.sh # macOS/Linux
start.bat # WindowsThis will install dependencies, start the API and frontend, and open your browser. You'll need Python 3.11+ installed.
cp .env.example .env
# Add your ANTHROPIC_API_KEY to .env
docker compose upThen open http://localhost:8501 in your browser.
Coming soon.
- An Anthropic API key (enter it in the app sidebar or set
ANTHROPIC_API_KEYin.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.
- Upload a .docx contract
- Select a negotiation playbook (or upload your own as JSON)
- Analyze — the tool extracts clauses, compares each against your playbook, and flags deviations
- Review the results with traffic-light risk ratings (green/yellow/red)
- Download the deviation report as HTML or Word
- 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.
- 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
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
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 |
source .venv/bin/activate
pytest tests/ -vAll LLM calls are mocked in tests — no API key needed to run the test suite.
- 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
MIT