{
  "id": "Swlucw30gxl83EFI",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Trade Break Reconciliation Assistant",
  "tags": [],
  "nodes": [
    {
      "id": "56124764-847f-41d9-b15a-cc322d787ad6",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        1040,
        176
      ],
      "parameters": {
        "model": "openai/gpt-oss-120b",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0c01a8d5-78a8-4497-b198-2bc6e74b4453",
      "name": "Starting Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -304,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "49d61aed-6071-4bb1-90a8-64b655b26943",
      "name": "Fetch Internal Trades",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -64,
        -128
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1747957679,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit#gid=1747957679",
          "cachedResultName": "Internal Trades"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit?usp=drivesdk",
          "cachedResultName": "n8n meeting notes automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "3e0527cd-78bb-43f5-a22f-28ae544d5a86",
      "name": "Fetch External Trades",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -64,
        80
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1613376579,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit#gid=1613376579",
          "cachedResultName": "External Trades"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit?usp=drivesdk",
          "cachedResultName": "n8n meeting notes automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "c7682776-d1a0-4dc6-84a7-ee6444f94142",
      "name": "Merge Internal & External Trades",
      "type": "n8n-nodes-base.merge",
      "position": [
        384,
        -32
      ],
      "parameters": {
        "mode": "combineBySql",
        "query": "SELECT \n  COALESCE(i.trade_id, e.trade_id) AS trade_id,\n\n  i.row_number AS row_number,  \n\n  i.trade_date AS internal_trade_date,\n  e.trade_date AS external_trade_date,\n\n  i.instrument AS internal_instrument,\n  e.instrument AS external_instrument,\n\n  i.side AS internal_side,\n  e.side AS external_side,\n\n  i.price AS internal_price,\n  e.price AS external_price,\n\n  i.quantity AS internal_quantity,\n  e.quantity AS external_quantity,\n\n  i.amount AS internal_amount,\n  e.amount AS external_amount,\n\n  i.currency AS internal_currency,\n  e.currency AS external_currency,\n\n  i.status AS internal_status,\n  e.status AS external_status\n\nFROM input1 i\nFULL OUTER JOIN input2 e\nON i.trade_id = e.trade_id",
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "cf076aeb-88cb-4cd1-8319-a90d75646f17",
      "name": "Detect Trade Breaks",
      "type": "n8n-nodes-base.code",
      "position": [
        576,
        -32
      ],
      "parameters": {
        "jsCode": "const results = [];\n\nfor (const item of items) {\n  const d = item.json;\n\n  let issues = [];\n\n  if (!d.internal_amount) issues.push(\"Missing in Internal\");\n  if (!d.external_amount) issues.push(\"Missing in External\");\n\n  if (d.internal_amount !== d.external_amount)\n    issues.push(\"Amount mismatch\");\n\n  if (d.internal_quantity !== d.external_quantity)\n    issues.push(\"Quantity mismatch\");\n\n  if (d.internal_price !== d.external_price)\n    issues.push(\"Price mismatch\");\n\n  if (d.internal_side !== d.external_side)\n    issues.push(\"Side mismatch\");\n\n  if (d.internal_currency !== d.external_currency)\n    issues.push(\"Currency mismatch\");\n\n  if (d.internal_status !== d.external_status)\n    issues.push(\"Status mismatch\");\n\n  const isMismatch = issues.length > 0;\n\n  results.push({\n    json: {\n      row_number: d.row_number,\n      trade_id: d.trade_id,\n\n    \n      isMismatch: isMismatch,\n\n      // readable issues\n      issues: isMismatch ? issues.join(\", \") : \"No Issue\",\n\n      internal_price: d.internal_price,\n      external_price: d.external_price,\n      internal_amount: d.internal_amount,\n      external_amount: d.external_amount,\n      internal_quantity: d.internal_quantity,\n      external_quantity: d.external_quantity\n    }\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "6549b6b7-4238-493c-b94f-9e61fe5f881d",
      "name": "Classify Severity",
      "type": "n8n-nodes-base.code",
      "position": [
        768,
        -32
      ],
      "parameters": {
        "jsCode": "const itemsOut = [];\n\nfor (const item of items) {\n  let severity = \"NA\";\n\n  try {\n    const output = item.json.output;\n    const parsed = output && output.includes('{')\n      ? JSON.parse(output.trim())\n      : null;\n\n    if (parsed) {\n      const reason = parsed.reason.toLowerCase();\n\n      if (reason.includes(\"amount\") || reason.includes(\"price\")) {\n        severity = \"High\";\n      } else if (reason.includes(\"quantity\")) {\n        severity = \"Medium\";\n      } else {\n        severity = \"Low\";\n      }\n    }\n\n  } catch (e) {\n    severity = \"Low\";\n  }\n\n  itemsOut.push({\n    json: {\n      ...item.json,\n      severity\n    }\n  });\n}\n\nreturn itemsOut;"
      },
      "typeVersion": 2
    },
    {
      "id": "5ce4adeb-fcd7-4a3b-8043-aa3902980f1f",
      "name": "Prepare Trade Data",
      "type": "n8n-nodes-base.set",
      "position": [
        976,
        -32
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "9172c544-d58a-4421-ba57-44e3aabc61fa",
              "name": "trade_id",
              "type": "string",
              "value": "={{$json.trade_id}}"
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "3f8e9aab-a158-45e1-b372-f193e2590062",
      "name": "Generate AI Reconciliation Insight",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1168,
        -32
      ],
      "parameters": {
        "text": "=Price: {{$json.internal_price}}\nQuantity: {{$json.internal_quantity}}\nAmount: {{$json.internal_amount}}\n\nExternal:\nPrice: {{$json.external_price}}\nQuantity: {{$json.external_quantity}}\nAmount: {{$json.external_amount}}\n\nGive:\n1. Likely reason (timing issue / price difference / quantity mismatch / missing trade / data error)\n2. One-line explanation\n3. Suggested action to resolve\n\nReturn ONLY JSON:\n{\n  \"reason\": \"\",\n  \"explanation\": \"\",\n  \"action\": \"\"\n}",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "b87493f1-e8af-4fc1-9946-c84a806a7183",
      "name": "Extract AI Output",
      "type": "n8n-nodes-base.set",
      "position": [
        1472,
        -32
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8b77ea38-5cb5-4603-8787-6b203d642b3b",
              "name": "Reason",
              "type": "string",
              "value": "={{ JSON.parse($json.output).reason }}"
            },
            {
              "id": "a44089dc-9c1b-426d-a346-7956933a693d",
              "name": "Action",
              "type": "string",
              "value": "={{ JSON.parse($json.output).action }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ec53dda5-298c-4a3f-9d75-93f2a3b5f520",
      "name": "Check Valid Row",
      "type": "n8n-nodes-base.if",
      "position": [
        1744,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "01dc9076-486a-4de4-94b1-27a5ca42896d",
              "operator": {
                "type": "number",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $('Prepare Trade Data').item.json.row_number }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "aad02651-ec2f-4006-ad1a-f8c17e14975a",
      "name": "Check Trade Mismatch",
      "type": "n8n-nodes-base.if",
      "position": [
        2576,
        -176
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "0b4158c5-116f-4474-9ded-6474c33e70cf",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.mismatch }}",
              "rightValue": "Yes"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "4374f2bc-e3fa-48f4-8ef2-b31d5d221608",
      "name": "Update Internal Trades Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2016,
        -176
      ],
      "parameters": {
        "columns": {
          "value": {
            "action": "={{ \n  !$('Prepare Trade Data').item.json.isMismatch\n    ? '-'\n    : ($json.Action || '')\n}}",
            "reason": "={{ \n  !$('Prepare Trade Data').item.json.isMismatch\n    ? 'Matched Successfully'\n    : ($json.Reason || '').trim()\n}}",
            "mismatch": "={{ $('Detect Trade Breaks').item.json.isMismatch  ? \"Yes\" : \"No\" }}",
            "severity": "={{ \n  !$('Prepare Trade Data').item.json.isMismatch\n    ? 'NA'\n    : (\n        ($json.output || '').toString().toLowerCase().includes('price') ||\n        ($json.output || '').toString().toLowerCase().includes('amount')\n      )\n    ? 'High'\n    : ($json.output || '').toString().toLowerCase().includes('quantity')\n    ? 'Medium'\n    : 'Low'\n}}",
            "row_number": "={{ $('Prepare Trade Data').item.json.row_number }}"
          },
          "schema": [
            {
              "id": "trade_id",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "trade_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "trade_date",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "trade_date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instrument",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "instrument",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "side",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "side",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "amount",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "currency",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "currency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "mismatch",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "mismatch",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "reason",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "severity",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "severity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "action",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "action",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1747957679,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit#gid=1747957679",
          "cachedResultName": "Internal Trades"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit?usp=drivesdk",
          "cachedResultName": "n8n meeting notes automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "0878a6e8-a32e-4ccc-be01-f90e22c72907",
      "name": "Update External Trades Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2240,
        -176
      ],
      "parameters": {
        "columns": {
          "value": {
            "action": "={{ $json.action }}",
            "reason": "={{ $json.reason }}",
            "mismatch": "={{ $json.mismatch }}",
            "severity": "={{ $json.severity }}",
            "row_number": "={{ $json.row_number }}"
          },
          "schema": [
            {
              "id": "trade_id",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "trade_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "trade_date",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "trade_date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instrument",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "instrument",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "side",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "side",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "amount",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "currency",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "currency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "mismatch",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "mismatch",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "reason",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "severity",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "severity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "action",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "action",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "row_number"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1613376579,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit#gid=1613376579",
          "cachedResultName": "External Trades"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit?usp=drivesdk",
          "cachedResultName": "n8n meeting notes automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "bbc527ae-1dc7-4e33-b472-220b47d1e264",
      "name": "Insert Missing Internal Trade",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2016,
        64
      ],
      "parameters": {
        "columns": {
          "value": {
            "action": "Verify and create missing trade in internal system or escalate if invalid.",
            "reason": "Trade exists only in external system",
            "mismatch": "Missing record",
            "severity": "High",
            "trade_id": "={{ $('Prepare Trade Data').item.json.trade_id }}"
          },
          "schema": [
            {
              "id": "trade_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "trade_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "trade_date",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "trade_date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instrument",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "instrument",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "side",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "side",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "amount",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "currency",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "currency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "mismatch",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "mismatch",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "reason",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "severity",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "severity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "action",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "action",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1747957679,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit#gid=1747957679",
          "cachedResultName": "Internal Trades"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit?usp=drivesdk",
          "cachedResultName": "n8n meeting notes automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "adbb4639-a505-4bff-985f-c48680eb260e",
      "name": "Insert External Trade Record",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2240,
        64
      ],
      "parameters": {
        "columns": {
          "value": {
            "action": "Verify and create missing trade in internal system or escalate if invalid.",
            "reason": "Trade exists only in external system",
            "mismatch": "Missing record",
            "severity": "High",
            "trade_id": "={{ $('Prepare Trade Data').item.json.trade_id }}"
          },
          "schema": [
            {
              "id": "trade_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "trade_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "trade_date",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "trade_date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "instrument",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "instrument",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "side",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "side",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "price",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "price",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "quantity",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "quantity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "amount",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "amount",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "currency",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "currency",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "status",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "status",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "mismatch",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "mismatch",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "reason",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "reason",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "severity",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "severity",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "action",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "action",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "trade_id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1613376579,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit#gid=1613376579",
          "cachedResultName": "External Trades"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Z9JlUPMr00U9k385p64yZbj4VKMDcQVd9AKa6FVXE60/edit?usp=drivesdk",
          "cachedResultName": "n8n meeting notes automation"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "ce399748-3aae-4df0-9609-5ed5aa2900dd",
      "name": "Send Trade Break Alert Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2784,
        -192
      ],
      "parameters": {
        "message": "=Trade Break Detected\n\nTrade ID: {{ $('Prepare Trade Data').item.json.trade_id }}\n\nIssue:\n{{ $('Prepare Trade Data').item.json.issues }}\n\nInternal:\nPrice: {{ $('Prepare Trade Data').item.json.internal_price }}\nQuantity: {{ $('Prepare Trade Data').item.json.internal_quantity }}\nAmount: {{ $('Prepare Trade Data').item.json.internal_amount }}\n\nExternal:\nPrice: {{ $('Prepare Trade Data').item.json.external_price }}\nQuantity: {{ $('Prepare Trade Data').item.json.external_quantity }}\nAmount: {{ $('Prepare Trade Data').item.json.external_amount }}\n\nSeverity: {{ $json.severity }}\n\nReason:\n{{\n!$('Prepare Trade Data').item.json.isMismatch\n? 'Matched Successfully'\n: ($json.Reason || $json.reason || '').trim()\n}}\n\nAction:\n{{\n!$('Prepare Trade Data').item.json.isMismatch\n? ''\n: ($json.Action || '')\n}}\n\nRegards,\nTrade Reconciliation System",
        "options": {},
        "subject": "=Trade Break Alert - {{ $('Prepare Trade Data').item.json.trade_id }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "aabfbb64-ff2b-49c8-afba-93df276ce859",
      "name": "Send Missing Trade Alert Email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        2592,
        64
      ],
      "parameters": {
        "message": "=Trade Break Detected\n\nTrade ID: {{ $('Prepare Trade Data').item.json.trade_id }}\n\nIssue:\n{{ $('Prepare Trade Data').item.json.issues }}\n\nInternal:{{ $json.mismatch }}\nPrice: {{ $json.mismatch }}\nQuantity:{{ $json.mismatch }}\nAmount: {{ $json.mismatch }}\n\nExternal:\nPrice: {{ $('Prepare Trade Data').item.json.external_price }}\nQuantity: {{ $('Prepare Trade Data').item.json.external_quantity }}\nAmount: {{ $('Prepare Trade Data').item.json.external_amount }}\n\nSeverity: {{ $json.severity }}\n\nReason:\n{{\n!$('Prepare Trade Data').item.json.isMismatch\n? 'Matched Successfully'\n: ($json.Reason || $json.reason || '').trim()\n}}\n\nAction:\n{{ $json.action }}\n\nRegards,\nTrade Reconciliation System",
        "options": {},
        "subject": "=Trade Break Alert - {{ $('Prepare Trade Data').item.json.trade_id }}",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "016b25fc-253b-4b30-b878-c5b15f0ec306",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1072,
        -416
      ],
      "parameters": {
        "width": 576,
        "height": 1056,
        "content": "# Trade Break Reconciliation Automation\n# How It Works\n\nThis workflow automates trade reconciliation between internal and external systems using Google Sheets. It fetches and merges trade data, then detects mismatches like price, quantity, amount or missing trades.Each break is classified by severity and AI generates the reason, explanation and suggested action. The results are updated in the sheets for tracking and audit.Missing trades are automatically handled by creating or updating records. Email alerts are sent with complete details for quick resolution.This reduces manual effort, improves accuracy and speeds up reconciliation.\n\n# Setup Steps\n\n## 1. Connect Google Sheets\nAuthenticate internal and external trade sheets\n\n## 2. Configure Data Merge Logic\nEnsure trade_id is used for matching records\n\n## 3. Configure Mismatch Detection\nSet comparison logic for price, quantity, amount, etc.\n\n## 4. Configure AI Model\nConnect Groq/OpenAI and define reconciliation prompt\n\n## 5. Configure Data Update\nMap mismatch, reason, severity and action fields\n\n## 6. Configure Email Alerts\nSet recipient and trade break email format\n\n## 7. Test Workflow\nRun workflow and validate reconciliation output"
      },
      "typeVersion": 1
    },
    {
      "id": "31d4e237-ab9c-45fc-a17c-183be9d6f8a3",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        -288
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 528,
        "content": "## Input & Data Fetch\n\nFetches trade data from internal and external Google Sheets and prepares it for reconciliation.\nEnsures all records are captured correctly before processing.\nActs as the starting point for comparing both data sources."
      },
      "typeVersion": 1
    },
    {
      "id": "4fd79ea6-a090-418f-bb92-bdc6a98d163f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        320,
        -208
      ],
      "parameters": {
        "color": 7,
        "width": 576,
        "height": 400,
        "content": "## Data Preparation, Mismatch Detection & Severity\n\nMerges internal and external trades using trade_id and prepares data for comparison. Identifies mismatches like price, quantity and amount differences.\nClassifies each issue by severity for prioritization."
      },
      "typeVersion": 1
    },
    {
      "id": "1dc6160d-57c3-4287-8741-e689dd255312",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        944,
        -192
      ],
      "parameters": {
        "color": 7,
        "width": 656,
        "height": 512,
        "content": "## AI Analysis & Data Preparation\n\nPrepares trade data and sends it to AI for analysis. Generates reason, explanation and suggested action for each mismatch. Transforms raw mismatch data into meaningful insights for users. Extracts and structures AI output into usable fields for downstream processing."
      },
      "typeVersion": 1
    },
    {
      "id": "d8a1b3cd-678b-435f-94a9-16845737429a",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1712,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 720,
        "height": 624,
        "content": "## Data Update & Handling\n\nUpdates reconciliation results back into Google Sheets for tracking. Handles missing trades by inserting or updating records. Maintains data consistency across internal and external systems. Ensures all records are properly mapped using row references. Prepares final structured data for reporting and notifications."
      },
      "typeVersion": 1
    },
    {
      "id": "337d8341-cc3c-40c6-a63a-286fc33bbf3a",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2512,
        -352
      ],
      "parameters": {
        "color": 7,
        "width": 512,
        "height": 672,
        "content": "## Notification & Alerts\n\nSends detailed email alerts with trade break information. Includes trade ID, issues, severity, reason and action. Ensures quick visibility and faster resolution of problems. Notifies users instantly for both mismatches and missing trades .Helps prioritize critical issues based on severity levels."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "6cb1180b-dd6e-476c-b989-8ee135e678a2",
  "connections": {
    "Check Valid Row": {
      "main": [
        [
          {
            "node": "Update Internal Trades Sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Insert Missing Internal Trade",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate AI Reconciliation Insight",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Starting Trigger": {
      "main": [
        [
          {
            "node": "Fetch Internal Trades",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch External Trades",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Classify Severity": {
      "main": [
        [
          {
            "node": "Prepare Trade Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract AI Output": {
      "main": [
        [
          {
            "node": "Check Valid Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Trade Data": {
      "main": [
        [
          {
            "node": "Generate AI Reconciliation Insight",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detect Trade Breaks": {
      "main": [
        [
          {
            "node": "Classify Severity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Trade Mismatch": {
      "main": [
        [
          {
            "node": "Send Trade Break Alert Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch External Trades": {
      "main": [
        [
          {
            "node": "Merge Internal & External Trades",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Fetch Internal Trades": {
      "main": [
        [
          {
            "node": "Merge Internal & External Trades",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert External Trade Record": {
      "main": [
        [
          {
            "node": "Send Missing Trade Alert Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update External Trades Sheet": {
      "main": [
        [
          {
            "node": "Check Trade Mismatch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Internal Trades Sheet": {
      "main": [
        [
          {
            "node": "Update External Trades Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insert Missing Internal Trade": {
      "main": [
        [
          {
            "node": "Insert External Trade Record",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Internal & External Trades": {
      "main": [
        [
          {
            "node": "Detect Trade Breaks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate AI Reconciliation Insight": {
      "main": [
        [
          {
            "node": "Extract AI Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}