{
  "id": "WVxaI3QS8NkVm2Pc",
  "name": "2. Detecting Financial Distress & Credit Risk with Bright Data & n8n",
  "tags": [],
  "nodes": [
    {
      "id": "3b9a501c-5f1e-4d70-8764-d81b4aebbd67",
      "name": "Run Financial Risk Scan",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        64,
        1392
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "abc8a0a1-dcf6-40e6-a2c7-149e50e27821",
      "name": "Set Company & Risk Parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        288,
        1392
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "32c706ed-8497-43f2-9fd9-11f47da3cced",
              "name": "company",
              "type": "string",
              "value": "Wirecard AG"
            },
            {
              "id": "d2f402fd-3861-4e5d-b325-dabfd079d0e0",
              "name": "country",
              "type": "string",
              "value": "Germany"
            },
            {
              "id": "63a628bc-da00-4354-b487-27b78be3e836",
              "name": "riskIndicators",
              "type": "array",
              "value": "[\"audit fraud\", \"insolvency\", \"regulatory investigation\"]"
            },
            {
              "id": "31fd3091-3dc7-45b5-95ed-98547fd3cd25",
              "name": "batchMode",
              "type": "boolean",
              "value": true
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "fe04ca3e-f104-490a-9e2c-7be918d677be",
      "name": "Validate Company Input",
      "type": "n8n-nodes-base.if",
      "position": [
        912,
        1392
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "781e4035-ef6f-4006-bc46-55c0768bcfdb",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.company }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "a20bf44f-7fae-4696-b40e-f17886f2acc0",
      "name": "Scrape Financial Filings",
      "type": "@brightdata/n8n-nodes-brightdata.brightData",
      "onError": "continueErrorOutput",
      "position": [
        1216,
        1120
      ],
      "parameters": {
        "url": "=https://www.google.com/search?q={{encodeURIComponent($json.company)}}%20financial%20filings",
        "zone": {
          "__rl": true,
          "mode": "list",
          "value": "n8n_unlocker"
        },
        "format": "json",
        "country": {
          "__rl": true,
          "mode": "list",
          "value": "us"
        },
        "requestOptions": {}
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "6f4f79c4-1a34-47eb-bd5f-9a930cc77748",
      "name": "Scrape Insolvency Register",
      "type": "@brightdata/n8n-nodes-brightdata.brightData",
      "onError": "continueErrorOutput",
      "position": [
        1216,
        1376
      ],
      "parameters": {
        "url": "=https://www.google.com/search?q={{encodeURIComponent($json.company)}}%20insolvency%20register",
        "zone": {
          "__rl": true,
          "mode": "list",
          "value": "n8n_unlocker"
        },
        "format": "json",
        "country": {
          "__rl": true,
          "mode": "list",
          "value": "de",
          "cachedResultName": "de"
        },
        "requestOptions": {}
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "056074c1-b2b0-497a-bb85-319dfe4071fc",
      "name": "Scrape Financial News",
      "type": "@brightdata/n8n-nodes-brightdata.brightData",
      "onError": "continueErrorOutput",
      "position": [
        1216,
        1648
      ],
      "parameters": {
        "url": "=https://www.google.com/search?q={{encodeURIComponent($json.company)}}%20financial%20news",
        "zone": {
          "__rl": true,
          "mode": "list",
          "value": "n8n_unlocker"
        },
        "format": "json",
        "country": {
          "__rl": true,
          "mode": "list",
          "value": "us"
        },
        "requestOptions": {}
      },
      "retryOnFail": true,
      "typeVersion": 1
    },
    {
      "id": "0158d04b-cc43-4a20-bb9b-23e34043ce48",
      "name": "Log Scraping Error",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1488,
        1872
      ],
      "parameters": {
        "columns": {
          "value": {
            "hasError": "True",
            "errorCode": "={{$json.statusCode || $json.code || 'N/A'}}",
            "timestamp": "={{ $now }}",
            "errorSource": "Bright Data Scraper",
            "errorMessage": "={{$json.error?.message || $json.message || 'Unknown Bright Data Error'}}"
          },
          "schema": [
            {
              "id": "errorSource",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "errorSource",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "errorMessage",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "errorMessage",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "errorCode",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "errorCode",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "hasError",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "hasError",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 299945015,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-VJbc3CQi7F9ROjcQnfeVmtM6pQ0-MgCKzpXI_HzqCI/edit#gid=299945015",
          "cachedResultName": "BD log error"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE/edit?usp=drivesdk",
          "cachedResultName": "2. Bright Data Financial Distress & Credit Risk Intelligence Engine"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "12c21197-6cf8-40a9-88a8-7192bcdc3aea",
      "name": "Detect Filing Distress Signals",
      "type": "n8n-nodes-base.code",
      "position": [
        1568,
        1104
      ],
      "parameters": {
        "jsCode": "// Get HTML safely from Bright Data node\nconst html =\n  $input.first().json.body ||\n  $input.first().json.data ||\n  \"\";\n\nconst text = html.toLowerCase();\n\n// Financial filings distress keywords\nconst keywords = [\n  \"bankruptcy\",\n  \"chapter 7\",\n  \"chapter 11\",\n  \"chapter 15\",\n  \"liquidation\",\n  \"restructuring\",\n  \"default\",\n  \"going concern\",\n  \"credit downgrade\"\n];\n\nlet found = [];\n\nfor (const word of keywords) {\n  if (text.includes(word)) {\n    found.push(word);\n  }\n}\n\nreturn [\n  {\n    source: \"financial_filings\",\n    distressSignals: found\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "cf2833e9-35a2-4ffd-86e0-d3aaf3fddaf5",
      "name": "Detect Insolvency Signals",
      "type": "n8n-nodes-base.code",
      "position": [
        1568,
        1360
      ],
      "parameters": {
        "jsCode": "const html =\n  $input.first().json.body ||\n  $input.first().json.data ||\n  \"\";\n\nconst text = html.toLowerCase();\n\n// Insolvency register focused keywords\nconst keywords = [\n  \"insolvency\",\n  \"bankruptcy\",\n  \"liquidation\",\n  \"administrator\",\n  \"receivership\",\n  \"dissolution\",\n  \"court filing\"\n];\n\nlet found = [];\n\nfor (const word of keywords) {\n  if (text.includes(word)) {\n    found.push(word);\n  }\n}\n\nreturn [\n  {\n    source: \"insolvency_register\",\n    distressSignals: found\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "d3028be5-0062-425e-8ba3-9f26acfc7eca",
      "name": "Detect News Distress Signals",
      "type": "n8n-nodes-base.code",
      "position": [
        1568,
        1632
      ],
      "parameters": {
        "jsCode": "const html =\n  $input.first().json.body ||\n  $input.first().json.data ||\n  \"\";\n\nconst text = html.toLowerCase();\n\n// Financial news distress keywords\nconst keywords = [\n  \"bankruptcy\",\n  \"insolvency\",\n  \"financial distress\",\n  \"missed payment\",\n  \"default\",\n  \"debt restructuring\",\n  \"credit downgrade\",\n  \"chapter 11\"\n];\n\nlet found = [];\n\nfor (const word of keywords) {\n  if (text.includes(word)) {\n    found.push(word);\n  }\n}\n\nreturn [\n  {\n    source: \"financial_news\",\n    distressSignals: found\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "a6068d94-af8f-4b7d-b682-ca9c625f8390",
      "name": "Merge All Distress Signals",
      "type": "n8n-nodes-base.merge",
      "position": [
        1872,
        1344
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3.2
    },
    {
      "id": "7d61d212-525d-4fab-93a0-d66edc88e59a",
      "name": "Categorize & Normalize Signals",
      "type": "n8n-nodes-base.code",
      "position": [
        2608,
        1360
      ],
      "parameters": {
        "jsCode": "// Collect all distress signals WITH source tracking\nlet allSignals = [];\nlet signalDetails = [];\n\n// Merge se multiple items aate hain\nfor (const item of $input.all()) {\n\n  const source = item.json.source || \"unknown\";\n\n  if (item.json.distressSignals) {\n\n    for (const signal of item.json.distressSignals) {\n\n      allSignals.push(signal);\n\n      signalDetails.push({\n        signal: signal,\n        source: source\n      });\n\n    }\n  }\n}\n\n// Remove duplicate signals (but keep detail list intact)\nallSignals = [...new Set(allSignals)];\n\n\n// Categorization buckets\nlet bankruptcy = [];\nlet insolvency = [];\nlet restructuring = [];\nlet filingIssues = [];\n\n// Categorize signals\nfor (const signal of allSignals) {\n\n  if (signal.includes(\"bankruptcy\") || signal.includes(\"chapter\")) {\n    bankruptcy.push(signal);\n  }\n\n  if (signal.includes(\"insolvency\") || signal.includes(\"administrator\")) {\n    insolvency.push(signal);\n  }\n\n  if (signal.includes(\"restructuring\") || signal.includes(\"liquidation\")) {\n    restructuring.push(signal);\n  }\n\n  if (signal.includes(\"default\") || signal.includes(\"late filing\")) {\n    filingIssues.push(signal);\n  }\n}\n\n\n// Return normalized + source-aware structure\nreturn [{\n  categorizedSignals: {\n    bankruptcySignals: bankruptcy,\n    insolvencySignals: insolvency,\n    restructuringSignals: restructuring,\n    filingIssueSignals: filingIssues\n  },\n  allSignals: allSignals,\n  signalSourceMap: signalDetails,\n  sourcesAnalyzed: [...new Set(signalDetails.map(s => s.source))]\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "4269f0c3-afac-4e52-af10-30e6f17da734",
      "name": "Prepare Signals for AI Analysis",
      "type": "n8n-nodes-base.set",
      "position": [
        2848,
        1360
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ebe066cb-31ec-4fe1-b22e-68894a7bd95f",
              "name": "company",
              "type": "string",
              "value": "={{ $('Set Company & Risk Parameters').first().json.company }}"
            },
            {
              "id": "7bdf8b01-4409-4437-8d16-3400e1daa1ae",
              "name": "country",
              "type": "string",
              "value": "={{ $('Set Company & Risk Parameters').first().json.country }}"
            },
            {
              "id": "9431d16f-5db8-4a00-b0c4-3f3275d009b6",
              "name": "distressSignals",
              "type": "array",
              "value": "={{ $json.allSignals }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "961b5b39-e67c-4eb2-86fe-941aa8abe12e",
      "name": "AI Financial Distress Classifier",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3088,
        1360
      ],
      "parameters": {
        "text": "=Analyze the following financial distress signals:\n\n{{ $json.distressSignals }}\n\nInstructions:\n- Base your decision ONLY on the provided signals.\n- If signals are weak or limited, assign LOW probability.\n- Be conservative in scoring.\n- Do not assume missing information.\n\nClassify:\n1. Primary distress type\n2. Probability (Low / Medium / High)\n3. Numerical risk score (0\u2013100)\n4. Short explanation (1\u20132 lines max)\n\nRespond ONLY in strictly valid JSON format:\n\n{\n  \"distressType\": \"\",\n  \"probability\": \"\",\n  \"riskScore\": 0,\n  \"explanation\": \"\"\n}\n",
        "options": {
          "systemMessage": "You are a financial credit risk classification assistant.\n\nYou MUST:\n- Return strictly valid JSON.\n- Return no extra text outside JSON.\n- Be conservative and risk-aware.\n- Never invent facts not present in the signals.\n\nIf signals are minimal, classify as LOW probability.\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "40ca3141-99de-4157-96be-642be38010ff",
      "name": "Validate AI Distress Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        3248,
        1632
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"distressType\": {\n      \"type\": \"string\",\n      \"description\": \"Primary financial distress classification\"\n    },\n    \"probability\": {\n      \"type\": \"string\",\n      \"enum\": [\"Low\", \"Medium\", \"High\"],\n      \"description\": \"Estimated probability of distress\"\n    },\n    \"riskScore\": {\n      \"type\": \"number\",\n      \"minimum\": 0,\n      \"maximum\": 100,\n      \"description\": \"Numerical financial risk score from 0 to 100\"\n    },\n    \"explanation\": {\n      \"type\": \"string\",\n      \"description\": \"Short explanation of the classification\"\n    }\n  },\n  \"required\": [\n    \"distressType\",\n    \"probability\",\n    \"riskScore\",\n    \"explanation\"\n  ],\n  \"additionalProperties\": false\n}\n"
      },
      "typeVersion": 1.3
    },
    {
      "id": "9e282fec-c212-4537-a5d6-6dc748539696",
      "name": "Apply Probability Weighting",
      "type": "n8n-nodes-base.code",
      "position": [
        3440,
        1360
      ],
      "parameters": {
        "jsCode": "// Get AI Agent output safely\nconst aiOutput = items[0].json.output || {};\n\n// Extract AI values\nconst distressType = aiOutput.distressType || \"\";\nconst probability = aiOutput.probability || \"Low\";\nconst aiRiskScore = aiOutput.riskScore || 0;\nconst explanation = aiOutput.explanation || \"\";\n\n// Start with AI risk score\nlet correlatedScore = aiRiskScore;\n\n// Probability weighting (conservative adjustment)\nif (probability === \"High\") {\n  correlatedScore += 10;\n} else if (probability === \"Medium\") {\n  correlatedScore += 5;\n} else {\n  correlatedScore += 0;\n}\n\n// Cap score between 0\u2013100\nif (correlatedScore > 100) correlatedScore = 100;\nif (correlatedScore < 0) correlatedScore = 0;\n\n// Return final structured output\nreturn [{\n  distressType,\n  probability,\n  aiRiskScore,\n  correlatedScore,\n  explanation\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "48d74bc4-633c-45bf-b769-4bfdf5778069",
      "name": "Apply Confidence Guardrails",
      "type": "n8n-nodes-base.code",
      "position": [
        3968,
        1360
      ],
      "parameters": {
        "jsCode": "// Get previous enriched output\nconst data = items[0].json;\n\n// Extract base values safely\nconst distressType = data.distressType || \"\";\nconst probability = data.probability || \"Low\";\nconst aiRiskScore = data.aiRiskScore || 0;\nconst correlatedScore = data.correlatedScore || 0;\nconst explanation = data.explanation || \"\";\nconst signalSourceMap = data.signalSourceMap || [];\n\n// Count unique sources (internal use only)\nlet uniqueSources = new Set();\n\nfor (const entry of signalSourceMap) {\n  if (entry.source) {\n    uniqueSources.add(entry.source);\n  }\n}\n\n// Confidence Guardrail Logic\nlet confidenceLevel = \"Low\";\nlet confidenceScore = 30;\n\n// Strong multi-source confirmation\nif (uniqueSources.size >= 3 && correlatedScore > 75) {\n  confidenceLevel = \"High\";\n  confidenceScore = 90;\n}\nelse if (uniqueSources.size === 2 && correlatedScore > 60) {\n  confidenceLevel = \"Medium\";\n  confidenceScore = 70;\n}\nelse if (uniqueSources.size === 1) {\n  confidenceLevel = \"Low\";\n  confidenceScore = 40;\n}\n\n// News-only penalty\nif (uniqueSources.size === 1 && uniqueSources.has(\"financial_news\")) {\n  confidenceScore -= 15;\n  confidenceLevel = \"Low\";\n}\n\n// Blend AI + correlation influence\nconfidenceScore = Math.round(\n  (confidenceScore * 0.7) + (aiRiskScore * 0.3)\n);\n\n// Cap between 0-100\nif (confidenceScore > 100) confidenceScore = 100;\nif (confidenceScore < 0) confidenceScore = 0;\n\n// Final structured return\nreturn [{\n  distressType,\n  probability,\n  aiRiskScore,\n  correlatedScore,\n  confidenceLevel,\n  confidenceScore,\n  explanation\n}];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "a1a0ffc3-b849-442e-931b-ea8054a3f63f",
      "name": "Generate Business Risk Decisions",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        4192,
        1360
      ],
      "parameters": {
        "text": "=You are given final structured financial distress analysis.\n\nDistress Type: {{ $json.distressType }}\nProbability: {{ $json.probability }}\nAI Risk Score: {{ $json.aiRiskScore }}\nCorrelated Score: {{ $json.correlatedScore }}\nConfidence Level: {{ $json.confidenceLevel }}\nConfidence Score: {{ $json.confidenceScore }}\nExplanation: {{ $json.explanation }}\n\nApply the following business rules:\n\nSUPPLIER MONITORING:\n- confidenceScore >= 70 \u2192 High Risk\n- 50\u201369 \u2192 Moderate Risk\n- below 50 \u2192 Low Risk\n\nONBOARDING DECISION:\n- confidenceScore >= 75 \u2192 Reject\n- 55\u201374 \u2192 Manual Review\n- below 55 \u2192 Approve\n\nPORTFOLIO EXPOSURE:\n- confidenceScore >= 70 \u2192 Critical\n- 50\u201369 \u2192 Elevated\n- below 50 \u2192 Normal\n\nReturn STRICTLY valid JSON.\nDo NOT wrap the result in quotes.\nDo NOT return a string.\nReturn a direct JSON object.\n\nOutput format:\n\n{\n  \"supplierMonitoring\": {\n    \"riskStatus\": \"\",\n    \"distressType\": \"\",\n    \"probability\": \"\",\n    \"confidenceScore\": 0\n  },\n  \"onboardingSnapshot\": {\n    \"approvalRecommendation\": \"\",\n    \"distressType\": \"\",\n    \"confidenceScore\": 0\n  },\n  \"portfolioExposure\": {\n    \"exposureCategory\": \"\",\n    \"portfolioRiskWeight\": 0\n  }\n}\n",
        "options": {
          "systemMessage": "You are a senior financial risk intelligence engine.\n\nYour task is to transform structured financial risk analysis data into three business-ready outputs:\n\n1) Supplier Monitoring Risk View\n2) Onboarding Credit Decision Snapshot\n3) Portfolio Exposure Feed\n\nRules:\n- Return STRICTLY valid JSON.\n- No extra commentary.\n- No markdown.\n- No explanations outside JSON.\n- Be conservative and risk-aware.\n- Base all decisions ONLY on provided scores and confidence values.\n- Do not invent data.\n- Maintain numerical integrity of provided scores.\n- Use structured decision logic.\n"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "39058a33-7e3d-471f-8bc7-13d6d12e04e9",
      "name": "Validate Business Decision Output",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        4336,
        1616
      ],
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"supplierMonitoring\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"riskStatus\": {\n          \"type\": \"string\",\n          \"enum\": [\"Low Risk\", \"Moderate Risk\", \"High Risk\"]\n        },\n        \"distressType\": {\n          \"type\": \"string\"\n        },\n        \"probability\": {\n          \"type\": \"string\",\n          \"enum\": [\"Low\", \"Medium\", \"High\"]\n        },\n        \"confidenceScore\": {\n          \"type\": \"number\",\n          \"minimum\": 0,\n          \"maximum\": 100\n        }\n      },\n      \"required\": [\n        \"riskStatus\",\n        \"distressType\",\n        \"probability\",\n        \"confidenceScore\"\n      ]\n    },\n    \"onboardingSnapshot\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"approvalRecommendation\": {\n          \"type\": \"string\",\n          \"enum\": [\"Approve\", \"Manual Review\", \"Reject\"]\n        },\n        \"distressType\": {\n          \"type\": \"string\"\n        },\n        \"confidenceScore\": {\n          \"type\": \"number\",\n          \"minimum\": 0,\n          \"maximum\": 100\n        }\n      },\n      \"required\": [\n        \"approvalRecommendation\",\n        \"distressType\",\n        \"confidenceScore\"\n      ]\n    },\n    \"portfolioExposure\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"exposureCategory\": {\n          \"type\": \"string\",\n          \"enum\": [\"Normal\", \"Elevated\", \"Critical\"]\n        },\n        \"portfolioRiskWeight\": {\n          \"type\": \"number\",\n          \"minimum\": 0\n        }\n      },\n      \"required\": [\n        \"exposureCategory\",\n        \"portfolioRiskWeight\"\n      ]\n    }\n  },\n  \"required\": [\n    \"supplierMonitoring\",\n    \"onboardingSnapshot\",\n    \"portfolioExposure\"\n  ]\n}\n"
      },
      "typeVersion": 1.3
    },
    {
      "id": "c545d1d9-2bfa-45ee-b792-e8718d3fff94",
      "name": "Is High Supplier Risk?",
      "type": "n8n-nodes-base.if",
      "position": [
        4624,
        1168
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e8cf7a4e-a6a0-492d-90d5-f31641c75beb",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.output.supplierMonitoring.riskStatus }}",
              "rightValue": "High Risk"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "5fe0e38e-3d97-4af8-8728-4d1d14f086d3",
      "name": "No Action Required",
      "type": "n8n-nodes-base.noOp",
      "position": [
        4912,
        1280
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2d6cb93b-5af0-4451-974c-2d65b295a4b7",
      "name": "Log Supplier Monitoring Risk",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        4912,
        1056
      ],
      "parameters": {
        "columns": {
          "value": {
            "country": "={{ $node[\"Set Company & Risk Parameters\"].json[\"country\"] }}",
            "riskStatus": "={{ $json.output.supplierMonitoring.riskStatus }}",
            "companyName": "={{ $node[\"Set Company & Risk Parameters\"].json[\"company\"] }}",
            "explanation": "={{ $('Apply Confidence Guardrails').item.json.explanation }}",
            "lastUpdated": "={{ $now }}",
            "probability": "={{ $json.output.supplierMonitoring.probability }}",
            "distressType": "={{ $json.output.supplierMonitoring.distressType }}",
            "confidenceScore": "={{ $json.output.supplierMonitoring.confidenceScore }}"
          },
          "schema": [
            {
              "id": "companyName",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "companyName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "country",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "country",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "riskStatus",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "riskStatus",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "distressType",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "distressType",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "probability",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "probability",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "confidenceScore",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "confidenceScore",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "lastUpdated",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "lastUpdated",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "explanation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "explanation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1-VJbc3CQi7F9ROjcQnfeVmtM6pQ0-MgCKzpXI_HzqCI/edit#gid=0",
          "cachedResultName": "Supplier Monitoring"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE/edit?usp=drivesdk",
          "cachedResultName": "2. Bright Data Financial Distress & Credit Risk Intelligence Engine"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "3826f3ba-4656-4c16-8d71-3c0ed59499fb",
      "name": "Log Onboarding Decision",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        4624,
        1360
      ],
      "parameters": {
        "columns": {
          "value": {
            "Country": "={{ $node[\"Set Company & Risk Parameters\"].json[\"country\"] }}",
            "TimeStamp": "={{ $now }}",
            "CompanyName": "={{ $node[\"Set Company & Risk Parameters\"].json[\"company\"] }}",
            "distressType": "={{ $json.output.onboardingSnapshot.distressType }}",
            "confidenceScore": "={{ $json.output.onboardingSnapshot.confidenceScore }}",
            "approvalRecommendation": "={{ $json.output.onboardingSnapshot.approvalRecommendation }}"
          },
          "schema": [
            {
              "id": "CompanyName",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "CompanyName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Country",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Country",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "approvalRecommendation",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "approvalRecommendation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "distressType",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "distressType",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "confidenceScore",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "confidenceScore",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "TimeStamp",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "TimeStamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1770084134,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE/edit#gid=1770084134",
          "cachedResultName": "Onboarding Snapshot Sheet"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE/edit?usp=drivesdk",
          "cachedResultName": "2. Bright Data Financial Distress & Credit Risk Intelligence Engine"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "81847e2d-6049-486d-aaf0-935e5884b4d1",
      "name": "Log Portfolio Exposure Status",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        4624,
        1584
      ],
      "parameters": {
        "columns": {
          "value": {
            "company": "={{ $node[\"Set Company & Risk Parameters\"].json[\"company\"] }}",
            "countryName": "={{ $node[\"Set Company & Risk Parameters\"].json[\"country\"] }}",
            "exposureCategory": "={{ $json.output.portfolioExposure.exposureCategory }}",
            "portfolioRiskWeight": "={{ $json.output.portfolioExposure.portfolioRiskWeight }}"
          },
          "schema": [
            {
              "id": "countryName",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "countryName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "company",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "company",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "exposureCategory",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "exposureCategory",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "portfolioRiskWeight",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "portfolioRiskWeight",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 511663763,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE/edit#gid=511663763",
          "cachedResultName": "portfolioExposure"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1CMaAm-dAZELQ05AkBkjSsitPNVdw2p5DDeiMI0MA7GE/edit?usp=drivesdk",
          "cachedResultName": "2. Bright Data Financial Distress & Credit Risk Intelligence Engine"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "0d63908f-8832-4808-9eae-9de45468c1d8",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        816
      ],
      "parameters": {
        "color": 4,
        "width": 512,
        "height": 560,
        "content": "## Financial Distress & Credit Risk Intelligence Engine\n\nThis workflow scans a company across financial filings, insolvency registers, and financial news to detect early distress signals.\n\nIt:\n\n- Collects multi-source financial risk indicators\n- Detects bankruptcy, insolvency, restructuring & default signals\n- Classifies financial distress using AI\n- Applies probability weighting and confidence guardrails\n- Converts analysis into business-ready credit decisions\n\nOutputs include:\n\u2022 Supplier Monitoring Risk Status  \n\u2022 Onboarding Approval Recommendation  \n\u2022 Portfolio Exposure Classification  \n\nWhat you need:\n- Bright Data account (for web scraping)\n- OpenRouter API key (for AI analysis)\n- Google Sheets (for output dashboards)\n\nBuilt for conservative, signal-based risk intelligence.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "033bf803-f566-4366-8bf6-f81b202db4aa",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        768
      ],
      "parameters": {
        "color": 7,
        "width": 1200,
        "height": 1328,
        "content": "## Multi-Source Financial Signal Collection\n\nCollects and consolidates financial distress indicators from multiple verified public sources for early credit risk detection.\n\n- Scrapes financial filings for bankruptcy or restructuring disclosures  \n- Monitors insolvency registers for liquidation or court filings  \n- Extracts distress-related financial news mentions  \n- Detects filing, insolvency, and news-based distress signals  \n- Merges signals into a unified structured dataset  \n- Logs scraping failures for monitoring and debugging  \n\nCreates a reliable multi-source foundation for downstream financial distress classification."
      },
      "typeVersion": 1
    },
    {
      "id": "f39697db-e09e-4fb1-9836-1b267cadb052",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2512,
        976
      ],
      "parameters": {
        "color": 7,
        "width": 1104,
        "height": 816,
        "content": "## AI Financial Distress Classification & Risk Scoring\n\nAnalyzes detected financial distress signals using AI to estimate credit risk exposure and refine scoring reliability.\n\n- Categorizes and normalizes detected distress signals  \n- Prepares structured inputs for AI evaluation  \n- Identifies primary financial distress type  \n- Assigns probability of distress occurrence  \n- Generates conservative risk score  \n- Applies probability-based score weighting  \n- Validates AI-generated structured output  \n- Applies confidence guardrails to adjust final risk score  \n\nEnsures reliable financial risk classification based on multi-source signal strength."
      },
      "typeVersion": 1
    },
    {
      "id": "9a675108-b614-4a6c-b637-1739d5d95676",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3920,
        928
      ],
      "parameters": {
        "color": 7,
        "width": 1216,
        "height": 848,
        "content": "## Confidence Guardrails & Business Decisioning\n\nRefines financial risk scores using confirmation logic and converts validated insights into actionable business decisions.\n\n- Applies confidence guardrails to adjust final risk score  \n- Uses multi-source confirmation for validation  \n- Generates supplier monitoring risk status  \n- Produces onboarding approval recommendation  \n- Categorizes portfolio exposure level  \n- Logs supplier monitoring decisions  \n- Records onboarding and exposure insights  \n\nTransforms validated financial signals into operational credit risk decisions."
      },
      "typeVersion": 1
    },
    {
      "id": "fa572ec1-0146-49fe-a288-be6a989f2a41",
      "name": "Financial Distress Classifier",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        3072,
        1632
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "61ff7bb5-5076-4f01-a556-68d2bc9a109b",
      "name": "Business Risk Decision Engine",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "position": [
        4160,
        1616
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "fd928013-5f62-459d-ad02-9ced3cffe868",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        304
      ],
      "parameters": {
        "color": 4,
        "width": 512,
        "height": 480,
        "content": "## Setup Instructions\n\nBefore running this workflow, configure the following credentials in n8n:\n\n**1. Bright Data API** \u2014 Required for web scraping\n- Sign up at brightdata.com\n- Create an API token\n- Add as \"BrightData account\" credential in n8n\n\n**2. OpenRouter API** \u2014 Required for AI classification\n- Sign up at openrouter.ai\n- Generate an API key\n- Add as \"OpenRouter account\" credential in n8n\n\n**3. Google Sheets OAuth** \u2014 Required for output logging\n- Connect your Google account in n8n\n- See the **Google Sheets Setup** sticky note for required tabs and columns\n- Update each Google Sheets node to point to your new spreadsheet\n\nAfter connecting credentials, edit the configuration node to set your target companies, URLs, or parameters."
      },
      "typeVersion": 1
    },
    {
      "id": "6e7ebc20-8eb4-4197-995e-4f9af82a5bee",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        1056
      ],
      "parameters": {
        "color": 7,
        "width": 496,
        "height": 528,
        "content": "## Input & Risk Configuration\n\nInitial configuration block where company details and financial risk indicators are defined for distress analysis.\n\n- Initiates financial risk scan  \n- Sets company name for evaluation  \n- Defines country of incorporation  \n- Specifies financial distress indicators to monitor  \n- Validates input parameters before signal collection  \n\nEnables targeted financial risk detection based on configurable inputs."
      },
      "typeVersion": 1
    },
    {
      "id": "9357dcf0-2e38-4afa-b08b-b5defec46345",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -784,
        1408
      ],
      "parameters": {
        "color": 4,
        "width": 508,
        "height": 464,
        "content": "## Google Sheets Setup\n\nCreate a Google Spreadsheet with 4 tabs and add these column headers in row 1:\n\n**Tab: Supplier Monitoring**\ncompanyName | country | riskStatus | distressType | probability | confidenceScore | lastUpdated | explanation\n\n**Tab: Onboarding Snapshot Sheet**\nCompanyName | Country | approvalRecommendation | distressType | confidenceScore | TimeStamp\n\n**Tab: portfolioExposure**\ncountryName | company | exposureCategory | portfolioRiskWeight\n\n**Tab: BD log error**\nerrorSource | errorMessage | errorCode | timestamp | hasError\n\nAfter creating the spreadsheet, update each Google Sheets node to point to your document and select the matching tab."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "binaryMode": "separate",
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "67f33262-d9f3-45b3-aff0-916cc69964ab",
  "connections": {
    "Scrape Financial News": {
      "main": [
        [
          {
            "node": "Detect News Distress Signals",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Scraping Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is High Supplier Risk?": {
      "main": [
        [
          {
            "node": "Log Supplier Monitoring Risk",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Action Required",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Company Input": {
      "main": [
        [
          {
            "node": "Scrape Financial Filings",
            "type": "main",
            "index": 0
          },
          {
            "node": "Scrape Insolvency Register",
            "type": "main",
            "index": 0
          },
          {
            "node": "Scrape Financial News",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Financial Risk Scan": {
      "main": [
        [
          {
            "node": "Set Company & Risk Parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape Financial Filings": {
      "main": [
        [
          {
            "node": "Detect Filing Distress Signals",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Scraping Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Insolvency Signals": {
      "main": [
        [
          {
            "node": "Merge All Distress Signals",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge All Distress Signals": {
      "main": [
        [
          {
            "node": "Categorize & Normalize Signals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Scrape Insolvency Register": {
      "main": [
        [
          {
            "node": "Detect Insolvency Signals",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Scraping Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply Confidence Guardrails": {
      "main": [
        [
          {
            "node": "Generate Business Risk Decisions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Apply Probability Weighting": {
      "main": [
        [
          {
            "node": "Apply Confidence Guardrails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate AI Distress Output": {
      "ai_outputParser": [
        [
          {
            "node": "AI Financial Distress Classifier",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "Detect News Distress Signals": {
      "main": [
        [
          {
            "node": "Merge All Distress Signals",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "Business Risk Decision Engine": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Business Risk Decisions",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Financial Distress Classifier": {
      "ai_languageModel": [
        [
          {
            "node": "AI Financial Distress Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set Company & Risk Parameters": {
      "main": [
        [
          {
            "node": "Validate Company Input",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Categorize & Normalize Signals": {
      "main": [
        [
          {
            "node": "Prepare Signals for AI Analysis",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Filing Distress Signals": {
      "main": [
        [
          {
            "node": "Merge All Distress Signals",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Signals for AI Analysis": {
      "main": [
        [
          {
            "node": "AI Financial Distress Classifier",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Financial Distress Classifier": {
      "main": [
        [
          {
            "node": "Apply Probability Weighting",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Business Risk Decisions": {
      "main": [
        [
          {
            "node": "Is High Supplier Risk?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Onboarding Decision",
            "type": "main",
            "index": 0
          },
          {
            "node": "Log Portfolio Exposure Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Business Decision Output": {
      "ai_outputParser": [
        [
          {
            "node": "Generate Business Risk Decisions",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}