{
  "id": "OhJsiEh8K8qLNiZP",
  "name": "Contract Clause Extraction & Risk Analysis",
  "tags": [],
  "nodes": [
    {
      "id": "fc1f8efb-01bd-48c0-b6bf-b3f6eb76abdd",
      "name": "Groq Chat Model3",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        1632,
        1552
      ],
      "parameters": {
        "model": "llama-3.3-70b-versatile",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "71873cce-7a0d-40f6-b13c-b5810bc8a2ca",
      "name": "Structured Output Parser3",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        1872,
        1552
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"payment_terms\": {\n      \"type\": \"string\",\n      \"description\": \"Detailed payment terms including payment period, invoicing schedule, and late payment fees.\"\n    },\n    \"penalties\": {\n      \"type\": \"string\",\n      \"description\": \"Any penalties, service credits, or financial consequences for non-performance.\"\n    },\n    \"sla\": {\n      \"type\": \"string\",\n      \"description\": \"Service Level Agreements including uptime, response times, and resolution commitments.\"\n    },\n    \"termination\": {\n      \"type\": \"string\",\n      \"description\": \"Conditions and notice period for contract termination.\"\n    },\n    \"renewal\": {\n      \"type\": \"string\",\n      \"description\": \"Contract renewal conditions, auto-renewal terms, and notice requirements.\"\n    },\n    \"liability\": {\n      \"type\": \"string\",\n      \"description\": \"Limitation of liability, caps on damages, and exclusions.\"\n    },\n    \"data_protection\": {\n      \"type\": \"string\",\n      \"description\": \"Data security, privacy, storage location, and compliance obligations.\"\n    }\n  },\n  \"required\": [\n    \"payment_terms\",\n    \"penalties\",\n    \"sla\",\n    \"termination\",\n    \"renewal\",\n    \"liability\",\n    \"data_protection\"\n  ],\n  \"additionalProperties\": false\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "365095b5-df34-439f-ac56-8e9713f6ea49",
      "name": "Groq Chat Model4",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        3808,
        1456
      ],
      "parameters": {
        "model": "openai/gpt-oss-120b",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "13da4070-3294-4413-ae2e-1946b6484a89",
      "name": "Structured Output Parser4",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        4032,
        1456
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"overall_risk_level\": {\n      \"type\": \"string\",\n      \"enum\": [\"Low\", \"Medium\", \"High\"]\n    },\n    \"executive_summary\": {\n      \"type\": \"string\"\n    },\n    \"key_risks\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    },\n    \"clause_risk_review\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"object\",\n        \"properties\": {\n          \"clause_name\": { \"type\": \"string\" },\n          \"risk_level\": {\n            \"type\": \"string\",\n            \"enum\": [\"Low\", \"Medium\", \"High\"]\n          },\n          \"risk_explanation\": { \"type\": \"string\" },\n          \"business_impact\": { \"type\": \"string\" }\n        },\n        \"required\": [\n          \"clause_name\",\n          \"risk_level\",\n          \"risk_explanation\",\n          \"business_impact\"\n        ]\n      }\n    },\n    \"missing_or_weak_protections\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    },\n    \"negotiation_recommendations\": {\n      \"type\": \"array\",\n      \"items\": {\n        \"type\": \"string\"\n      }\n    },\n    \"final_recommendation\": {\n      \"type\": \"string\"\n    }\n  },\n  \"required\": [\n    \"overall_risk_level\",\n    \"executive_summary\",\n    \"key_risks\",\n    \"clause_risk_review\",\n    \"missing_or_weak_protections\",\n    \"negotiation_recommendations\",\n    \"final_recommendation\"\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "28ad32a0-2b76-49b8-a01f-8e5fd5b26717",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        880
      ],
      "parameters": {
        "color": 7,
        "width": 2160,
        "height": 896,
        "content": "## Contract Intake & Text Extraction\nThis segment captures the uploaded contract, reads the file, and converts it into clean readable text for downstream AI clause extraction and analysis."
      },
      "typeVersion": 1
    },
    {
      "id": "6a64b445-f444-4ad3-b02f-fe64479f26c5",
      "name": "Trigger \u2013 Contract Upload",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        80,
        1216
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "12Cg0TruwhYZIIes59_AX0u2GQyZ-elS1",
          "cachedResultUrl": "https://drive.google.com/drive/folders/12Cg0TruwhYZIIes59_AX0u2GQyZ-elS1",
          "cachedResultName": "Contract"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fede913c-b780-45bb-a4b9-3e6445ac2f7d",
      "name": "Download File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        352,
        1216
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "50aecb35-d11f-4e39-832b-5ba618c23fde",
      "name": "Extract content from PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        976,
        1056
      ],
      "parameters": {
        "options": {},
        "operation": "pdf"
      },
      "typeVersion": 1.1
    },
    {
      "id": "bf0939d4-4160-4d8c-8dbb-a632b871e7d4",
      "name": "Check if PDF",
      "type": "n8n-nodes-base.if",
      "position": [
        672,
        1216
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4620d81c-144d-4321-a1a2-6c17164fa00a",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{$binary.data.mimeType}}",
              "rightValue": "=application/pdf"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "52528c4f-0284-4c53-8bd7-257d2e6d06a8",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2720,
        864
      ],
      "parameters": {
        "color": 7,
        "width": 1888,
        "height": 816,
        "content": "## Clause Comparison & AI Risk Assessment\nThis segment compares vendor clauses against company standards and uses AI to generate a full risk report including risk levels, executive summary, key risks, and negotiation recommendations."
      },
      "typeVersion": 1
    },
    {
      "id": "a615f811-1bf5-4cca-9b7e-58df6346185c",
      "name": "Fetch Standard Clauses",
      "type": "n8n-nodes-base.notion",
      "position": [
        2880,
        1056
      ],
      "parameters": {
        "options": {},
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "34431eba-a729-801d-a6ca-fd02cc5cb369",
          "cachedResultUrl": "https://www.notion.so/34431ebaa729801da6cafd02cc5cb369",
          "cachedResultName": "Standard Clause Library"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "83890feb-1a19-4cb6-929e-cca896c6e479",
      "name": "Extract Content",
      "type": "n8n-nodes-base.code",
      "position": [
        1216,
        1248
      ],
      "parameters": {
        "jsCode": "const item = $input.first();\n\n// Safe access\nconst binary = item.binary?.data;\n\nif (!binary) {\n  throw new Error(\"No binary data found. Make sure Dropbox Download node is correct.\");\n}\n\n// Safer filename extraction\nconst fileName =\n  binary.fileName ||\n  item.json[\"File Name\"] ||\n  item.json.name ||\n  \"unknown.md\";\n\nconst mimeType = binary.mimeType;\n\n// Get file buffer\nconst binaryBuffer = await this.helpers.getBinaryDataBuffer(0, 'data');\n\n// Convert to text\nconst fileContent = binaryBuffer.toString('utf-8');\n\nreturn [\n  {\n    json: {\n      fileName,\n      mimeType,\n      fileContent,\n      timestamp: new Date().toISOString()\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "f263956b-92df-48ed-a38a-25df5f606c5f",
      "name": "Extract Contract Clauses",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1664,
        1328
      ],
      "parameters": {
        "text": "=From the contract below extract:\n\n- Payment Terms\n- Late Payment Penalties\n- SLA / Service Levels\n- Termination Clause\n- Renewal Terms\n- Liability Clause\n- Data Protection Clause\n\nReturn JSON format:\n\n{\n \"payment_terms\":\"\",\n \"penalties\":\"\",\n \"sla\":\"\",\n \"termination\":\"\",\n \"renewal\":\"\",\n \"liability\":\"\",\n \"data_protection\":\"\"\n}\n\nContract:\n{{ $json.fileContent || $json.text }}",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "You are a legal contract analyst. Extract key procurement clauses from contracts. Return STRICT JSON."
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "4f8cfc65-1a0c-43b8-a2a1-146b0714face",
      "name": "Compare Vendor vs Standard Clauses",
      "type": "n8n-nodes-base.code",
      "position": [
        3536,
        1184
      ],
      "parameters": {
        "jsCode": "// get all incoming items from Merge node\nconst items = $input.all();\n\n// find the item that contains AI extracted clauses\nconst aiItem = items.find(i => i.json.output);\n\n// vendor clauses live inside output\nconst extracted = aiItem.json.output;\n\n// remaining items = Notion Standard Clause records\nconst standards = items\n  .filter(i => !i.json.output && i.json.property_clause_type)\n  .map(i => i.json);\n\n// helper to get standard clause by type\nfunction getStandard(type){\n  return standards.find(s => s.property_clause_type === type);\n}\n\n\n// clause types must match Notion select values\nconst clauseTypes = [\n  \"Payment Terms\",\n  \"Penalties\",\n  \"SLA\",\n  \"Termination\",\n  \"Renewal\",\n  \"Liability\",\n  \"Data Protection\"\n];\n\nlet deviations = [];\nlet comparison = {};\n\nclauseTypes.forEach(type => {\n\n  const std = getStandard(type);\n\n  // convert to JSON key format used by AI output\n  const key = type.toLowerCase().replace(\" \", \"_\");\n\n  const extractedText = extracted[key];\n  const standardText = std?.property_standard_text || \"\";\n\n  comparison[key] = {\n  clause_type: type,\n  extracted: extractedText,\n  standard: standardText,\n  risk_level_if_deviates: std?.property_risk_level_if_deviates || \"Unknown\"\n};\n\n\n});\n\nreturn [{\n  json: {\n    clauses: extracted,\n    comparison,\n  }\n}];"
      },
      "typeVersion": 2
    },
    {
      "id": "ebf85df5-f71a-4f2b-82df-8c6a88bbb38e",
      "name": "Merge Vendor + Standards",
      "type": "n8n-nodes-base.merge",
      "position": [
        3248,
        1184
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "eb77f9a8-7975-4351-93b0-32af6a290492",
      "name": "AI Risk Analysis & Executive Report",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        3840,
        1184
      ],
      "parameters": {
        "text": "=Here is the clause comparison data:\n\n{{ JSON.stringify($json.comparison, null, 2) }}\n\nCreate a Legal Risk Report with these sections:\n\n1. Executive Summary\n- Overall contract risk level (Low / Medium / High)\n- Short explanation why\n\n2. Key Risk Findings\nExplain the biggest risks and their impact.\n\n3. Clause-by-Clause Risk Review\nFor each deviating clause:\n- Why it is risky\n- Possible business impact\n\n4. Missing or Weak Protections\nIdentify gaps vs standard protections.\n\n5. Negotiation Recommendations\nGive clear actions procurement/legal should request.\n\nEnd with a short conclusion suitable for leadership.",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "You are a senior legal counsel reviewing a vendor contract.  You receive structured clause comparison data between: - Company standard clauses - Vendor contract clauses  Your task: Produce a professional legal risk report for executives.  Write in clear business English. Be concise but insightful. Do NOT output JSON. Use formatted sections."
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "0479b145-aa9c-45d5-8d18-829823bd0c21",
      "name": "Prepare Clause Comparison Dataset",
      "type": "n8n-nodes-base.code",
      "position": [
        4352,
        1184
      ],
      "parameters": {
        "jsCode": "// nodes\nconst compare = $items(\"Compare Vendor vs Standard Clauses\")[0].json.comparison;\nconst aiRisk = $items(\"AI Risk Analysis & Executive Report\")[0].json.output.clause_risk_review;\n\n// normalize helper (VERY IMPORTANT)\nfunction normalize(text){\n  return text\n    .toLowerCase()\n    .replace(/[\\u00A0\\u202F]/g, \" \") // weird spaces \u2192 normal space\n    .replace(/[^\\w\\s]/g, \"\")        // remove punctuation\n    .replace(/\\s+/g, \" \")           // collapse spaces\n    .trim();\n}\n\n// helper \u2192 get risk by clause name\nfunction getRiskLevel(clauseType){\n  const normalizedType = normalize(clauseType);\n\n  const found = aiRisk.find(r =>\n    normalize(r.clause_name) === normalizedType\n  );\n\n  return found ? found.risk_level : \"Unknown\";\n}\n\nconst output = [];\n\nfor (const key of Object.keys(compare)) {\n\n  const clause = compare[key];\n\n  output.push({\n    clause_type: clause.clause_type,\n    vendor_clause: clause.extracted,\n    standard_clause: clause.standard,\n    risk_level: getRiskLevel(clause.clause_type)   \n  });\n\n}\n\nreturn output.map(i => ({ json: i }));"
      },
      "typeVersion": 2
    },
    {
      "id": "39c9a0fa-0a8d-46e2-8646-b1d86fb36a9b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        5104,
        736
      ],
      "parameters": {
        "color": 7,
        "width": 1680,
        "height": 944,
        "content": "## Clause Rewrite Engine (Policy Alignment)\nThis segment rewrites only medium and high-risk clauses using AI to align vendor language with company policy and produce negotiation-ready alternative wording."
      },
      "typeVersion": 1
    },
    {
      "id": "c8073ab3-4994-4d2d-93eb-85c9070bcd16",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        7280,
        736
      ],
      "parameters": {
        "color": 7,
        "width": 1392,
        "height": 816,
        "content": "## Alerts & Contract Storage\nFinal segment alerts stakeholders about risky contracts and stores structured contract intelligence, including risk summary and rewritten clauses, in Notion for tracking, governance, and reporting."
      },
      "typeVersion": 1
    },
    {
      "id": "073c65dd-45a7-491b-8620-4184d8be1266",
      "name": "Loop Through Clauses",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        5328,
        1168
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "6b74501c-cd7b-4bc1-bfd6-9be59c2bdeb1",
      "name": "Check If Clause Needs Rewrite",
      "type": "n8n-nodes-base.if",
      "position": [
        5792,
        1184
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "03d8eaf6-f49c-4515-ab16-f0bad8277e89",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.risk_level }}",
              "rightValue": "Low"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "6e8a517f-976d-4b23-8174-0737195d0823",
      "name": "AI Rewrite Risky Clauses",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        6352,
        1168
      ],
      "parameters": {
        "text": "=You are a senior procurement and legal expert.\n\nYour task is to revise the vendor clause so that it fully aligns with the company\u2019s standard clause and risk requirements.\n\nInstructions:\n- Compare the vendor clause against the company standard clause.\n- Identify gaps or deviations.\n- Rewrite the clause so it aligns with company policy.\n- Preserve clear, enforceable legal language.\n- Do NOT summarize.\n- Do NOT explain.\n- Return only valid JSON.\n\nReturn JSON format:\n{\n  \"clause_type\": \"\",\n  \"risk_level\": \"\",\n  \"revised_clause\": \"\"\n}\n\nClause Type:\n{{ $json.clause_type }}\n\nRisk Level:\n{{ $json.risk_level }}\n\nVendor Clause:\n{{ $json.vendor_clause }}\n\nCompany Standard Clause:\n{{ $json.standard_clause }}",
        "batching": {},
        "messages": {
          "messageValues": [
            {
              "message": "You are a senior legal counsel reviewing a vendor contract.  You receive structured clause comparison data between: - Company standard clauses - Vendor contract clauses  Your task: Produce a professional legal risk report for executives.  Write in clear business English. Be concise but insightful. Do NOT output JSON. Use formatted sections."
            }
          ]
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 1.9
    },
    {
      "id": "288cc323-2792-4b3f-8e4b-0f20abcede27",
      "name": "Parse Rewritten Clause Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        6496,
        1424
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"clause_type\": {\n      \"type\": \"string\",\n      \"description\": \"Name of the clause being rewritten\"\n    },\n    \"revised_clause\": {\n      \"type\": \"string\",\n      \"description\": \"Improved clause wording aligned with company policy\"\n    }\n  },\n  \"required\": [\n    \"clause_type\",\n    \"revised_clause\"\n  ]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "95e7bc56-2824-485c-97d2-cc056a35c966",
      "name": "LLM",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        6352,
        1440
      ],
      "parameters": {
        "model": "meta-llama/llama-4-scout-17b-16e-instruct",
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "3d3ed717-a0e3-456a-8cf7-4b848ca90832",
      "name": "Combine All Revised Clauses",
      "type": "n8n-nodes-base.code",
      "position": [
        6496,
        960
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\n\nconst combined = {};\n\nfor (const item of items) {\n  const out = item.json.output || {};\n  const type = out.clause_type;\n  const text = out.revised_clause;\n\n  if (!type || !text) continue;\n\n  const key = type.toLowerCase().replace(/\\s+/g, \"_\");\n  combined[key] = text;\n}\n\nreturn [\n  {\n    json: {\n      revised_clauses: combined\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "765aa434-cb42-4e19-b759-1ee8aa457b09",
      "name": "Check If Contract Is Risky",
      "type": "n8n-nodes-base.if",
      "position": [
        7712,
        960
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "4ce446e8-61ab-4b8c-a053-2f778cd8883c",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.overall_risk_level }}",
              "rightValue": "High"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "e907bb5d-d20b-45da-81a3-e6d7c95be773",
      "name": "Send Slack Risk Alert",
      "type": "n8n-nodes-base.slack",
      "position": [
        8112,
        944
      ],
      "parameters": {
        "text": "=*HIGH RISK CONTRACT DETECTED*\n\n*Overall Risk Level:* {{ $('Format Final Contract Review Record').item.json.overall_risk_level }}\n*Executive Summary:*\n{{ $('Format Final Contract Review Record').item.json.executive_summary }}\n\n*Key Risks:*\n{{ $('AI Risk Analysis & Executive Report').item.json.output.key_risks.join(\"\\n\u2022 \") }}\n\n*Top Recommendations:*\n{{ $('AI Risk Analysis & Executive Report').item.json.output.negotiation_recommendations.join(\"\\n\u2022 \") }}\n\n*Suggested Clause Rewrites*\n{{ Object.entries($items('Format Final Contract Review Record')[0].json.revised_clauses)\n  .map(([key, value]) => \n    \"\u2022 *\" + key.replace(/_/g,\" \").replace(/\\b\\w/g,l=>l.toUpperCase()) + \"*\\n\" + value\n  ).join(\"\\n\\n\") }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0AQS47TGQ0",
          "cachedResultName": "all-dropbox-note-sync"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 2.4
    },
    {
      "id": "a72b1d32-9aa2-441a-a691-2b1d86ef20c3",
      "name": "Create Contract Review Record",
      "type": "n8n-nodes-base.notion",
      "position": [
        8432,
        1200
      ],
      "parameters": {
        "title": "={{ $('Download File').item.json.name }} - {{$now.toFormat(\"yyyy-LL-dd\")}}",
        "simple": false,
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "34431eba-a729-8019-985e-c8e0c23af9a5",
          "cachedResultUrl": "https://www.notion.so/34431ebaa7298019985ec8e0c23af9a5",
          "cachedResultName": "Contract Reviews"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Risk Level|select",
              "selectValue": "={{  $('Format Final Contract Review Record').item.json.overall_risk_level }}"
            },
            {
              "key": "Executive Summary|rich_text",
              "text": {
                "text": [
                  {
                    "text": "={{  $('AI Risk Analysis & Executive Report').item.json.output.executive_summary }}",
                    "annotationUi": {}
                  }
                ]
              },
              "richText": true
            },
            {
              "key": "Key Risks|rich_text",
              "text": {
                "text": [
                  {
                    "text": "={{String(  $('Format Final Contract Review Record').item.json.key_risks.map(r => \"\u2022 \" + r).join(\"\\n\") )}}",
                    "annotationUi": {}
                  }
                ]
              },
              "richText": true
            },
            {
              "key": "Recommendations|rich_text",
              "text": {
                "text": [
                  {
                    "text": "={{String( $('Format Final Contract Review Record').item.json.negotiation_recommendations.map(r => \"\u2022 \" + r).join(\"\\n\") )}}",
                    "annotationUi": {}
                  }
                ]
              },
              "richText": true
            },
            {
              "key": "Final Recommendation|rich_text",
              "textContent": "={{  $('Format Final Contract Review Record').item.json.final_recommendation }}"
            },
            {
              "key": "Alternative Clauses|rich_text",
              "textContent": "={{ Object.entries($items(\"Format Final Contract Review Record\")[0].json.revised_clauses)\n  .map(([key, value]) => \n    \"\u2022 \" + key.replace(/_/g,\" \").replace(/\\b\\w/g,l=>l.toUpperCase()) + \"\\n\" + value\n  ).join(\"\\n\\n\") }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "830473d1-a8a6-4179-a3af-9a4eee91f5e0",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -576
      ],
      "parameters": {
        "width": 1216,
        "height": 864,
        "content": "## Workflow Overview: Contract Clause Extraction & Risk Analysis\n\nThis workflow automates the end-to-end review of vendor contracts to detect risk before signing. It extracts clauses from uploaded agreements, compares them with company-approved standards stored in Notion, performs AI-driven risk assessment, and generates executive insights, alerts, and recommended clause rewrites. High-risk contracts trigger Slack notifications while all structured results are stored in Notion, enabling procurement and legal teams to review, negotiate, and approve contracts faster with consistent policy alignment.\n\n## How it works\n\nThe workflow begins when a contract is uploaded. The file is read and converted into raw text, allowing both PDF/DOC and text-based contracts to be processed.  \nAI then extracts key procurement clauses such as payment terms, SLA, penalties, termination, renewal, liability, and data protection.\n\nNext, the workflow retrieves company standard clauses from Notion and compares them against the vendor contract to detect deviations.  \nAn AI risk analysis step evaluates each clause, assigns risk levels, highlights missing protections, and produces an executive summary with negotiation recommendations.\n\nIf risk is detected, the workflow sends a formatted Slack alert containing the risk summary and suggested clause rewrites.  \nFinally, all structured contract review data is stored in Notion for auditability, reporting, and future reference.\n\n## Setup steps \n\n**Trigger Contract Upload** \u2014 Start workflow when a new contract is uploaded.  \n**Extract Contract Text** \u2014 Convert PDF/DOC/TXT to text.  \n**AI Clause Extraction** \u2014 Extract key clauses in structured format.  \n**Fetch Standard Clauses** \u2014 Load company clause templates from Notion.  \n**Compare Clauses** \u2014 Detect deviations from standards.  \n**AI Risk Analysis** \u2014 Generate risk report and recommendations.  \n**Rewrite Risky Clauses** \u2014 Produce safer alternative wording.  \n**Send Slack Alert** \u2014 Notify stakeholders if risk detected.  \n**Store in Notion** \u2014 Save structured contract review data."
      },
      "typeVersion": 1
    },
    {
      "id": "ec3d8715-d9b1-4036-be4d-bc33837a506c",
      "name": "Format Final Contract Review Record",
      "type": "n8n-nodes-base.set",
      "position": [
        7408,
        960
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b0b2bc5f-1e9b-4c74-8bb4-48b62c206318",
              "name": "revised_clauses",
              "type": "object",
              "value": "={{ $json.revised_clauses }}"
            },
            {
              "id": "dc388dff-cabe-4964-bf06-623d2c2755eb",
              "name": "name",
              "type": "string",
              "value": "={{ $('Download File').item.json.name }}"
            },
            {
              "id": "6b6cbeab-2b9f-47d1-bc25-4b888df3c197",
              "name": "executive_summary",
              "type": "string",
              "value": "={{ $('AI Risk Analysis & Executive Report').item.json.output.executive_summary }}"
            },
            {
              "id": "93373257-48d2-49cc-97dc-b7884fbd5e4b",
              "name": "overall_risk_level",
              "type": "string",
              "value": "={{ $('AI Risk Analysis & Executive Report').item.json.output.overall_risk_level }}"
            },
            {
              "id": "ad9b7de2-4fcd-43c2-89a6-fbe6f21c7db0",
              "name": "final_recommendation",
              "type": "string",
              "value": "={{ $('AI Risk Analysis & Executive Report').item.json.output.final_recommendation }}"
            },
            {
              "id": "e36eb634-d99e-44e2-83a0-ca493ddb5517",
              "name": "negotiation_recommendations",
              "type": "array",
              "value": "={{ $('AI Risk Analysis & Executive Report').item.json.output.negotiation_recommendations }}"
            },
            {
              "id": "fc0de024-4e77-4d0c-9b51-05029f1d31ff",
              "name": "key_risks",
              "type": "array",
              "value": "={{ $('AI Risk Analysis & Executive Report').item.json.output.key_risks }}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "executionOrder": "v1"
  },
  "versionId": "fd206044-3718-4559-93fc-031a22c54cee",
  "nodeGroups": [],
  "connections": {
    "LLM": {
      "ai_languageModel": [
        [
          {
            "node": "AI Rewrite Risky Clauses",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check if PDF": {
      "main": [
        [
          {
            "node": "Extract content from PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Check if PDF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Content": {
      "main": [
        [
          {
            "node": "Extract Contract Clauses",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Standard Clauses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Contract Clauses",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model4": {
      "ai_languageModel": [
        [
          {
            "node": "AI Risk Analysis & Executive Report",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Loop Through Clauses": {
      "main": [
        [
          {
            "node": "Combine All Revised Clauses",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Check If Clause Needs Rewrite",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Slack Risk Alert": {
      "main": [
        [
          {
            "node": "Create Contract Review Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Standard Clauses": {
      "main": [
        [
          {
            "node": "Merge Vendor + Standards",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Rewrite Risky Clauses": {
      "main": [
        [
          {
            "node": "Loop Through Clauses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Contract Clauses": {
      "main": [
        [
          {
            "node": "Merge Vendor + Standards",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Extract content from PDF": {
      "main": [
        [
          {
            "node": "Extract Contract Clauses",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Standard Clauses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Vendor + Standards": {
      "main": [
        [
          {
            "node": "Compare Vendor vs Standard Clauses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser3": {
      "ai_outputParser": [
        [
          {
            "node": "Extract Contract Clauses",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser4": {
      "ai_outputParser": [
        [
          {
            "node": "AI Risk Analysis & Executive Report",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Check If Contract Is Risky": {
      "main": [
        [
          {
            "node": "Send Slack Risk Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Contract Review Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Combine All Revised Clauses": {
      "main": [
        [
          {
            "node": "Format Final Contract Review Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trigger \u2013 Contract Upload": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If Clause Needs Rewrite": {
      "main": [
        [
          {
            "node": "AI Rewrite Risky Clauses",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Through Clauses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Rewritten Clause Output": {
      "ai_outputParser": [
        [
          {
            "node": "AI Rewrite Risky Clauses",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Clause Comparison Dataset": {
      "main": [
        [
          {
            "node": "Loop Through Clauses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compare Vendor vs Standard Clauses": {
      "main": [
        [
          {
            "node": "AI Risk Analysis & Executive Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Risk Analysis & Executive Report": {
      "main": [
        [
          {
            "node": "Prepare Clause Comparison Dataset",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Final Contract Review Record": {
      "main": [
        [
          {
            "node": "Check If Contract Is Risky",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}