{
  "name": "Analyze contract risk from PDFs with OpenAI, Supabase and Slack alerts",
  "nodes": [
    {
      "id": "8a78e62f-28c0-4d24-9a33-521acd836974",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2032,
        1552
      ],
      "parameters": {
        "width": 560,
        "height": 520,
        "content": "## Enterprise AI Contract Intelligence - Pro\n\n**Who it's for:** Legal, Procurement, Compliance teams. ESN/agencies.\n\n**What it does:**\n1. Upload contract PDF via form (with metadata: type, department,"
      }
    },
    {
      "id": "54d26b31-109f-4508-aaeb-0ecbd3bea3d6",
      "name": "Supabase Schema",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2032,
        896
      ],
      "parameters": {
        "width": 564,
        "height": 620,
        "content": "**Supabase Schema** — Run in Supabase SQL Editor before use:\n\n```sql\nCREATE TABLE IF NOT EXISTS contract_analyses (\n  id UUID DEFAULT gen_random_uuid() PRIMARY KEY,\n  filename TEXT NOT NULL,\n  contrac"
      }
    },
    {
      "id": "87dfd4af-c94e-4d18-b51f-0b3c56cf7072",
      "name": "Step 1 Ingest",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2640,
        1552
      ],
      "parameters": {
        "width": 300,
        "height": 140,
        "content": "**Step 1 - Ingest**\n\nForm upload with metadata (contract type, submitter, department, counterparty) or Manual test with sample data. Config node centralizes all settings."
      }
    },
    {
      "id": "e63d0723-0341-43a0-b15b-f48d78178052",
      "name": "Step 2 Deduplicate",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2976,
        1552
      ],
      "parameters": {
        "width": 300,
        "height": 140,
        "content": "**Step 2 - Deduplicate**\n\nQuery Supabase for existing analysis with the same filename. If found, skip analysis and show previous result. Avoids wasting AI tokens on re-uploads."
      }
    },
    {
      "id": "f658564e-c7a3-4808-a59e-0815adbcceba",
      "name": "Step 3 Extract",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3312,
        1552
      ],
      "parameters": {
        "width": 300,
        "height": 140,
        "content": "**Step 3 - Extract & Prepare**\n\nExtract text from PDF binary, normalize, truncate to 12k chars, merge with form metadata and config for downstream AI calls."
      }
    },
    {
      "id": "a8abaca7-fffe-4268-a7fd-4b8f54fd3086",
      "name": "Step 4 AI Analysis",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3696,
        1552
      ],
      "parameters": {
        "width": 340,
        "height": null,
        "content": "**Step 4 - AI Two-Pass Analysis**\n\nPass 1: Quick classification (type, parties, dates, jurisdiction, ~300 tokens).\nPass 2: Deep risk analysis (clauses, obligations, red flags, recommendations, ~2000 t"
      }
    },
    {
      "id": "aa16c460-b7aa-4b7f-9a75-fd05b74287c9",
      "name": "Step 5 Report Alert",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4144,
        1552
      ],
      "parameters": {
        "width": 360,
        "height": null,
        "content": "**Step 5 - Report, Store & Alert**\n\nBuild Report generates Slack Block Kit JSON + HTML email body.\nSupabase insert stores full analysis with metadata.\nHigh risk → Slack Blocks alert + Gmail HTML repor"
      }
    },
    {
      "id": "cb0e27e8-f26e-436d-a474-f10c699dccb1",
      "name": "Error Handling Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        4832,
        1552
      ],
      "parameters": {
        "width": 320,
        "height": 120,
        "content": "**Error Handling**\n\nError Trigger catches any workflow failure and sends a notification to the admin Slack channel (#n8n-errors). Includes workflow name, error message, and timestamp."
      }
    },
    {
      "id": "2dc1a40d-d75a-43c6-a19f-ac60f5b6a88a",
      "name": "Upload Contract",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        2736,
        1856
      ]
    },
    {
      "id": "536c0506-43b9-4869-9e66-182864bf5d63",
      "name": "Manual Test",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        2736,
        2160
      ]
    },
    {
      "id": "5d3ff4a9-4d75-4f35-b767-84c8f7f680f7",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "position": [
        2736,
        2000
      ]
    },
    {
      "id": "5003aa1e-ea7e-46c0-8e1c-0a3844f2c25c",
      "name": "Check Duplicate",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        3040,
        2000
      ]
    },
    {
      "id": "a0749143-735f-4443-b85f-6748c8a36c7d",
      "name": "Already Exists?",
      "type": "n8n-nodes-base.if",
      "position": [
        3264,
        2000
      ]
    },
    {
      "id": "d6f15504-861a-48c9-b078-4158d17bb5d7",
      "name": "Already Analyzed",
      "type": "n8n-nodes-base.form",
      "position": [
        3472,
        1920
      ]
    },
    {
      "id": "1a67b439-5764-4fce-a3ef-5f4f28f70211",
      "name": "Has File?",
      "type": "n8n-nodes-base.if",
      "position": [
        3472,
        2096
      ]
    },
    {
      "id": "3352c639-8fbe-40c9-ae9b-30faa9c8b083",
      "name": "Extract PDF Text",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        3696,
        2016
      ]
    },
    {
      "id": "9b475384-b8d7-480a-a249-607a16d68cfb",
      "name": "Sample Data",
      "type": "n8n-nodes-base.set",
      "position": [
        3696,
        2192
      ]
    },
    {
      "id": "06ff5e07-5631-4d13-998f-976be80288b5",
      "name": "Prepare Text",
      "type": "n8n-nodes-base.code",
      "position": [
        3920,
        2096
      ]
    },
    {
      "id": "b6bc0ed1-4325-4d2a-8a81-ebf730dc9fac",
      "name": "Parse Classification",
      "type": "n8n-nodes-base.code",
      "position": [
        4384,
        2096
      ]
    },
    {
      "id": "eebe98e1-641f-4930-ae9a-0005ea1b1ed2",
      "name": "Parse Risk Analysis",
      "type": "n8n-nodes-base.code",
      "position": [
        4816,
        2096
      ]
    },
    {
      "id": "db2f0f88-2472-4d28-97e2-a6ab518c7996",
      "name": "Build Report",
      "type": "n8n-nodes-base.code",
      "position": [
        5040,
        2096
      ]
    },
    {
      "id": "7f7d0872-3bb8-4480-b748-96722b07ca77",
      "name": "Supabase Insert",
      "type": "n8n-nodes-base.supabase",
      "position": [
        5264,
        2096
      ]
    },
    {
      "id": "607470fa-deb2-4e4d-9a14-80494cf17b61",
      "name": "High Risk?",
      "type": "n8n-nodes-base.if",
      "position": [
        5472,
        2096
      ]
    },
    {
      "id": "c745489a-3292-424d-9d66-c9d10dd9c8cd",
      "name": "Form Ending",
      "type": "n8n-nodes-base.form",
      "position": [
        6144,
        2096
      ]
    },
    {
      "id": "45f67023-11d0-4198-a0dd-4172751ce974",
      "name": "Error Trigger",
      "type": "n8n-nodes-base.errorTrigger",
      "position": [
        4944,
        2352
      ]
    },
    {
      "id": "a10dab0a-9abd-4fa9-9ea5-8cb4ab4811fd",
      "name": "Slack Admin — Error",
      "type": "n8n-nodes-base.slack",
      "position": [
        5184,
        2352
      ]
    },
    {
      "id": "4fcde5ae-05c7-4c05-ab89-72169fbe7c5a",
      "name": "AI Pass 1 - Classify",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4160,
        2096
      ]
    },
    {
      "id": "97fb58ef-4cc7-4d7d-b0f1-80a915064880",
      "name": "AI Pass 2 - Deep Risk",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        4592,
        2096
      ]
    },
    {
      "id": "3951bc85-a646-4284-93d8-0dd60965d3fd",
      "name": "Slack Alert - High Risk",
      "type": "n8n-nodes-base.slack",
      "position": [
        5696,
        1904
      ]
    },
    {
      "id": "06fbd53b-aba8-4de0-b8ea-2df20c8a7a71",
      "name": "Gmail - Risk Report",
      "type": "n8n-nodes-base.gmail",
      "position": [
        5696,
        2096
      ]
    },
    {
      "id": "971832e8-72b7-4794-bf2f-0e1dacf61ad8",
      "name": "Slack Summary - Low Risk",
      "type": "n8n-nodes-base.slack",
      "position": [
        5696,
        2304
      ]
    }
  ],
  "connections": {
    "Config": {
      "main": [
        [
          {
            "node": "Check Duplicate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has File?": {
      "main": [
        [
          {
            "node": "Extract PDF Text",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sample Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "High Risk?": {
      "main": [
        [
          {
            "node": "Slack Alert - High Risk",
            "type": "main",
            "index": 0
          },
          {
            "node": "Gmail - Risk Report",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Slack Summary - Low Risk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Test": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sample Data": {
      "main": [
        [
          {
            "node": "Prepare Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Report": {
      "main": [
        [
          {
            "node": "Supabase Insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Text": {
      "main": [
        [
          {
            "node": "AI Pass 1 - Classify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Error Trigger": {
      "main": [
        [
          {
            "node": "Slack Admin — Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Already Exists?": {
      "main": [
        [
          {
            "node": "Already Analyzed",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Has File?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Duplicate": {
      "main": [
        [
          {
            "node": "Already Exists?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Insert": {
      "main": [
        [
          {
            "node": "High Risk?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Contract": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract PDF Text": {
      "main": [
        [
          {
            "node": "Prepare Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Risk Analysis": {
      "main": [
        [
          {
            "node": "Build Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Pass 1 - Classify": {
      "main": [
        [
          {
            "node": "Parse Classification",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Classification": {
      "main": [
        [
          {
            "node": "AI Pass 2 - Deep Risk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Pass 2 - Deep Risk": {
      "main": [
        [
          {
            "node": "Parse Risk Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack Alert - High Risk": {
      "main": [
        [
          {
            "node": "Form Ending",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Slack Summary - Low Risk": {
      "main": [
        [
          {
            "node": "Form Ending",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}