{
  "id": "YIJV9oyQgWMVM9F9",
  "name": "Autonomous AI-Driven Document Trust, Fraud Detection and Compliance Engine",
  "tags": [],
  "nodes": [
    {
      "id": "4832d247-cb09-4945-9056-5595f87f9fdb",
      "name": "Document Ingestion Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -1936,
        288
      ],
      "parameters": {
        "path": "document-ingestion",
        "options": {
          "binaryPropertyName": "data"
        },
        "httpMethod": "POST",
        "responseMode": "lastNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "49e1d7ab-f0ac-4c24-81f4-bf0cc1873194",
      "name": "Workflow Configuration",
      "type": "n8n-nodes-base.set",
      "position": [
        -1712,
        288
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "riskThresholdLow",
              "type": "number",
              "value": 30
            },
            {
              "id": "id-2",
              "name": "riskThresholdHigh",
              "type": "number",
              "value": 70
            },
            {
              "id": "id-3",
              "name": "riskThresholdCritical",
              "type": "number",
              "value": 90
            },
            {
              "id": "id-4",
              "name": "maxWaitTimeHours",
              "type": "number",
              "value": 48
            },
            {
              "id": "id-5",
              "name": "vectorStoreMemoryId",
              "type": "string",
              "value": "fraud_detection_docs"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "dd2721c6-ec7a-4b44-93dc-608da857853f",
      "name": "Generate Document Hash",
      "type": "n8n-nodes-base.crypto",
      "position": [
        -1488,
        288
      ],
      "parameters": {
        "type": "SHA256",
        "binaryData": true,
        "dataPropertyName": "documentHash"
      },
      "typeVersion": 1
    },
    {
      "id": "800737e3-8569-4152-97c7-7d6138adc926",
      "name": "Route by Document Type",
      "type": "n8n-nodes-base.switch",
      "position": [
        -1264,
        256
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "PDF",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $json.mimeType }}",
                    "rightValue": "pdf"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Image",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $json.mimeType }}",
                    "rightValue": "image"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Office",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": false,
                  "typeValidation": "loose"
                },
                "combinator": "or",
                "conditions": [
                  {
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $json.mimeType }}",
                    "rightValue": "officedocument"
                  },
                  {
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $json.mimeType }}",
                    "rightValue": "msword"
                  },
                  {
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "leftValue": "={{ $json.mimeType }}",
                    "rightValue": "ms-excel"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "ignoreCase": true,
          "fallbackOutput": "extra"
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "0af0936e-96d8-4419-b490-2c1dc98f2b0f",
      "name": "Extract Text from PDF",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -1040,
        96
      ],
      "parameters": {
        "options": {
          "joinPages": true
        },
        "operation": "pdf"
      },
      "typeVersion": 1.1
    },
    {
      "id": "f48e9bfe-14b1-4207-a9f1-b7d358f9421d",
      "name": "OCR Processing for Images",
      "type": "n8n-nodes-base.code",
      "position": [
        -1040,
        288
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// OCR Processing for Images\n// Extract text from image binary data using OCR service\n\nconst item = $input.item;\n\n// Get the binary data from the input\nconst binaryData = item.binary;\n\nif (!binaryData) {\n  throw new Error('No binary data found in input item');\n}\n\n// Get the first binary property (usually 'data' or similar)\nconst binaryPropertyName = Object.keys(binaryData)[0];\nconst imageData = binaryData[binaryPropertyName];\n\nif (!imageData) {\n  throw new Error('No image data found in binary property');\n}\n\n// Placeholder for OCR service integration\n// In production, this would call an OCR API like Google Vision, AWS Textract, or Tesseract\nconst ocrServiceUrl = '<__PLACEHOLDER_VALUE__OCR_API_ENDPOINT__>';\nconst ocrApiKey = '<__PLACEHOLDER_VALUE__OCR_API_KEY__>';\n\n// Simulate OCR processing\n// In production, you would:\n// 1. Convert binary data to base64 or buffer\n// 2. Send to OCR service API\n// 3. Parse the response to extract text\n\nconst extractedText = `[OCR PLACEHOLDER] Text extracted from image: ${imageData.fileName || 'unknown'}\\n\\nThis is where the actual OCR text would appear after processing the image through an OCR service.`;\n\n// Return the extracted text along with preserved binary data\nreturn {\n  json: {\n    text: extractedText,\n    fileName: imageData.fileName || 'unknown',\n    mimeType: imageData.mimeType || 'unknown',\n    fileSize: imageData.fileSize || 0,\n    ocrProcessed: true,\n    ocrTimestamp: new Date().toISOString()\n  },\n  binary: binaryData\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "463e43df-4e14-43ad-b1de-fd2c515e886d",
      "name": "Extract from Office Documents",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        -1040,
        480
      ],
      "parameters": {
        "options": {},
        "operation": "xlsx"
      },
      "typeVersion": 1.1
    },
    {
      "id": "e09cb369-be82-4268-9edf-c887fe15d046",
      "name": "Merge Extracted Content",
      "type": "n8n-nodes-base.merge",
      "position": [
        -816,
        272
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition",
        "numberInputs": 3
      },
      "typeVersion": 3.2
    },
    {
      "id": "e51e0acf-ebad-4050-a8b3-da91eb25e5e1",
      "name": "Metadata Extraction Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -48,
        32
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "You are a document metadata extraction specialist. Extract structured metadata from the provided document text.\n\nExtract the following fields:\n- documentType: Type of document (invoice, contract, ID, certificate, etc.)\n- issuer: Organization or entity that issued the document\n- issueDate: Date the document was issued (ISO format)\n- expiryDate: Expiry date if applicable (ISO format)\n- documentNumber: Unique identifier or reference number\n- entities: Array of named entities (people, organizations, locations)\n- keyDates: Array of important dates mentioned\n- amounts: Array of monetary amounts with currency\n- signatures: Number and description of signatures present\n- watermarks: Description of watermarks or security features\n\nReturn all fields in the structured format defined by the output parser."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "86ffc223-4049-436b-8fd9-cdee40e909ec",
      "name": "OpenAI Model - Metadata",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -40,
        208
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c7b9c812-fa3f-4c3d-b7ec-4c56a3d2f8d5",
      "name": "Metadata Schema Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        88,
        208
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"documentType\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"The type of document (e.g., invoice, contract, passport, etc.)\"\n\t\t},\n\t\t\"issuer\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"The entity that issued the document\"\n\t\t},\n\t\t\"issueDate\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"The date the document was issued\"\n\t\t},\n\t\t\"expiryDate\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"The expiry date of the document\"\n\t\t},\n\t\t\"documentNumber\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"The unique identifier or number of the document\"\n\t\t},\n\t\t\"entities\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"description\": \"List of entities mentioned in the document\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"string\"\n\t\t\t}\n\t\t},\n\t\t\"keyDates\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"description\": \"Important dates mentioned in the document\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"string\"\n\t\t\t}\n\t\t},\n\t\t\"amounts\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"description\": \"Monetary amounts or numerical values in the document\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"number\"\n\t\t\t}\n\t\t},\n\t\t\"signatures\": {\n\t\t\t\"type\": \"object\",\n\t\t\t\"description\": \"Information about signatures present in the document\",\n\t\t\t\"properties\": {\n\t\t\t\t\"present\": {\n\t\t\t\t\t\"type\": \"boolean\"\n\t\t\t\t},\n\t\t\t\t\"count\": {\n\t\t\t\t\t\"type\": \"number\"\n\t\t\t\t},\n\t\t\t\t\"signatories\": {\n\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"watermarks\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Description of watermarks or security features present\"\n\t\t}\n\t}\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "f24bf43b-73fb-4732-aa24-9751f4dc202f",
      "name": "Forgery Detection Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -48,
        432
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "You are a forensic document analysis expert specializing in forgery detection.\n\nAnalyze the document text for indicators of forgery or manipulation:\n\n1. Inconsistent formatting or fonts\n2. Suspicious date patterns or chronological inconsistencies\n3. Unusual language patterns or terminology\n4. Missing or incomplete security features\n5. Alterations or corrections that seem suspicious\n6. Mismatched signatures or authorization patterns\n7. Inconsistent metadata or document properties\n\nFor each indicator found, provide:\n- indicator: Type of forgery indicator\n- severity: low, medium, high, critical\n- description: Detailed explanation\n- confidence: Confidence score 0-100\n- location: Where in document this was found\n\nReturn structured analysis with overall forgery risk score (0-100)."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "81e2642c-e06e-47f7-8082-7aef9ffde3d3",
      "name": "OpenAI Model - Forgery",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -40,
        608
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c42ca91a-c76c-475c-b12a-b3f59abf7097",
      "name": "Forgery Analysis Schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        88,
        608
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"overallRiskScore\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Overall risk score for forgery detection\"\n\t\t},\n\t\t\"indicators\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"object\",\n\t\t\t\t\"properties\": {\n\t\t\t\t\t\"indicator\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Name or type of the forgery indicator\"\n\t\t\t\t\t},\n\t\t\t\t\t\"severity\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Severity level of the indicator\"\n\t\t\t\t\t},\n\t\t\t\t\t\"description\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Detailed description of the indicator\"\n\t\t\t\t\t},\n\t\t\t\t\t\"confidence\": {\n\t\t\t\t\t\t\"type\": \"number\",\n\t\t\t\t\t\t\"description\": \"Confidence level in the indicator detection\"\n\t\t\t\t\t},\n\t\t\t\t\t\"location\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Location in the document where the indicator was found\"\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t\"required\": [\"indicator\", \"severity\", \"description\", \"confidence\", \"location\"]\n\t\t\t},\n\t\t\t\"description\": \"Array of forgery indicators detected\"\n\t\t},\n\t\t\"recommendation\": {\n\t\t\t\"type\": \"string\",\n\t\t\t\"description\": \"Recommendation based on the forgery analysis\"\n\t\t}\n\t},\n\t\"required\": [\"overallRiskScore\", \"indicators\", \"recommendation\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "3899ee56-317a-4cfb-9356-1b32034e08fe",
      "name": "Semantic Contradiction Detector",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -48,
        784
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "You are a semantic analysis expert detecting logical contradictions and inconsistencies in documents.\n\nAnalyze the document for:\n\n1. Internal contradictions (statements that conflict with each other)\n2. Temporal inconsistencies (impossible timelines or date conflicts)\n3. Logical impossibilities (claims that cannot be true simultaneously)\n4. Inconsistent numerical data (amounts that don't add up)\n5. Conflicting entity information (same entity with different attributes)\n6. Policy or regulation violations\n\nFor each contradiction found:\n- type: Type of contradiction\n- severity: low, medium, high, critical\n- description: What contradicts what\n- evidence: Specific text excerpts\n- confidence: Confidence score 0-100\n\nReturn structured analysis with overall contradiction risk score (0-100)."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "7fb5708c-37bc-46bd-af31-53e4dbf0d8af",
      "name": "OpenAI Model - Semantic",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -40,
        1008
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "5d47675b-b5e7-4697-a0ed-7e0217734698",
      "name": "Contradiction Schema Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        88,
        1008
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"overallRiskScore\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Overall risk score for contradictions\"\n\t\t},\n\t\t\"contradictions\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"object\",\n\t\t\t\t\"properties\": {\n\t\t\t\t\t\"type\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Type of contradiction\"\n\t\t\t\t\t},\n\t\t\t\t\t\"severity\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Severity level of the contradiction\"\n\t\t\t\t\t},\n\t\t\t\t\t\"description\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Description of the contradiction\"\n\t\t\t\t\t},\n\t\t\t\t\t\"evidence\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Evidence supporting the contradiction\"\n\t\t\t\t\t},\n\t\t\t\t\t\"confidence\": {\n\t\t\t\t\t\t\"type\": \"number\",\n\t\t\t\t\t\t\"description\": \"Confidence level in the contradiction detection\"\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t\"required\": [\"type\", \"severity\", \"description\", \"evidence\", \"confidence\"]\n\t\t\t},\n\t\t\t\"description\": \"Array of detected contradictions\"\n\t\t},\n\t\t\"hasLogicalIssues\": {\n\t\t\t\"type\": \"boolean\",\n\t\t\t\"description\": \"Whether logical issues were detected\"\n\t\t}\n\t},\n\t\"required\": [\"overallRiskScore\", \"contradictions\", \"hasLogicalIssues\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "c10bdd5d-6c19-4391-9e23-c1d20372a665",
      "name": "Historical Document Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -464,
        880
      ],
      "parameters": {
        "mode": "insert",
        "memoryKey": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Workflow Configuration').item.json.vectorStoreMemoryId }}"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "ad259e05-6c11-4f12-8655-85281be01528",
      "name": "OpenAI Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        -496,
        1104
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "56e6fdfd-2ac7-4467-95d9-326f36634a71",
      "name": "Document Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -368,
        1104
      ],
      "parameters": {
        "options": {},
        "jsonData": "={{ $json.text }}",
        "jsonMode": "expressionData",
        "textSplittingMode": "custom"
      },
      "typeVersion": 1.1
    },
    {
      "id": "a9394d66-827a-485c-9ddf-f27ee6b7930d",
      "name": "Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        -288,
        1312
      ],
      "parameters": {
        "options": {},
        "chunkOverlap": 200
      },
      "typeVersion": 1
    },
    {
      "id": "0f9c1699-2e8d-4683-8ac1-5feae51d02c8",
      "name": "Entity Enrichment Tool",
      "type": "@n8n/n8n-nodes-langchain.toolCode",
      "position": [
        688,
        464
      ],
      "parameters": {
        "jsCode": "// Entity Enrichment Tool\n// Enriches extracted entities by querying internal systems and external registries\n\nconst query = $fromAI('query', 'The entity name or identifier to enrich');\n\n// Parse the query to extract entity information\nconst entityName = query.trim();\n\nif (!entityName) {\n  return 'Error: No entity name provided for enrichment';\n}\n\n// Placeholder for internal database query\nconst internalDbUrl = '<__PLACEHOLDER_VALUE__INTERNAL_DB_API_ENDPOINT__>';\nconst internalDbApiKey = '<__PLACEHOLDER_VALUE__INTERNAL_DB_API_KEY__>';\n\n// Placeholder for external registry API\nconst externalRegistryUrl = '<__PLACEHOLDER_VALUE__EXTERNAL_REGISTRY_API_ENDPOINT__>';\nconst externalRegistryApiKey = '<__PLACEHOLDER_VALUE__EXTERNAL_REGISTRY_API_KEY__>';\n\n// Simulate entity enrichment\n// In production, this would:\n// 1. Query internal customer/entity database\n// 2. Query external registries (company registries, sanctions lists, etc.)\n// 3. Query credit bureaus or risk databases\n// 4. Aggregate and normalize the data\n\nconst enrichedData = {\n  entityName: entityName,\n  entityType: 'organization',\n  registrationNumber: 'REG-' + Math.random().toString(36).substr(2, 9).toUpperCase(),\n  registrationDate: '2015-03-15',\n  registrationCountry: 'US',\n  status: 'active',\n  industry: 'Financial Services',\n  riskRating: 'medium',\n  sanctionsMatch: false,\n  pepMatch: false,\n  adverseMediaCount: 0,\n  creditScore: 720,\n  yearsInBusiness: new Date().getFullYear() - 2015,\n  verificationStatus: 'verified',\n  lastUpdated: new Date().toISOString(),\n  dataSources: ['internal_db', 'company_registry', 'credit_bureau'],\n  additionalInfo: {\n    address: '123 Business St, New York, NY 10001',\n    phone: '+1234567890',\n    website: 'https://example.com',\n    employees: '50-100'\n  }\n};\n\n// Return enriched data as formatted string\nreturn `Entity Enrichment Results for \"${entityName}\":\n\nEntity Type: ${enrichedData.entityType}\nRegistration Number: ${enrichedData.registrationNumber}\nRegistration Date: ${enrichedData.registrationDate}\nCountry: ${enrichedData.registrationCountry}\nStatus: ${enrichedData.status}\nIndustry: ${enrichedData.industry}\nRisk Rating: ${enrichedData.riskRating}\nSanctions Match: ${enrichedData.sanctionsMatch ? 'YES - ALERT' : 'No'}\nPEP Match: ${enrichedData.pepMatch ? 'YES - ALERT' : 'No'}\nAdverse Media: ${enrichedData.adverseMediaCount} articles found\nCredit Score: ${enrichedData.creditScore}\nYears in Business: ${enrichedData.yearsInBusiness}\nVerification Status: ${enrichedData.verificationStatus}\n\nAdditional Information:\n- Address: ${enrichedData.additionalInfo.address}\n- Phone: ${enrichedData.additionalInfo.phone}\n- Website: ${enrichedData.additionalInfo.website}\n- Employees: ${enrichedData.additionalInfo.employees}\n\nData Sources: ${enrichedData.dataSources.join(', ')}\nLast Updated: ${enrichedData.lastUpdated}\n\nNote: This is simulated enrichment data. In production, replace placeholders with actual API endpoints and keys.`;",
        "description": "Enriches extracted entities by querying internal systems and external registries for additional information"
      },
      "typeVersion": 1.3
    },
    {
      "id": "f06b1355-4a70-4a8a-b222-48efc30abb6a",
      "name": "Entity Enrichment Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        608,
        240
      ],
      "parameters": {
        "text": "={{ JSON.stringify($json) }}",
        "options": {
          "systemMessage": "You are an entity enrichment specialist. Use the enrichEntity tool to gather additional information about entities extracted from the document.\n\nFor each entity (person, organization, location):\n1. Call the enrichEntity tool with the entity name and type\n2. Gather additional context from internal systems and external registries\n3. Identify any red flags or compliance issues\n4. Check against sanctions lists and watchlists\n5. Verify entity legitimacy and reputation\n\nReturn enriched entity data with:\n- entityName: Original entity name\n- entityType: Type of entity\n- verified: Whether entity was verified\n- riskLevel: Risk level (low, medium, high, critical)\n- additionalInfo: Enriched information gathered\n- flags: Array of any red flags or concerns\n- sources: Data sources consulted"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "4296f718-4fba-4a97-9b72-f603238f3a18",
      "name": "OpenAI Model - Enrichment",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        560,
        464
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c80260c2-2606-4c9e-a234-4bd933b9be5d",
      "name": "Enrichment Schema Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        816,
        464
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"enrichedEntities\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"description\": \"Array of enriched entity information\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"object\",\n\t\t\t\t\"properties\": {\n\t\t\t\t\t\"entityName\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Name of the entity\"\n\t\t\t\t\t},\n\t\t\t\t\t\"entityType\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Type of entity (person, organization, location, etc.)\"\n\t\t\t\t\t},\n\t\t\t\t\t\"verified\": {\n\t\t\t\t\t\t\"type\": \"boolean\",\n\t\t\t\t\t\t\"description\": \"Whether the entity has been verified\"\n\t\t\t\t\t},\n\t\t\t\t\t\"riskLevel\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Risk level associated with the entity\"\n\t\t\t\t\t},\n\t\t\t\t\t\"additionalInfo\": {\n\t\t\t\t\t\t\"type\": \"string\",\n\t\t\t\t\t\t\"description\": \"Additional information about the entity\"\n\t\t\t\t\t},\n\t\t\t\t\t\"flags\": {\n\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\"description\": \"Flags or warnings associated with the entity\",\n\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\t\"sources\": {\n\t\t\t\t\t\t\"type\": \"array\",\n\t\t\t\t\t\t\"description\": \"Sources used for entity enrichment\",\n\t\t\t\t\t\t\"items\": {\n\t\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t\"required\": [\"entityName\", \"entityType\", \"verified\", \"riskLevel\"]\n\t\t\t}\n\t\t},\n\t\t\"overallEnrichmentScore\": {\n\t\t\t\"type\": \"number\",\n\t\t\t\"description\": \"Overall enrichment score for all entities\"\n\t\t}\n\t},\n\t\"required\": [\"enrichedEntities\", \"overallEnrichmentScore\"]\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "954e537d-00a2-4ac2-8119-dade90eb2007",
      "name": "Calculate Risk Score",
      "type": "n8n-nodes-base.code",
      "position": [
        1024,
        240
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Calculate Multi-Factor Risk Score\n// Combines analysis results from metadata, forgery, semantic, pattern, and enrichment analyses\n\nconst item = $input.item.json;\n\n// Extract risk scores from different analysis components\nconst metadataAnalysis = item.metadataAnalysis || {};\nconst forgeryAnalysis = item.forgeryAnalysis || {};\nconst semanticAnalysis = item.semanticAnalysis || {};\nconst patternAnalysis = item.patternAnalysis || {};\nconst enrichmentAnalysis = item.enrichmentAnalysis || {};\n\n// Define weights for each analysis component\nconst weights = {\n  forgery: 0.35,      // Forgery detection is highest priority\n  semantic: 0.25,     // Semantic contradictions are critical\n  pattern: 0.20,      // Historical patterns provide context\n  enrichment: 0.15,   // Entity enrichment adds validation\n  metadata: 0.05      // Metadata provides baseline info\n};\n\n// Extract individual risk scores (0-100 scale)\nconst forgeryScore = forgeryAnalysis.overallRiskScore || 0;\nconst semanticScore = semanticAnalysis.overallRiskScore || 0;\nconst patternScore = patternAnalysis.overallRiskScore || 0;\nconst enrichmentScore = enrichmentAnalysis.overallRiskScore || 0;\nconst metadataScore = metadataAnalysis.riskScore || 0;\n\n// Calculate weighted risk score\nconst weightedRiskScore = (\n  (forgeryScore * weights.forgery) +\n  (semanticScore * weights.semantic) +\n  (patternScore * weights.pattern) +\n  (enrichmentScore * weights.enrichment) +\n  (metadataScore * weights.metadata)\n);\n\n// Extract confidence scores from each analysis\nconst forgeryConfidence = forgeryAnalysis.averageConfidence || 70;\nconst semanticConfidence = semanticAnalysis.averageConfidence || 70;\nconst patternConfidence = patternAnalysis.averageConfidence || 70;\nconst enrichmentConfidence = enrichmentAnalysis.averageConfidence || 70;\nconst metadataConfidence = metadataAnalysis.confidence || 70;\n\n// Calculate overall confidence (weighted average)\nconst overallConfidence = (\n  (forgeryConfidence * weights.forgery) +\n  (semanticConfidence * weights.semantic) +\n  (patternConfidence * weights.pattern) +\n  (enrichmentConfidence * weights.enrichment) +\n  (metadataConfidence * weights.metadata)\n);\n\n// Calculate confidence interval\nconst confidenceMargin = (100 - overallConfidence) / 2;\nconst confidenceInterval = {\n  lower: Math.max(0, weightedRiskScore - confidenceMargin),\n  upper: Math.min(100, weightedRiskScore + confidenceMargin)\n};\n\n// Generate explainable risk factors\nconst riskFactors = [];\n\n// Add forgery indicators\nif (forgeryAnalysis.indicators && forgeryAnalysis.indicators.length > 0) {\n  forgeryAnalysis.indicators.forEach(indicator => {\n    if (indicator.severity === 'high' || indicator.severity === 'critical') {\n      riskFactors.push({\n        category: 'Forgery Detection',\n        factor: indicator.indicator,\n        severity: indicator.severity,\n        impact: forgeryScore * weights.forgery,\n        description: indicator.description,\n        confidence: indicator.confidence\n      });\n    }\n  });\n}\n\n// Add semantic contradictions\nif (semanticAnalysis.contradictions && semanticAnalysis.contradictions.length > 0) {\n  semanticAnalysis.contradictions.forEach(contradiction => {\n    if (contradiction.severity === 'high' || contradiction.severity === 'critical') {\n      riskFactors.push({\n        category: 'Semantic Analysis',\n        factor: contradiction.type,\n        severity: contradiction.severity,\n        impact: semanticScore * weights.semantic,\n        description: contradiction.description,\n        confidence: contradiction.confidence\n      });\n    }\n  });\n}\n\n// Add historical pattern matches\nif (patternAnalysis.patterns && patternAnalysis.patterns.length > 0) {\n  patternAnalysis.patterns.forEach(pattern => {\n    if (pattern.similarity > 70) {\n      riskFactors.push({\n        category: 'Historical Patterns',\n        factor: pattern.patternType,\n        severity: pattern.similarity > 90 ? 'critical' : 'high',\n        impact: patternScore * weights.pattern,\n        description: pattern.description,\n        confidence: pattern.similarity\n      });\n    }\n  });\n}\n\n// Add enrichment findings\nif (enrichmentAnalysis.riskIndicators && enrichmentAnalysis.riskIndicators.length > 0) {\n  enrichmentAnalysis.riskIndicators.forEach(indicator => {\n    riskFactors.push({\n      category: 'Entity Enrichment',\n      factor: indicator.type,\n      severity: indicator.severity,\n      impact: enrichmentScore * weights.enrichment,\n      description: indicator.description,\n      confidence: indicator.confidence || 70\n    });\n  });\n}\n\n// Sort risk factors by impact (descending)\nriskFactors.sort((a, b) => b.impact - a.impact);\n\n// Determine risk level\nlet riskLevel = 'low';\nlet recommendation = 'Document appears legitimate. Proceed with standard processing.';\n\nif (weightedRiskScore >= 90) {\n  riskLevel = 'critical';\n  recommendation = 'CRITICAL RISK: Document shows multiple severe fraud indicators. Immediate security team review required. Do not process.';\n} else if (weightedRiskScore >= 70) {\n  riskLevel = 'high';\n  recommendation = 'HIGH RISK: Document contains significant fraud indicators. Mandatory compliance team review before processing.';\n} else if (weightedRiskScore >= 30) {\n  riskLevel = 'medium';\n  recommendation = 'MEDIUM RISK: Document has some concerning elements. Recommend additional verification before processing.';\n}\n\n// Generate summary statistics\nconst summary = {\n  totalIndicators: riskFactors.length,\n  criticalIndicators: riskFactors.filter(f => f.severity === 'critical').length,\n  highIndicators: riskFactors.filter(f => f.severity === 'high').length,\n  mediumIndicators: riskFactors.filter(f => f.severity === 'medium').length,\n  averageConfidence: overallConfidence,\n  analysisTimestamp: new Date().toISOString()\n};\n\n// Return comprehensive risk assessment\nreturn {\n  json: {\n    riskScore: Math.round(weightedRiskScore * 100) / 100,\n    riskLevel: riskLevel,\n    confidence: Math.round(overallConfidence * 100) / 100,\n    confidenceInterval: {\n      lower: Math.round(confidenceInterval.lower * 100) / 100,\n      upper: Math.round(confidenceInterval.upper * 100) / 100\n    },\n    riskFactors: riskFactors,\n    recommendation: recommendation,\n    summary: summary,\n    componentScores: {\n      forgery: Math.round(forgeryScore * 100) / 100,\n      semantic: Math.round(semanticScore * 100) / 100,\n      pattern: Math.round(patternScore * 100) / 100,\n      enrichment: Math.round(enrichmentScore * 100) / 100,\n      metadata: Math.round(metadataScore * 100) / 100\n    },\n    weights: weights,\n    // Preserve original analysis data\n    metadataAnalysis: metadataAnalysis,\n    forgeryAnalysis: forgeryAnalysis,\n    semanticAnalysis: semanticAnalysis,\n    patternAnalysis: patternAnalysis,\n    enrichmentAnalysis: enrichmentAnalysis\n  }\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "c452abe3-a3a1-4243-bd43-5822b49afc5f",
      "name": "Route by Risk Level",
      "type": "n8n-nodes-base.switch",
      "position": [
        1248,
        208
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Low Risk",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    },
                    "leftValue": "={{ $json.riskScore }}",
                    "rightValue": "={{ $('Workflow Configuration').item.json.riskThresholdLow }}"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Medium Risk",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    },
                    "leftValue": "={{ $json.riskScore }}",
                    "rightValue": "={{ $('Workflow Configuration').item.json.riskThresholdHigh }}"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "High Risk",
              "conditions": {
                "options": {
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "operator": {
                      "type": "number",
                      "operation": "lt"
                    },
                    "leftValue": "={{ $json.riskScore }}",
                    "rightValue": "={{ $('Workflow Configuration').item.json.riskThresholdCritical }}"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {
          "ignoreCase": true,
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Critical Risk"
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "375957af-da0a-41e2-957c-0aa1afc8920b",
      "name": "Store Low Risk Documents",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1920,
        48
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "<__PLACEHOLDER_VALUE__Low_Risk_Documents_Table__>"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "metadata": "={{ $json.metadata }}",
            "riskScore": "={{ $json.riskScore }}",
            "timestamp": "={{ $json.timestamp }}",
            "documentHash": "={{ $json.documentHash }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "834d44e7-7ed4-420c-abdc-c038296be72d",
      "name": "Wait for Human Review",
      "type": "n8n-nodes-base.wait",
      "position": [
        1696,
        240
      ],
      "parameters": {
        "resume": "webhook",
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "1e20acce-bead-4120-96a1-c56efdb8dee2",
      "name": "Notify Compliance Team",
      "type": "n8n-nodes-base.slack",
      "position": [
        1472,
        240
      ],
      "parameters": {
        "text": "=Document requires human review\n\nDocument Hash: {{ $json.documentHash }}\nRisk Score: {{ $json.riskScore }}\nRisk Level: Medium\n\nPlease review and approve/reject via the review link.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Compliance_Channel_ID__>"
        },
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "88b77e33-8f0a-4d2f-ac2c-c0a21972d119",
      "name": "Store High Risk Documents",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1920,
        240
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "<__PLACEHOLDER_VALUE__High_Risk_Documents_Table__>"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "riskScore": "={{ $json.riskScore }}",
            "timestamp": "={{ $json.timestamp }}",
            "reviewedBy": "={{ $json.reviewedBy }}",
            "documentHash": "={{ $json.documentHash }}",
            "reviewDecision": "={{ $json.reviewDecision }}"
          },
          "schema": [
            {
              "id": "documentHash",
              "required": false,
              "displayName": "documentHash",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "riskScore",
              "required": false,
              "displayName": "riskScore",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "reviewDecision",
              "required": false,
              "displayName": "reviewDecision",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "reviewedBy",
              "required": false,
              "displayName": "reviewedBy",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "timestamp",
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "documentHash",
            "riskScore",
            "reviewDecision",
            "reviewedBy",
            "timestamp"
          ]
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "64ba3559-b81d-4ef8-9045-c858ffcbbd06",
      "name": "Store Critical Risk Documents",
      "type": "n8n-nodes-base.postgres",
      "position": [
        1920,
        432
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "<__PLACEHOLDER_VALUE__Critical_Risk_Documents_Table__>"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "riskScore": "={{ $json.riskScore }}",
            "timestamp": "={{ $json.timestamp }}",
            "documentHash": "={{ $json.documentHash }}",
            "allAnalysisResults": "={{ $json.allAnalysisResults }}"
          },
          "mappingMode": "defineBelow"
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "07bed5ae-e7fa-4881-a787-41a67c0f1ea5",
      "name": "Alert Security Team",
      "type": "n8n-nodes-base.slack",
      "position": [
        1696,
        432
      ],
      "parameters": {
        "text": "=CRITICAL SECURITY ALERT: High-risk document detected\n\nDocument Hash: {{ $json.documentHash }}\nRisk Score: {{ $json.riskScore }}\nRisk Level: CRITICAL\n\nImmediate investigation required. Document has been quarantined.",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "<__PLACEHOLDER_VALUE__Security_Alert_Channel_ID__>"
        },
        "otherOptions": {
          "mrkdwn": true,
          "link_names": true
        },
        "authentication": "oAuth2"
      },
      "credentials": {
        "slackOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "1ec628ce-e55f-447e-906d-91f695c8b7f6",
      "name": "Log Audit Trail",
      "type": "n8n-nodes-base.postgres",
      "position": [
        2144,
        240
      ],
      "parameters": {
        "table": {
          "__rl": true,
          "mode": "name",
          "value": "<__PLACEHOLDER_VALUE__Audit_Trail_Table__>"
        },
        "schema": {
          "__rl": true,
          "mode": "list",
          "value": "public"
        },
        "columns": {
          "value": {
            "userId": "={{ $json.userId }}",
            "riskLevel": "={{ $json.riskLevel }}",
            "riskScore": "={{ $json.riskScore }}",
            "documentHash": "={{ $json.documentHash }}",
            "allAnalysisData": "={{ $json.allAnalysisData }}",
            "processingDuration": "={{ $json.processingDuration }}",
            "processingTimestamp": "={{ $json.processingTimestamp }}"
          },
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": []
        },
        "options": {}
      },
      "typeVersion": 2.6
    },
    {
      "id": "2f891122-ec1d-4e6a-8f74-b6f8b0899b40",
      "name": "Generate Cryptographic Proof",
      "type": "n8n-nodes-base.crypto",
      "position": [
        2368,
        240
      ],
      "parameters": {
        "value": "={{ JSON.stringify($json) }}",
        "action": "sign",
        "encoding": "base64",
        "algorithm": "RSA-SHA256",
        "privateKey": "YOUR_CREDENTIAL_HERE",
        "dataPropertyName": "cryptographicProof"
      },
      "typeVersion": 1
    },
    {
      "id": "5f0236ed-ddca-4fc4-b054-223ec956bf2d",
      "name": "Return Processing Result",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        2816,
        240
      ],
      "parameters": {
        "options": {
          "responseCode": 200
        },
        "respondWith": "json",
        "enableResponseOutput": true
      },
      "typeVersion": 1.5
    },
    {
      "id": "7cd4893c-7d6e-4f70-a0d7-4e817d0641cf",
      "name": "Prepare Response Data",
      "type": "n8n-nodes-base.set",
      "position": [
        2592,
        240
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "status",
              "type": "string",
              "value": "processed"
            },
            {
              "id": "id-2",
              "name": "documentHash",
              "type": "string",
              "value": "={{ $json.documentHash }}"
            },
            {
              "id": "id-3",
              "name": "riskScore",
              "type": "number",
              "value": "={{ $json.riskScore }}"
            },
            {
              "id": "id-4",
              "name": "riskLevel",
              "type": "string",
              "value": "={{ $json.riskLevel }}"
            },
            {
              "id": "id-5",
              "name": "processingTimestamp",
              "type": "string",
              "value": "={{ $now.toISO() }}"
            },
            {
              "id": "id-6",
              "name": "cryptographicProof",
              "type": "string",
              "value": "={{ $json.cryptographicProof }}"
            },
            {
              "id": "id-7",
              "name": "auditTrailId",
              "type": "string",
              "value": "={{ $json.auditId }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "b3f18239-00e1-4b13-b552-7f6f3908b8de",
      "name": "Historical Pattern Comparison Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -48,
        1288
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "You are a historical pattern analysis expert comparing current documents against historical fraud patterns.\n\nAnalyze the current document against the vector store of historical documents to identify:\n\n1. Similar fraud patterns from past cases\n2. Recurring suspicious entities or organizations\n3. Common forgery techniques previously detected\n4. Geographic or temporal fraud clusters\n5. Behavioral patterns of known fraudsters\n\nFor each pattern match:\n- patternType: Type of historical pattern\n- similarity: Similarity score 0-100\n- historicalCases: Number of similar historical cases\n- description: What pattern was matched\n- riskImplication: Why this pattern is concerning\n\nReturn structured analysis with overall historical risk score (0-100)."
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "6debc39d-3a78-4494-8a94-4aaa0b248fee",
      "name": "OpenAI Model - Pattern",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -40,
        1512
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "cd25a50a-5b5a-45ab-994c-1a08bf17df54",
      "name": "Pattern Analysis Schema",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        88,
        1512
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"overallRiskScore\": {\n\t\t\t\"type\": \"number\"\n\t\t},\n\t\t\"patterns\": {\n\t\t\t\"type\": \"array\",\n\t\t\t\"items\": {\n\t\t\t\t\"type\": \"object\",\n\t\t\t\t\"properties\": {\n\t\t\t\t\t\"patternType\": {\n\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t},\n\t\t\t\t\t\"similarity\": {\n\t\t\t\t\t\t\"type\": \"number\"\n\t\t\t\t\t},\n\t\t\t\t\t\"historicalCases\": {\n\t\t\t\t\t\t\"type\": \"number\"\n\t\t\t\t\t},\n\t\t\t\t\t\"description\": {\n\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t},\n\t\t\t\t\t\"riskImplication\": {\n\t\t\t\t\t\t\"type\": \"string\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t\"isKnownPattern\": {\n\t\t\t\"type\": \"boolean\"\n\t\t}\n\t}\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "b05a007c-a726-4a58-826f-c3457b00f184",
      "name": "Merge Analysis Results",
      "type": "n8n-nodes-base.merge",
      "position": [
        304,
        656
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "combineBy": "combineByPosition",
        "numberInputs": 4
      },
      "typeVersion": 3.2
    },
    {
      "id": "bd76ea5e-8b46-4592-95cf-47011a479238",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        16,
        -416
      ],
      "parameters": {
        "color": 6,
        "width": 528,
        "height": 320,
        "content": "## Prerequisites\nNVIDIA NIM API access, OpenAI API key (GPT-4), Anthropic Claude API key\n## Use Cases\nMulti-vendor proposal evaluation, regulatory compliance document review\n## Customization\nAdjust AI model parameters per analysis depth, modify recommendation scoring algorithms\n## Benefits\nProcesses multiple documents 90% faster than manual review, eliminates bias through multi-model "
      },
      "typeVersion": 1
    },
    {
      "id": "1ee81327-7383-416b-bcdb-9b43aa305fc3",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -624,
        -336
      ],
      "parameters": {
        "width": 560,
        "height": 208,
        "content": "## Setup Steps\n1. Configure NVIDIA NIM API credentials for creative content analysis\n2. Add OpenAI API key with GPT-4 access for strategic evaluation\n3. Connect Anthropic Claude API for technical assessment capabilities\n4. Set up Google Sheets integration with read/write permissions\n5. Configure Gmail OAuth2 credentials for automated report delivery\n6. Customize analysis prompts and recommendation thresholds "
      },
      "typeVersion": 1
    },
    {
      "id": "74975de4-ce2a-444c-80af-81cda863d81c",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1840,
        -352
      ],
      "parameters": {
        "width": 1152,
        "height": 224,
        "content": "## How It Works\nThis workflow automates intelligent document analysis by processing multiple uploaded files through parallel AI pipelines to extract insights, generate comparative analysis, and produce actionable recommendations delivered via email. Designed for business analysts, consultants, and researchers, it enables efficient synthesis of insights from diverse document types into strategic, data-driven conclusions. The workflow eliminates the manual effort of reviewing documents, identifying patterns, cross-referencing information, and formulating recommendations by orchestrating structured data extraction, routing content through specialized AI models (OpenAI and Claude), aggregating and validating results, and formatting professional-grade reports. End-to-end processing includes batch document ingestion, structured extraction, parallel AI analysis, comparative evaluation, recommendation generation, report formatting, and tracked delivery via Gmail."
      },
      "typeVersion": 1
    },
    {
      "id": "562cee0e-a81b-40c5-aeb5-ba8a37e843ab",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -592,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 1072,
        "height": 1760,
        "content": "## Parallel Multi-Pipeline AI Analysis\n**Why:** Routes documents through specialized AI processing streams\u2014creative evaluation (NVIDIA), strategic assessment (GPT-4), technical review (Claude)\u2014to capture comprehensive perspectives and domain-specific insights."
      },
      "typeVersion": 1
    },
    {
      "id": "46f7e31b-04c8-47a9-a1c8-834e1a6693b1",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2000,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 1376,
        "height": 800,
        "content": "## Batch Document Ingestion & Classification\n**Why:** Processes multiple document formats simultaneously and categorizes content by type, enabling specialized analysis pathways and efficient resource allocation across AI models."
      },
      "typeVersion": 1
    },
    {
      "id": "e6108a11-0082-4559-8302-3604a86ccde4",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        496,
        -64
      ],
      "parameters": {
        "color": 7,
        "width": 832,
        "height": 752,
        "content": "\n## Cross-Reference & Recommendation Synthesis\n**Why:** Aggregates findings from all analysis pipelines, identifies patterns and discrepancies, generates prioritized actionable recommendations based on consensus insights."
      },
      "typeVersion": 1
    },
    {
      "id": "49d0fe11-ea2c-49d9-942d-f23e59d5ba1c",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        -48
      ],
      "parameters": {
        "color": 7,
        "width": 1744,
        "height": 736,
        "content": "## Report Generation & Automated Distribution\n**Why:** Compiles structured reports with executive summaries, detailed findings, and recommendations, then delivers via Gmail with tracking for accountability."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "8c5457fb-5b75-446b-8824-5afc1f8c2024",
  "connections": {
    "Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Document Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Document Loader": {
      "ai_document": [
        [
          {
            "node": "Historical Document Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Log Audit Trail": {
      "main": [
        [
          {
            "node": "Generate Cryptographic Proof",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Historical Document Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Alert Security Team": {
      "main": [
        [
          {
            "node": "Store Critical Risk Documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by Risk Level": {
      "main": [
        [
          {
            "node": "Store Low Risk Documents",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Notify Compliance Team",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Alert Security Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Risk Score": {
      "main": [
        [
          {
            "node": "Route by Risk Level",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Text from PDF": {
      "main": [
        [
          {
            "node": "Merge Extracted Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Response Data": {
      "main": [
        [
          {
            "node": "Return Processing Result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Human Review": {
      "main": [
        [
          {
            "node": "Store High Risk Documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Entity Enrichment Tool": {
      "ai_tool": [
        [
          {
            "node": "Entity Enrichment Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Generate Document Hash": {
      "main": [
        [
          {
            "node": "Route by Document Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Analysis Results": {
      "main": [
        [
          {
            "node": "Entity Enrichment Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Metadata Schema Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Metadata Extraction Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Notify Compliance Team": {
      "main": [
        [
          {
            "node": "Wait for Human Review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Forgery": {
      "ai_languageModel": [
        [
          {
            "node": "Forgery Detection Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Pattern": {
      "ai_languageModel": [
        [
          {
            "node": "Historical Pattern Comparison Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Route by Document Type": {
      "main": [
        [
          {
            "node": "Extract Text from PDF",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "OCR Processing for Images",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Extract from Office Documents",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Workflow Configuration": {
      "main": [
        [
          {
            "node": "Generate Document Hash",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Entity Enrichment Agent": {
      "main": [
        [
          {
            "node": "Calculate Risk Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Forgery Analysis Schema": {
      "ai_outputParser": [
        [
          {
            "node": "Forgery Detection Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Forgery Detection Agent": {
      "main": [
        [
          {
            "node": "Merge Analysis Results",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Extracted Content": {
      "main": [
        [
          {
            "node": "Metadata Extraction Agent",
            "type": "main",
            "index": 0
          },
          {
            "node": "Forgery Detection Agent",
            "type": "main",
            "index": 0
          },
          {
            "node": "Semantic Contradiction Detector",
            "type": "main",
            "index": 0
          },
          {
            "node": "Historical Document Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Metadata": {
      "ai_languageModel": [
        [
          {
            "node": "Metadata Extraction Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Model - Semantic": {
      "ai_languageModel": [
        [
          {
            "node": "Semantic Contradiction Detector",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Pattern Analysis Schema": {
      "ai_outputParser": [
        [
          {
            "node": "Historical Pattern Comparison Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Enrichment Schema Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Entity Enrichment Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Store Low Risk Documents": {
      "main": [
        [
          {
            "node": "Log Audit Trail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Metadata Extraction Agent": {
      "main": [
        [
          {
            "node": "Merge Analysis Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OCR Processing for Images": {
      "main": [
        [
          {
            "node": "Merge Extracted Content",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "OpenAI Model - Enrichment": {
      "ai_languageModel": [
        [
          {
            "node": "Entity Enrichment Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Store High Risk Documents": {
      "main": [
        [
          {
            "node": "Log Audit Trail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Document Ingestion Webhook": {
      "main": [
        [
          {
            "node": "Workflow Configuration",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Contradiction Schema Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Semantic Contradiction Detector",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Generate Cryptographic Proof": {
      "main": [
        [
          {
            "node": "Prepare Response Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from Office Documents": {
      "main": [
        [
          {
            "node": "Merge Extracted Content",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Store Critical Risk Documents": {
      "main": [
        [
          {
            "node": "Log Audit Trail",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Semantic Contradiction Detector": {
      "main": [
        [
          {
            "node": "Merge Analysis Results",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Historical Document Vector Store": {
      "main": [
        [
          {
            "node": "Historical Pattern Comparison Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Historical Pattern Comparison Agent": {
      "main": [
        [
          {
            "node": "Merge Analysis Results",
            "type": "main",
            "index": 3
          }
        ]
      ]
    }
  }
}