{
  "name": "02 - Project #2 AI Invoice Processing System",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "invoice-upload",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        0
      ],
      "id": "1edd5183-ee10-47c5-bc45-72ad737aab7d",
      "name": "Webhook"
    },
    {
      "parameters": {
        "operation": "pdf",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1.1,
      "position": [
        208,
        0
      ],
      "id": "ede58241-60d5-450d-a368-ac3164f6edc8",
      "name": "Extract from File"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Extract the following invoice.\n\nReturn ONLY valid JSON.\n\nRequired JSON format:\n\n{\n  \"vendor\": \"\",\n  \"invoice_number\": \"\",\n  \"invoice_date\": \"\",\n  \"currency\": \"\",\n  \"total\": 0,\n  \"items\": []\n}\n\nInvoice:\n\n{{ $json.text }}",
        "messages": {
          "messageValues": []
        },
        "batching": {}
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.9,
      "position": [
        416,
        0
      ],
      "id": "d0f0e388-c7e7-48b2-ac3b-a7de8d3f4c0a",
      "name": "Basic LLM Chain"
    },
    {
      "parameters": {
        "model": "qwen2.5:3b",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "typeVersion": 1,
      "position": [
        416,
        176
      ],
      "id": "62ee2bbb-1e6a-4a7f-8ed2-325fa973deec",
      "name": "Ollama Chat Model",
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "options": {
          "responseCode": 200
        }
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        1072,
        0
      ],
      "id": "0fc36468-51ad-4de4-8306-b8b8b5dd276e",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={{ JSON.parse($json.text) }}\n",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.5,
      "position": [
        688,
        0
      ],
      "id": "b6f7e94f-74f7-473b-a111-766fb51aa095",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "CREATE TABLE IF NOT EXISTS invoices (\n    id SERIAL PRIMARY KEY,\n    vendor TEXT,\n    invoice_number TEXT,\n    invoice_date DATE,\n    currency TEXT,\n    total NUMERIC,\n    items JSONB,\n    created_at TIMESTAMP DEFAULT NOW()\n);",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.7,
      "position": [
        896,
        0
      ],
      "id": "527c91ee-b1c1-43d4-9844-08965c334af0",
      "name": "Execute a SQL query",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ollama Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Basic LLM Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Basic LLM Chain": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Execute a SQL query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute a SQL query": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "747e63e7-cadc-4a78-9d65-c7a705816746",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodeGroups": [],
  "id": "e8Aa2DnUgGRYf56O",
  "tags": []
}