A runnable LangGraph Studio MVP for contract review with policy routing, interrupt-based human approval, and local audit/reporting.
The graph is intentionally shaped around 7 business nodes:
- A contract comes in.
- The system reads it and breaks it into clauses.
- AI extracts important details and flags risky language.
- A rules engine checks company policy.
- Safe/standard cases move forward automatically.
- Risky or uncertain cases pause for a human reviewer.
- Every decision is logged for audit and reporting.
START
│
▼
ingest_contract
/ \
[failed] [ok]
│ │
│ parse_and_chunk_clauses
│ / \
│ [parse failed] [parsed]
│ │ │
│ │ extract_details_and_flag_risk
│ │ │
│ │ check_policy_rules
│ │ / | \
│ │ [auto_advance] [human_review] [other]
│ │ │ │ │
│ │ auto_advance_ human_review ⚡ │
│ │ standard_cases (interrupt) │
│ │ │ │ │
└───────┴────────┴───────────────┴────────────┘
│
audit_and_report
│
END
Routing summary:
| From | Condition | To |
|---|---|---|
ingest_contract |
final_status == "failed" |
audit_and_report |
ingest_contract |
otherwise | parse_and_chunk_clauses |
parse_and_chunk_clauses |
parse_status != "parsed" |
audit_and_report |
parse_and_chunk_clauses |
parse_status == "parsed" |
extract_details_and_flag_risk |
check_policy_rules |
route == "auto_advance" |
auto_advance_standard_cases |
check_policy_rules |
route == "human_review" |
human_review ⚡ |
check_policy_rules |
otherwise | audit_and_report |
⚡ human_review uses interrupt() — the graph pauses here and resumes on the same thread after a reviewer decision.
This repo started as a spec pack. It now includes a runnable Python LangGraph project that can be opened in LangGraph Studio and demoed locally against contract files on your Mac.
Current MVP scope:
- Local file-path intake for
TXT,DOCX, and text-basedPDF - One LangGraph workflow with exactly 7 top-level nodes
- Multi-provider LLM adapter for
OpenAI,Gemini, andGrok - Deterministic policy routing
- Human-in-the-loop approval via LangGraph
interrupt()with durable local resume - SQLite + JSONL audit logging
- SQLite-backed LangGraph checkpoints for restart-safe local review recovery
- Markdown run reports under
runtime/reports/
Deferred from this first pass:
- OCR for scanned PDFs
- CRM / ticketing / e-sign integrations
- Redline generation
- Production auth / multi-tenancy
contract_review_langgraph/
graph.py
checkpointing.py
nodes.py
llm.py
parsing.py
policies.py
audit.py
prompts.py
state.py
fixtures/
policies/
spec/
tests/
langgraph.json
pyproject.toml
- Create a virtualenv and install dependencies.
- Copy
.env.exampleto.envand add at least one API key. - Start LangGraph Studio dev mode:
langgraph dev- In Studio, run the
contract_review_workflowgraph with input like:
{
"contract_path": "/Users/your-name/path/to/contract.txt",
"provider": "openai",
"policy_pack": "/Users/orbarak/Desktop/or-git/agentic-contract-review/policies/default_policy.yaml",
"run_label": "local-demo"
}-
By default,
LANGGRAPH_CHECKPOINTER=sqlite, so interrupted review threads persist toruntime/audit/checkpoints.sqlite3and can be resumed after a local process restart. -
If the graph pauses in
human_review, resume the same thread with a payload like:
{
"decision": "edit",
"edited_extractions": [
{
"clause_id": "clause-002",
"summary": "Reviewer clarified the indemnity obligation."
}
],
"edited_risks": [
{
"clause_id": "clause-002",
"risk_level": "high",
"confidence": 0.98,
"reviewer_reason": "Broad indemnity remained unacceptable."
}
],
"reviewer_notes": "Escalated risk remained valid.",
"reviewer_id": "demo-reviewer"
}This repo also includes a FastAPI wrapper in api/main.py for browser-based demos.
Current API surface:
POST /api/runPOST /api/resume/{thread_id}GET /api/runs/{thread_id}GET /api/pending-reviewsGET /api/health
If you want to power a public website demo, use the deployment checklist in DEPLOYMENT.md. It covers:
- local API smoke testing
- Railway deployment
- Vercel
VITE_API_URLwiring - CORS setup
- demo-day caveats for interrupt/resume
Every run produces local artifacts:
- SQLite DB:
runtime/audit/audit.sqlite3 - SQLite checkpoints:
runtime/audit/checkpoints.sqlite3 - JSONL event stream:
runtime/audit/events.jsonl - Markdown report:
runtime/reports/<run_id>.md
openaiuses the OpenAI Chat Completions API.grokuses an OpenAI-compatible API shape viahttps://api.x.ai/v1.geminiuses the GooglegenerateContentAPI.- If the chosen provider is unavailable and
ALLOW_HEURISTIC_FALLBACK=true, the graph falls back to a deterministic local extractor so the demo can still run.
The original project framing is still in spec/: