{
  "name": "Contract Clause Finder",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "contract-clause",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "ccf0001-0001-4000-8000-000000000001",
      "name": "Receive Contract Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [240, 300]
    },
    {
      "parameters": {
        "url": "={{ $json.body.contractUrl }}",
        "options": {
          "responseType": "arraybuffer",
          "timeout": 60000
        }
      },
      "id": "ccf0001-0002-4000-8000-000000000002",
      "name": "Download Contract PDF",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [460, 300]
    },
    {
      "parameters": {
        "operation": "pdf",
        "options": {}
      },
      "id": "ccf0001-0003-4000-8000-000000000003",
      "name": "Extract Contract Text",
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [680, 300]
    },
    {
      "parameters": {
        "resource": "text",
        "operation": "message",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o",
          "mode": "list"
        },
        "messages": {
          "values": [
            {
              "content": "You are a legal contract analyst. The user is looking for information about: {{ $('Receive Contract Webhook').item.json.body.query }}\n\nAnalyze the following contract text and:\n1. Identify and quote the most relevant clauses\n2. Explain what each clause means in plain English\n3. Flag any potentially risky or unusual terms\n4. Provide a risk rating: Low / Medium / High\n\nContract text:\n{{ $json.text }}"
            }
          ]
        },
        "options": {
          "temperature": 0.1
        }
      },
      "id": "ccf0001-0004-4000-8000-000000000004",
      "name": "Find Relevant Clauses",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1,
      "position": [900, 300]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "field1",
              "name": "analysis",
              "value": "={{ $json.message.content }}",
              "type": "string"
            },
            {
              "id": "field2",
              "name": "query",
              "value": "={{ $('Receive Contract Webhook').item.json.body.query }}",
              "type": "string"
            },
            {
              "id": "field3",
              "name": "processedAt",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "ccf0001-0005-4000-8000-000000000005",
      "name": "Structure Result",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3,
      "position": [1120, 300]
    }
  ],
  "connections": {
    "Receive Contract Webhook": {
      "main": [[{ "node": "Download Contract PDF", "type": "main", "index": 0 }]]
    },
    "Download Contract PDF": {
      "main": [[{ "node": "Extract Contract Text", "type": "main", "index": 0 }]]
    },
    "Extract Contract Text": {
      "main": [[{ "node": "Find Relevant Clauses", "type": "main", "index": 0 }]]
    },
    "Find Relevant Clauses": {
      "main": [[{ "node": "Structure Result", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": {},
  "pinData": {}
}
