Contract Review & Extraction
Automate contract analysis at scale. The agent reads uploaded contracts, extracts key terms into structured data, compares against your standard playbook, flags deviations and risky clauses, and routes findings for legal review. Every extraction and flag is auditable.
Architecture
Graduated review: Standard-term contracts auto-approve (~60%). Minor deviations get AI risk analysis and recommended redlines (~25%). Novel clauses, high-value agreements, or high-risk provisions escalate to legal counsel (~15%).
Required Actions
| Action | Kind | Purpose |
|---|---|---|
extract_contract_terms |
llm |
Parse contract and extract structured key terms |
lookup_playbook |
http |
Fetch standard acceptable terms for this contract type |
assess_clause_risk |
llm |
Classify risk level of a specific clause |
draft_redline |
llm |
Generate suggested alternative language |
search_precedent |
http |
Search past executed contracts for similar clauses |
log_contract |
custom-table |
Write extracted terms to contract database |
curl -X POST http://localhost:3009/actions \
-H "X-Org-Id: your-org" \
-H "Content-Type: application/json" \
-d '{
"action_name": "extract_contract_terms",
"kind": "llm",
"template": "Extract the following key terms from this contract as JSON:\n- parties (array of names)\n- effective_date\n- termination_date\n- auto_renewal (boolean)\n- renewal_notice_days\n- governing_law\n- liability_cap (amount or \"unlimited\")\n- indemnification_scope (\"mutual\", \"one-way\", \"none\")\n- payment_terms\n- sla_commitments (array)\n- termination_for_convenience (boolean)\n- change_of_control_clause (boolean)\n- data_handling_provisions (summary)\n- non_compete_scope (summary or \"none\")\n\nContract text:\n{{contract_text}}\n\nRespond with valid JSON only.",
"model": "gpt-4",
"max_tokens": 2000
}'
curl -X POST http://localhost:3009/actions \
-H "X-Org-Id: your-org" \
-H "Content-Type: application/json" \
-d '{
"action_name": "assess_clause_risk",
"kind": "llm",
"template": "Assess the risk of this contract clause for our organization.\n\nClause: {{clause_text}}\nOur standard position: {{standard_position}}\nContract value: {{contract_value}}\n\nClassify as:\n- low: Minor deviation, commercially acceptable\n- medium: Notable deviation, should be negotiated but not a blocker\n- high: Material risk, requires legal review before signing\n- critical: Unacceptable as written, must be changed\n\nRespond with JSON: {\"risk_level\": \"...\", \"reasoning\": \"...\", \"recommendation\": \"...\"}",
"model": "gpt-4",
"max_tokens": 500
}'
Workflow Definition
{
"name": "contract_review_pipeline",
"definition": {
"actions": [
{
"type": "extract_contract_terms",
"properties": {
"contract_text": "@input.contract_text"
},
"outputKey": "extracted_terms"
},
{
"type": "matcher",
"properties": {
"left": "@extracted_terms.clauses",
"right": "@input.playbook_terms",
"matchOn": ["clause_type"],
"fuzzyThreshold": 80,
"descriptionKey": "clause_text",
"outputMatched": "standard_clauses",
"outputUnmatchedLeft": "deviations",
"outputUnmatchedRight": "missing_clauses"
}
},
{
"type": "loop",
"filter": {
"condition": {
"or": [
{ "greaterThan": [{ "length": "@deviations" }, 0] },
{ "greaterThan": [{ "length": "@missing_clauses" }, 0] }
]
}
},
"properties": {
"mode": "react",
"objective": "Review these contract deviations and missing clauses.\n\nDeviations from playbook: {{deviations}}\nMissing standard clauses: {{missing_clauses}}\nContract value: {{input.contract_value}}\nCounterparty: {{input.counterparty}}\n\nFor each deviation: 1) Assess the risk level, 2) Search for precedent in past contracts, 3) If high/critical risk, draft redline language. 4) For missing clauses, note whether they're required for this contract type. 5) Complete with a summary and overall risk score.",
"tools": [
{ "type": "action", "name": "assess_clause_risk" },
{ "type": "action", "name": "search_precedent" },
{ "type": "action", "name": "draft_redline" }
],
"model": "gpt-4",
"max_iterations": 15,
"timeout_ms": 300000,
"on_stuck": {
"iterations": 4,
"action": "escalate"
},
"result_key": "review_analysis"
}
},
{
"type": "PbotApproval",
"filter": {
"condition": {
"or": [
{ "greaterThan": ["@input.contract_value", 100000] },
{ "in": ["@review_analysis.overall_risk", ["high", "critical"]] }
]
}
},
"properties": {
"comment": "Contract review complete for {{input.counterparty}}. Value: ${{input.contract_value}}. Risk: {{review_analysis.overall_risk}}. Review AI analysis and approve or request changes.",
"request_payload": {
"counterparty": "@input.counterparty",
"contract_value": "@input.contract_value",
"extracted_terms": "@extracted_terms",
"deviations": "@deviations",
"missing_clauses": "@missing_clauses",
"ai_analysis": "@review_analysis"
}
}
},
{
"type": "custom-table",
"properties": {
"table": "contract_registry",
"operation": "write",
"keys": ["contract_id"],
"values": ["@input.contract_id"],
"fields": {
"counterparty": "@input.counterparty",
"contract_value": "@input.contract_value",
"effective_date": "@extracted_terms.effective_date",
"termination_date": "@extracted_terms.termination_date",
"liability_cap": "@extracted_terms.liability_cap",
"overall_risk": "@review_analysis.overall_risk",
"deviations_count": "@deviations.length",
"reviewed_at": "@now",
"reviewer_approved": "@__approved"
}
}
}
]
}
}
What the Agent Investigates
For each deviation from your standard playbook, the agent:
1. Classifies risk. Uses the assess_clause_risk LLM action with your standard position as context. A liability cap of $1M on a $50K contract is low risk. Unlimited liability on a $500K contract is critical.
2. Searches precedent. Queries your contract database for past agreements with similar deviations. "We accepted a 12-month non-compete from Vendor X in 2024" provides negotiating context.
3. Drafts redlines. For high/critical risks, generates alternative language that protects your position while remaining commercially reasonable.
4. Flags missing clauses. If your playbook requires a data processing addendum and the contract doesn't include one, the agent notes this as a gap requiring attention.
Sample Reasoning Trace
Iteration 1:
Thought: "3 deviations found. Starting with the most concerning: unlimited liability clause."
Action: assess_clause_risk
Input: { "clause_text": "Vendor shall be liable for all damages without limitation...",
"standard_position": "Liability capped at 2x annual contract value",
"contract_value": "250000" }
Result: { "risk_level": "critical", "reasoning": "Unlimited liability on $250K contract exposes us...",
"recommendation": "Require cap at 2x annual value ($500K)" }
Iteration 2:
Thought: "Critical risk. Let me check if we've accepted unlimited liability from this vendor before."
Action: search_precedent
Input: { "counterparty": "TechVendor Inc", "clause_type": "liability" }
Result: { "found": true, "precedent": "2024 contract: liability capped at $300K" }
Iteration 3:
Thought: "We had a cap last time. This is a regression. Drafting redline."
Action: draft_redline
Input: { "original": "Vendor shall be liable for all damages without limitation...",
"position": "Cap at 2x annual value, consistent with 2024 agreement" }
Result: { "suggested_language": "Vendor's aggregate liability shall not exceed two times the annual fees..." }
Iteration 4:
Thought: "Logging progress and moving to next deviation."
Action: __log_progress__
Input: { "message": "Liability clause: CRITICAL. Redline drafted. Precedent: 2024 cap at $300K." }
... [continues for remaining deviations] ...
Iteration 8:
Thought: "All deviations reviewed. 1 critical (liability), 1 medium (auto-renewal), 1 low (governing law)."
Action: __complete__
Input: {
"answer": "Overall risk: HIGH. 1 critical clause (unlimited liability — redline drafted), 1 medium (auto-renewal without notice period), 1 low (governing law difference). Recommend negotiation before signing.",
"confidence": 0.9
}
Customization
Contract types: Adjust the extract_contract_terms template for your contract types — SaaS agreements, NDAs, MSAs, SOWs, vendor agreements. Each type can have a different extraction schema.
Playbook terms: The @input.playbook_terms dataset is your standard acceptable positions. Maintain this as a custom table that legal updates as policies change.
Risk thresholds: The approval filter triggers on contracts over $100K or high/critical risk. Adjust to your organization's materiality thresholds.
Approval routing: For different contract types, configure different approval flows — procurement approves vendor agreements, legal approves customer-facing terms, finance approves payment terms beyond standard.
Term database: The contract_registry custom table builds a searchable database of all extracted terms across every contract. This enables portfolio-level analysis — "how many contracts have unlimited liability?" — and feeds the precedent search tool.