Email Categorization

    This workflow uses AI to read and organize your inbox. It uses Google Gemini to understand email content, rather than keywords. How it works A schedule runs the workflow daily to scan the latest messages. The workflow sends email content to Google Gemini AI. The AI determines if an email is a bill, question, invite, or junk. Based on the AI's decision, it automatically applies the correct label in Gmail or Outlook.

    Shared 1/19/2026

    2 views

    Visual Workflow

    JSON Code

    {
      "id": "b62mUixbnPfHQyKK",
      "meta": {
        "instanceId": "162eec3732de59437b64feac9b77d3c4c84098988ae869a1ee7e056d40699a32",
        "templateCredsSetupCompleted": true
      },
      "name": "Email Categorization",
      "tags": [],
      "nodes": [
        {
          "id": "905cb42d-46e8-46e6-9467-4a2eb422d7b5",
          "name": "Schedule Trigger",
          "type": "n8n-nodes-base.scheduleTrigger",
          "position": [
            -64,
            -96
          ],
          "parameters": {
            "rule": {
              "interval": [
                {
                  "triggerAtHour": 9
                }
              ]
            }
          },
          "typeVersion": 1.3
        },
        {
          "id": "f96a304c-de59-4491-b9d2-09ce69b1b42f",
          "name": "Get many messages",
          "type": "n8n-nodes-base.gmail",
          "position": [
            752,
            -96
          ],
          "webhookId": "7e050408-592f-4b37-82b5-82ac21eab149",
          "parameters": {
            "limit": "={{ $('Edit Fields').item.json.Limit }}",
            "filters": {
              "receivedAfter": "={{ $('Edit Fields').item.json.ReceivedAfter }}"
            },
            "operation": "getAll"
          },
          "credentials": {
            "gmailOAuth2": {
              "id": "P75ucVf9LpvRaayr",
              "name": "yvesyiu7"
            }
          },
          "typeVersion": 2.2
        },
        {
          "id": "f023264b-15b7-4f35-b4d1-cd1df3f820f7",
          "name": "Edit Fields",
          "type": "n8n-nodes-base.set",
          "position": [
            144,
            -96
          ],
          "parameters": {
            "options": {},
            "assignments": {
              "assignments": [
                {
                  "id": "2297ca63-7b0d-4bc8-9ea5-8a9833ecc161",
                  "name": "ReceivedAfter",
                  "type": "string",
                  "value": "={{ $today.minus({ days: 1 }).toISO() }}"
                },
                {
                  "id": "832ed645-ba92-4a6e-b2fe-cd76ab56c7a6",
                  "name": "SheetId",
                  "type": "string",
                  "value": "1ysc3MMi6wXnm0vWH-AooUc-DuIw5pjWh9el39YDYB3U"
                },
                {
                  "id": "e6663a18-2b78-4a68-bc8d-bb61d0b8fd96",
                  "name": "GID",
                  "type": "string",
                  "value": "1104156495"
                },
                {
                  "id": "29e3ae54-3ed2-40e1-86f4-0d5157c34f82",
                  "name": "Limit",
                  "type": "string",
                  "value": "10"
                },
                {
                  "id": "f493b895-e8cd-4505-bdd9-e89e2b74ce4a",
                  "name": "Label GID",
                  "type": "string",
                  "value": "667751980"
                }
              ]
            }
          },
          "typeVersion": 3.4
        },
        {
          "id": "c55eed6b-ebd2-458b-88aa-f32f6603fac1",
          "name": "Append row in sheet",
          "type": "n8n-nodes-base.googleSheets",
          "position": [
            944,
            -96
          ],
          "parameters": {
            "columns": {
              "value": {
                "id": "={{ $json.id}}",
                "From": "={{ $json.From}}",
                "Snippet": "={{ $json.snippet }}",
                "Subject": "={{ $json.Subject }}"
              },
              "schema": [
                {
                  "id": "id",
                  "type": "string",
                  "display": true,
                  "removed": false,
                  "required": false,
                  "displayName": "id",
                  "defaultMatch": true,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "Subject",
                  "type": "string",
                  "display": true,
                  "removed": false,
                  "required": false,
                  "displayName": "Subject",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "From",
                  "type": "string",
                  "display": true,
                  "removed": false,
                  "required": false,
                  "displayName": "From",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "Snippet",
                  "type": "string",
                  "display": true,
                  "removed": false,
                  "required": false,
                  "displayName": "Snippet",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "AI Category",
                  "type": "string",
                  "display": true,
                  "removed": false,
                  "required": false,
                  "displayName": "AI Category",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                }
              ],
              "mappingMode": "defineBelow",
              "matchingColumns": [
                "id"
              ],
              "attemptToConvertTypes": false,
              "convertFieldsToString": false
            },
            "options": {},
            "operation": "append",
            "sheetName": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields').item.json.GID }}"
            },
            "documentId": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields').item.json.SheetId }}"
            }
          },
          "credentials": {
            "googleSheetsOAuth2Api": {
              "id": "Ub9TjjddT01r06uo",
              "name": "Yves"
            }
          },
          "typeVersion": 4.7
        },
        {
          "id": "a27e0fe6-abef-4d71-b4ed-cbd1a327b1e8",
          "name": "Loop Over Items",
          "type": "n8n-nodes-base.splitInBatches",
          "position": [
            1328,
            -96
          ],
          "parameters": {
            "options": {},
            "batchSize": 15
          },
          "typeVersion": 3
        },
        {
          "id": "caa69095-d625-4e87-8629-707ea3f2ad66",
          "name": "Replace Me",
          "type": "n8n-nodes-base.noOp",
          "position": [
            1952,
            -80
          ],
          "parameters": {},
          "typeVersion": 1
        },
        {
          "id": "76e5def8-c14a-4210-8362-15a904784e9a",
          "name": "Google Gemini Chat Model",
          "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
          "position": [
            1552,
            176
          ],
          "parameters": {
            "options": {}
          },
          "credentials": {
            "googlePalmApi": {
              "id": "eAJWGGMp44sGQn30",
              "name": "Google Gemini(PaLM) Api account"
            }
          },
          "typeVersion": 1
        },
        {
          "id": "698b76de-260a-4d86-a4ea-3f3eaa9524d0",
          "name": "Append or update row in sheet",
          "type": "n8n-nodes-base.googleSheets",
          "position": [
            1952,
            -432
          ],
          "parameters": {
            "columns": {
              "value": {
                "id": "={{ $json.id }}",
                "AI Category": "={{ $json.label }}"
              },
              "schema": [
                {
                  "id": "id",
                  "type": "string",
                  "display": true,
                  "removed": false,
                  "required": false,
                  "displayName": "id",
                  "defaultMatch": true,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "Subject",
                  "type": "string",
                  "display": true,
                  "required": false,
                  "displayName": "Subject",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "From",
                  "type": "string",
                  "display": true,
                  "required": false,
                  "displayName": "From",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "Snippet",
                  "type": "string",
                  "display": true,
                  "required": false,
                  "displayName": "Snippet",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "AI Category",
                  "type": "string",
                  "display": true,
                  "required": false,
                  "displayName": "AI Category",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                }
              ],
              "mappingMode": "defineBelow",
              "matchingColumns": [
                "id"
              ],
              "attemptToConvertTypes": false,
              "convertFieldsToString": false
            },
            "options": {},
            "operation": "appendOrUpdate",
            "sheetName": {
              "__rl": true,
              "mode": "id",
              "value": "1104156495"
            },
            "documentId": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields').item.json.SheetId }}"
            }
          },
          "credentials": {
            "googleSheetsOAuth2Api": {
              "id": "Ub9TjjddT01r06uo",
              "name": "Yves"
            }
          },
          "typeVersion": 4.7
        },
        {
          "id": "798f7dd0-5aad-48ac-9019-4b56bd8d7239",
          "name": "Aggregate1",
          "type": "n8n-nodes-base.aggregate",
          "position": [
            1136,
            -96
          ],
          "parameters": {
            "options": {},
            "aggregate": "aggregateAllItemData"
          },
          "typeVersion": 1
        },
        {
          "id": "6d5e8faf-e909-48f4-9bc6-e2096b9be39b",
          "name": "Add label to message",
          "type": "n8n-nodes-base.gmail",
          "position": [
            2528,
            -240
          ],
          "webhookId": "4fdd954e-5afa-491f-90ea-ad0717e82161",
          "parameters": {
            "labelIds": "={{ $json.id }}",
            "messageId": "={{ $('Loop Over Items2').item.json.id }}",
            "operation": "addLabels"
          },
          "credentials": {
            "gmailOAuth2": {
              "id": "P75ucVf9LpvRaayr",
              "name": "yvesyiu7"
            }
          },
          "typeVersion": 2.2
        },
        {
          "id": "4123b3f1-b1d1-404a-9681-c09b53c71c80",
          "name": "Get Labels",
          "type": "n8n-nodes-base.googleSheets",
          "position": [
            336,
            -96
          ],
          "parameters": {
            "options": {},
            "sheetName": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields').item.json['Label GID'] }}"
            },
            "documentId": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields').item.json.SheetId }}"
            }
          },
          "credentials": {
            "googleSheetsOAuth2Api": {
              "id": "Ub9TjjddT01r06uo",
              "name": "Yves"
            }
          },
          "typeVersion": 4.7
        },
        {
          "id": "2ce0f4d7-88fb-4d19-83cc-b228a9b6cb98",
          "name": "Edit Fields2",
          "type": "n8n-nodes-base.set",
          "position": [
            112,
            -624
          ],
          "parameters": {
            "options": {},
            "assignments": {
              "assignments": [
                {
                  "id": "2297ca63-7b0d-4bc8-9ea5-8a9833ecc161",
                  "name": "ReceivedAfter",
                  "type": "string",
                  "value": "={{ $today.minus({ days: 1 }).toISO() }}"
                },
                {
                  "id": "832ed645-ba92-4a6e-b2fe-cd76ab56c7a6",
                  "name": "SheetId",
                  "type": "string",
                  "value": "1ysc3MMi6wXnm0vWH-AooUc-DuIw5pjWh9el39YDYB3U"
                },
                {
                  "id": "e6663a18-2b78-4a68-bc8d-bb61d0b8fd96",
                  "name": "GID",
                  "type": "string",
                  "value": "667751980"
                },
                {
                  "id": "29e3ae54-3ed2-40e1-86f4-0d5157c34f82",
                  "name": "Limit",
                  "type": "string",
                  "value": "10"
                },
                {
                  "id": "f493b895-e8cd-4505-bdd9-e89e2b74ce4a",
                  "name": "Label GID",
                  "type": "string",
                  "value": "667751980"
                }
              ]
            }
          },
          "typeVersion": 3.4
        },
        {
          "id": "f309487a-a094-44cb-a7d5-5891fe795179",
          "name": "Get Labels1",
          "type": "n8n-nodes-base.googleSheets",
          "position": [
            1024,
            -624
          ],
          "parameters": {
            "options": {},
            "sheetName": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields2').item.json.GID }}"
            },
            "documentId": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields2').item.json.SheetId }}"
            }
          },
          "credentials": {
            "googleSheetsOAuth2Api": {
              "id": "Ub9TjjddT01r06uo",
              "name": "Yves"
            }
          },
          "typeVersion": 4.7
        },
        {
          "id": "5e4b8043-4cb7-4df3-9154-723132ca74a4",
          "name": "Loop Over Items1",
          "type": "n8n-nodes-base.splitInBatches",
          "position": [
            1200,
            -624
          ],
          "parameters": {
            "options": {}
          },
          "typeVersion": 3
        },
        {
          "id": "a9c85123-804f-49e2-9980-8a79ce822d2a",
          "name": "Replace Me1",
          "type": "n8n-nodes-base.noOp",
          "position": [
            1840,
            -624
          ],
          "parameters": {},
          "typeVersion": 1
        },
        {
          "id": "b4f50891-e054-489b-8351-6bcb4eea016c",
          "name": "Get many labels2",
          "type": "n8n-nodes-base.gmail",
          "position": [
            272,
            -624
          ],
          "webhookId": "6da41a3b-d594-49ef-94d0-260a7d5bcbc9",
          "parameters": {
            "resource": "label",
            "returnAll": true
          },
          "credentials": {
            "gmailOAuth2": {
              "id": "P75ucVf9LpvRaayr",
              "name": "yvesyiu7"
            }
          },
          "typeVersion": 2.2
        },
        {
          "id": "91a9e89b-61a2-4945-96d8-eedc6bd4bfbb",
          "name": "Aggregate",
          "type": "n8n-nodes-base.aggregate",
          "position": [
            832,
            -624
          ],
          "parameters": {
            "options": {},
            "fieldsToAggregate": {
              "fieldToAggregate": [
                {
                  "fieldToAggregate": "Label Exist"
                }
              ]
            }
          },
          "typeVersion": 1
        },
        {
          "id": "003604d0-ccc1-498f-a4fe-a75bd5a03637",
          "name": "Get Label Exist",
          "type": "n8n-nodes-base.set",
          "position": [
            656,
            -624
          ],
          "parameters": {
            "options": {},
            "assignments": {
              "assignments": [
                {
                  "id": "a2edda94-85b1-4e8c-bde5-e89548923f80",
                  "name": "Label Exist",
                  "type": "string",
                  "value": "={{ $('Get many labels2').item.json.name }}"
                }
              ]
            }
          },
          "typeVersion": 3.4
        },
        {
          "id": "97546082-3afa-41d0-8adf-1892eff7680a",
          "name": "Check if Label Exist",
          "type": "n8n-nodes-base.if",
          "position": [
            1408,
            -608
          ],
          "parameters": {
            "options": {},
            "conditions": {
              "options": {
                "version": 3,
                "leftValue": "",
                "caseSensitive": true,
                "typeValidation": "strict"
              },
              "combinator": "and",
              "conditions": [
                {
                  "id": "f343023e-7426-47f6-a19a-251e050a70a4",
                  "operator": {
                    "type": "array",
                    "operation": "contains",
                    "rightType": "any"
                  },
                  "leftValue": "={{ $('Aggregate').item.json['Label Exist'] }}",
                  "rightValue": "={{ $json.Labels }}"
                }
              ]
            }
          },
          "typeVersion": 2.3
        },
        {
          "id": "c7b157ea-1f58-41d9-a77e-0b9bd70b2d12",
          "name": "Create a label",
          "type": "n8n-nodes-base.gmail",
          "position": [
            1616,
            -544
          ],
          "webhookId": "82be4dfc-690e-4cf0-9c44-c0dfc0d35c0d",
          "parameters": {
            "name": "={{ $json.Labels }}",
            "options": {},
            "resource": "label",
            "operation": "create"
          },
          "credentials": {
            "gmailOAuth2": {
              "id": "P75ucVf9LpvRaayr",
              "name": "yvesyiu7"
            }
          },
          "typeVersion": 2.2
        },
        {
          "id": "1580fc52-bb6b-4d4b-bb7d-e8a6ebd2ad2f",
          "name": "Check Labels",
          "type": "n8n-nodes-base.manualTrigger",
          "position": [
            -64,
            -624
          ],
          "parameters": {},
          "typeVersion": 1
        },
        {
          "id": "3a96dd63-218b-49dc-877d-832ae823f140",
          "name": "Csv to Json",
          "type": "n8n-nodes-base.code",
          "position": [
            1632,
            -256
          ],
          "parameters": {
            "jsCode": "const csvString = $('Loop Over Items').first().json.output.trim(); // Adjust 'output' path if your AI provider nests it differently (e.g., choices[0].message.content)\nconst lines = csvString.split('\\n').slice(1); // Skip header\nreturn lines.map(line => {\n  const [id, labelsStr] = line.split(',');\n  const labels = labelsStr.trim().split(';').map(label => label.trim()).filter(label => label); // Split into array, trim, and filter empty\n  return { json: { id: id.trim(), label: labels } }; // 'label' is now an array for multi-labels\n});"
          },
          "typeVersion": 2
        },
        {
          "id": "0eeccf81-ad7c-498a-8034-9cf643ea3a3b",
          "name": "Categorize Emails with AI",
          "type": "@n8n/n8n-nodes-langchain.agent",
          "position": [
            1552,
            -80
          ],
          "parameters": {
            "text": "=You are an email categorizer. You will receive a JSON array of emails.\nFor each email, assign one or more of these labels if they apply (choose all relevant ones; it's okay to assign multiple, but only if the email truly fits them;the labels also contains numbers. Don't delete the number):\n\n{{ $('Aggregate Labels with Description').item.json.Labels }}\n\nAnd below are the descriptions of all labels.\n{{ $('Aggregate Labels with Description').item.json.Description }}\n\nIf multiple labels apply, separate them with a semicolon (;) in the label field (e.g., Promotions;Work).\nOutput ONLY a valid CSV with exactly these two columns and nothing else:\nid,label\n<email1_id>,<label1;label2> (or just  if single)\n<email2_id>,<chosen_label>\n...\nRules (strictly follow):\n\nFirst line must be exactly: id,label\nOne email per line\nNo spaces before/after commas or semicolons\nNo quotes, no extra text, no markdown, no code block, no explanations\nPreserve the exact order of the input array\nDo not output anything else (not even ```csv\n\nInput JSON:\n{{ JSON.stringify($json.data) }} <-- (or paste your array here if testing manually)\nOnly output the CSV lines.",
            "options": {},
            "promptType": "define"
          },
          "typeVersion": 3.1
        },
        {
          "id": "06c7f39c-c0d2-458c-8430-be7a71e5177a",
          "name": "Aggregate Labels with Description",
          "type": "n8n-nodes-base.aggregate",
          "position": [
            544,
            -96
          ],
          "parameters": {
            "options": {},
            "fieldsToAggregate": {
              "fieldToAggregate": [
                {
                  "fieldToAggregate": "Labels"
                },
                {
                  "fieldToAggregate": "=Description"
                },
                {}
              ]
            }
          },
          "typeVersion": 1
        },
        {
          "id": "ad131538-e36d-45df-88cd-e67db4a353d5",
          "name": "Append or update row in sheet1",
          "type": "n8n-nodes-base.googleSheets",
          "position": [
            464,
            -624
          ],
          "parameters": {
            "columns": {
              "value": {
                "Id": "={{ $json.id }}",
                "Labels": "={{ $json.name }}"
              },
              "schema": [
                {
                  "id": "Labels",
                  "type": "string",
                  "display": true,
                  "removed": false,
                  "required": false,
                  "displayName": "Labels",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "Description",
                  "type": "string",
                  "display": true,
                  "required": false,
                  "displayName": "Description",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                },
                {
                  "id": "Id",
                  "type": "string",
                  "display": true,
                  "required": false,
                  "displayName": "Id",
                  "defaultMatch": false,
                  "canBeUsedToMatch": true
                }
              ],
              "mappingMode": "defineBelow",
              "matchingColumns": [
                "Labels"
              ],
              "attemptToConvertTypes": false,
              "convertFieldsToString": false
            },
            "options": {},
            "operation": "appendOrUpdate",
            "sheetName": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields2').item.json.GID }}"
            },
            "documentId": {
              "__rl": true,
              "mode": "id",
              "value": "={{ $('Edit Fields2').item.json.SheetId }}"
            }
          },
          "credentials": {
            "googleSheetsOAuth2Api": {
              "id": "Ub9TjjddT01r06uo",
              "name": "Yves"
            }
          },
          "typeVersion": 4.7
        },
        {
          "id": "163a4609-3403-4843-abed-56e9e2196daf",
          "name": "Loop Over Items2",
          "type": "n8n-nodes-base.splitInBatches",
          "position": [
            1952,
            -256
          ],
          "parameters": {
            "options": {}
          },
          "typeVersion": 3
        },
        {
          "id": "da41169a-5879-4cee-a887-2762d8f76a20",
          "name": "Replace Me2",
          "type": "n8n-nodes-base.noOp",
          "position": [
            2688,
            -240
          ],
          "parameters": {},
          "typeVersion": 1
        },
        {
          "id": "e583104d-fd8c-498f-8b11-3d212a4cdc27",
          "name": "Get many labels1",
          "type": "n8n-nodes-base.gmail",
          "position": [
            2128,
            -240
          ],
          "webhookId": "84380596-7ef6-4fbf-b1f8-d179bcf23785",
          "parameters": {
            "resource": "label",
            "returnAll": true
          },
          "credentials": {
            "gmailOAuth2": {
              "id": "P75ucVf9LpvRaayr",
              "name": "yvesyiu7"
            }
          },
          "typeVersion": 2.2
        },
        {
          "id": "324a17c2-9e91-4523-bec9-e43e291ba5a2",
          "name": "Filter",
          "type": "n8n-nodes-base.filter",
          "position": [
            2320,
            -240
          ],
          "parameters": {
            "options": {},
            "conditions": {
              "options": {
                "version": 3,
                "leftValue": "",
                "caseSensitive": true,
                "typeValidation": "strict"
              },
              "combinator": "and",
              "conditions": [
                {
                  "id": "a8f93919-8b6f-42c4-a8cd-4b8179de1af5",
                  "operator": {
                    "type": "array",
                    "operation": "contains",
                    "rightType": "any"
                  },
                  "leftValue": "={{ $('Loop Over Items2').item.json.label }}",
                  "rightValue": "={{ $json.name }}"
                }
              ]
            }
          },
          "typeVersion": 2.3
        },
        {
          "id": "630db6cd-a005-42c0-b5b2-ac0de1abc603",
          "name": "Sticky Note",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            -128,
            -736
          ],
          "parameters": {
            "height": 80,
            "content": "Check and add labels"
          },
          "typeVersion": 1
        },
        {
          "id": "fcae46cd-9fc0-4eb5-ac14-21ccb3227ade",
          "name": "Sticky Note1",
          "type": "n8n-nodes-base.stickyNote",
          "position": [
            -144,
            -208
          ],
          "parameters": {
            "width": 288,
            "height": 96,
            "content": "Get latest Emails and Categorize them with labels"
          },
          "typeVersion": 1
        }
      ],
      "active": false,
      "pinData": {},
      "settings": {
        "availableInMCP": false,
        "executionOrder": "v1"
      },
      "versionId": "1ad22fcd-7ee6-4499-a434-b27b1e37a8f8",
      "connections": {
        "Filter": {
          "main": [
            [
              {
                "node": "Add label to message",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Aggregate": {
          "main": [
            [
              {
                "node": "Get Labels1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Aggregate1": {
          "main": [
            [
              {
                "node": "Loop Over Items",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Get Labels": {
          "main": [
            [
              {
                "node": "Aggregate Labels with Description",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Replace Me": {
          "main": [
            [
              {
                "node": "Loop Over Items",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Csv to Json": {
          "main": [
            [
              {
                "node": "Append or update row in sheet",
                "type": "main",
                "index": 0
              },
              {
                "node": "Loop Over Items2",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Edit Fields": {
          "main": [
            [
              {
                "node": "Get Labels",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Get Labels1": {
          "main": [
            [
              {
                "node": "Loop Over Items1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Replace Me1": {
          "main": [
            [
              {
                "node": "Loop Over Items1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Replace Me2": {
          "main": [
            [
              {
                "node": "Loop Over Items2",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Check Labels": {
          "main": [
            [
              {
                "node": "Edit Fields2",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Edit Fields2": {
          "main": [
            [
              {
                "node": "Get many labels2",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Create a label": {
          "main": [
            [
              {
                "node": "Replace Me1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Get Label Exist": {
          "main": [
            [
              {
                "node": "Aggregate",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Loop Over Items": {
          "main": [
            [
              {
                "node": "Csv to Json",
                "type": "main",
                "index": 0
              }
            ],
            [
              {
                "node": "Categorize Emails with AI",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Get many labels1": {
          "main": [
            [
              {
                "node": "Filter",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Get many labels2": {
          "main": [
            [
              {
                "node": "Append or update row in sheet1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Loop Over Items1": {
          "main": [
            [],
            [
              {
                "node": "Check if Label Exist",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Loop Over Items2": {
          "main": [
            [],
            [
              {
                "node": "Get many labels1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Schedule Trigger": {
          "main": [
            [
              {
                "node": "Edit Fields",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Get many messages": {
          "main": [
            [
              {
                "node": "Append row in sheet",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Append row in sheet": {
          "main": [
            [
              {
                "node": "Aggregate1",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Add label to message": {
          "main": [
            [
              {
                "node": "Replace Me2",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Check if Label Exist": {
          "main": [
            [
              {
                "node": "Replace Me1",
                "type": "main",
                "index": 0
              }
            ],
            [
              {
                "node": "Create a label",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Google Gemini Chat Model": {
          "ai_languageModel": [
            [
              {
                "node": "Categorize Emails with AI",
                "type": "ai_languageModel",
                "index": 0
              }
            ]
          ]
        },
        "Categorize Emails with AI": {
          "main": [
            [
              {
                "node": "Replace Me",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Append or update row in sheet": {
          "main": [
            []
          ]
        },
        "Append or update row in sheet1": {
          "main": [
            [
              {
                "node": "Get Label Exist",
                "type": "main",
                "index": 0
              }
            ]
          ]
        },
        "Aggregate Labels with Description": {
          "main": [
            [
              {
                "node": "Get many messages",
                "type": "main",
                "index": 0
              }
            ]
          ]
        }
      }
    }