Contract Analyzer

Extract key terms, obligations, and risks from legal contracts using a local-first AI workflow.

Quick Example

1import { relay } from "@relayplane/workflows";
2
3const result = await relay
4 .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";
3
4// Define contract schema
5const 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});
26
27async function analyzeContract(contractText: string) {
28 const result = await relay
29 .workflow("contract-analyzer")
30
31 // Step 1: Extract structured contract terms
32 .step("extract-terms", {
33 schema: ContractSchema,
34 systemPrompt: `Extract key contract terms as structured JSON:
35 - Identify all parties and their roles
36 - Parse payment terms and amounts
37 - List all obligations with deadlines
38 - Extract termination and liability clauses
39 - Note auto-renewal provisions`,
40 })
41 .with("anthropic:claude-3.5-sonnet")
42
43 // Step 2: Identify potential risks
44 .step("identify-risks", {
45 systemPrompt: `Analyze the contract for potential risks:
46 - Unfavorable terms or obligations
47 - Missing key provisions
48 - Ambiguous language
49 - Liability exposure
50 - Termination difficulties
51 Return a risk assessment with severity levels.`,
52 })
53 .with("openai:gpt-4o")
54 .depends("extract-terms")
55
56 // Step 3: Generate executive summary
57 .step("summarize", {
58 systemPrompt: `Create executive summary highlighting:
59 - Deal structure and value
60 - Key dates and deadlines
61 - Major obligations
62 - Top 3 risks
63 - Recommended actions`,
64 })
65 .with("openai:gpt-4o-mini")
66 .depends("identify-risks")
67
68 .run({ contractText });
69
70 return {
71 terms: result.steps["extract-terms"],
72 risks: result.steps["identify-risks"],
73 summary: result.steps.summarize,
74 };
75}
76
77// Example usage
78const 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.

See Also