Contract Analyzer
Extract key terms, obligations, and risks from legal contracts using a local-first AI workflow.
Quick Example
1import { relay } from "@relayplane/workflows";23const result = await relay4 .workflow("contract-analyzer")5 .step("extract-terms").with("anthropic:claude-3.5-sonnet")6 .step("identify-risks").with("openai:gpt-4o").depends("extract-terms")7 .run({ contractText: "..." });Full Implementation
1import { relay } from "@relayplane/workflows";2import { z } from "zod";34// Define contract schema5const ContractSchema = z.object({6 parties: z.array(z.object({7 name: z.string(),8 role: z.enum(["client", "vendor", "partner"]),9 })),10 effectiveDate: z.string(),11 expirationDate: z.string().optional(),12 autoRenewal: z.boolean(),13 paymentTerms: z.object({14 amount: z.number(),15 frequency: z.string(),16 currency: z.string(),17 }),18 obligations: z.array(z.object({19 party: z.string(),20 description: z.string(),21 deadline: z.string().optional(),22 })),23 terminationClauses: z.array(z.string()),24 liabilityLimits: z.string().optional(),25});2627async function analyzeContract(contractText: string) {28 const result = await relay29 .workflow("contract-analyzer")3031 // Step 1: Extract structured contract terms32 .step("extract-terms", {33 schema: ContractSchema,34 systemPrompt: `Extract key contract terms as structured JSON:35 - Identify all parties and their roles36 - Parse payment terms and amounts37 - List all obligations with deadlines38 - Extract termination and liability clauses39 - Note auto-renewal provisions`,40 })41 .with("anthropic:claude-3.5-sonnet")4243 // Step 2: Identify potential risks44 .step("identify-risks", {45 systemPrompt: `Analyze the contract for potential risks:46 - Unfavorable terms or obligations47 - Missing key provisions48 - Ambiguous language49 - Liability exposure50 - Termination difficulties51 Return a risk assessment with severity levels.`,52 })53 .with("openai:gpt-4o")54 .depends("extract-terms")5556 // Step 3: Generate executive summary57 .step("summarize", {58 systemPrompt: `Create executive summary highlighting:59 - Deal structure and value60 - Key dates and deadlines61 - Major obligations62 - Top 3 risks63 - Recommended actions`,64 })65 .with("openai:gpt-4o-mini")66 .depends("identify-risks")6768 .run({ contractText });6970 return {71 terms: result.steps["extract-terms"],72 risks: result.steps["identify-risks"],73 summary: result.steps.summarize,74 };75}7677// Example usage78const analysis = await analyzeContract(contractPDF);79console.log("Summary:", analysis.summary);80console.log("Risks:", analysis.risks);Use Cases
- Vendor contract review automation
- NDA analysis and comparison
- SaaS agreement evaluation
- Employment contract screening
- Partnership agreement analysis
Best Practices
- Use Claude for legal text extraction - better at structured legal language
- Always have legal review for high-value contracts
- Compare against your standard contract templates
- Flag non-standard clauses for manual review
This workflow assists legal review but does not replace legal counsel.Always have contracts reviewed by qualified legal professionals.