{
  "name": "M12 Golden set scorer",
  "nodes": [
    {
      "parameters": {},
      "id": "29e4dcd7-0a0d-45ed-8f1d-0ac6ded861d7",
      "name": "Run once",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "operation": "read",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "PICK-THE-M12-MONITORING-WORKBOOK"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Golden set"
        },
        "options": {}
      },
      "id": "0a64b546-d6d5-4e84-a78d-d3ba04cb8dc0",
      "name": "Read golden set",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "f9154f62-f3eb-4afd-8178-9b64f79b15f0",
              "leftValue": "={{ $json.id }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "id": "7bc186a7-295c-420a-b6dd-08dae700e943",
      "name": "Only golden rows",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "25ce526f-1a43-4f58-aa38-cf8f2ce60990",
              "name": "version",
              "value": "v1",
              "type": "string"
            },
            {
              "id": "2943951b-1bfe-4235-b3e8-87c9bd613630",
              "name": "change",
              "value": "v1: the Session 10 classifier",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "d9739e6b-294b-4777-ac4a-4382c033902b",
      "name": "Prompt version",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        660,
        0
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=You classify incoming customer emails for a small software company.\nRead the email below and reply with exactly one label from this list:\nbilling, technical, sales, unsure\nRules:\n- billing: invoices, payments, refunds, subscription changes\n- technical: errors, login problems, how-to questions about the product\n- sales: pricing, demos, new licences, partnerships\n- unsure: anything else, or if two labels fit equally well\nReply with the label, a vertical bar, and a confidence from 1 (a guess) to 5 (certain), for example: billing|4\nNothing else: no punctuation, no explanation.\nEmail subject: {{ $json.subject }}\nEmail body: {{ $json.body }}",
        "batching": {}
      },
      "id": "a9c060a4-8293-4ff6-b080-ed259659e96a",
      "name": "Classify",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        880,
        0
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.5-flash",
        "options": {
          "temperature": 0
        }
      },
      "id": "f47d6fec-10a9-44fa-8bab-64a35b8a0c77",
      "name": "Gemini (flash)",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        920,
        240
      ],
      "credentials": {
        "googlePalmApi": {
          "id": null,
          "name": "",
          "__aiGatewayManaged": true
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f2359739-1659-48bc-a54f-fae3983693b3",
              "name": "version",
              "value": "={{ $('Prompt version').item.json.version }}",
              "type": "string"
            },
            {
              "id": "fab3d436-0ed8-4385-aa3c-9096b9d33262",
              "name": "item",
              "value": "={{ $('Prompt version').item.json.id }}",
              "type": "number"
            },
            {
              "id": "1254b6cd-b58c-4d4d-bdb7-d71b70eb3312",
              "name": "expected",
              "value": "={{ $('Prompt version').item.json.agreed }}",
              "type": "string"
            },
            {
              "id": "cba17b2b-78df-41ab-b762-b137b2f831da",
              "name": "got",
              "value": "={{ ($json.text || '').split('|')[0].trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "b32a380e-233f-413f-a3bc-f8c358a7a4a2",
              "name": "confidence",
              "value": "={{ (($json.text || '').split('|')[1] || '').trim() }}",
              "type": "string"
            },
            {
              "id": "01232b3b-0a15-4943-848b-49b4044fb9f9",
              "name": "correct",
              "value": "={{ ($json.text || '').split('|')[0].trim().toLowerCase() === String($('Prompt version').item.json.agreed).trim().toLowerCase() ? 1 : 0 }}",
              "type": "number"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "id": "6bf6305b-5d61-4ed5-ace7-44bddedd211d",
      "name": "Compare",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1200,
        0
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "PICK-THE-M12-MONITORING-WORKBOOK"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Scores"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "value": {
            "version": "={{ $json.version }}",
            "item": "={{ $json.item }}",
            "expected": "={{ $json.expected }}",
            "got": "={{ $json.got }}",
            "confidence": "={{ $json.confidence }}",
            "correct": "={{ $json.correct }}"
          },
          "schema": [
            {
              "id": "version",
              "displayName": "version",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "item",
              "displayName": "item",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "expected",
              "displayName": "expected",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "got",
              "displayName": "got",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "confidence",
              "displayName": "confidence",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "correct",
              "displayName": "correct",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "id": "22cca7f6-1b1f-48a6-8110-f30c4fb36918",
      "name": "Append scores",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1440,
        -120
      ]
    },
    {
      "parameters": {
        "fieldsToSummarize": {
          "values": [
            {
              "aggregation": "sum",
              "field": "correct"
            },
            {
              "aggregation": "count",
              "field": "item"
            }
          ]
        },
        "options": {}
      },
      "id": "9584d3a0-f29d-49a0-b62a-36dc4a701f03",
      "name": "Add up",
      "type": "n8n-nodes-base.summarize",
      "typeVersion": 1.1,
      "position": [
        1440,
        140
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "PICK-THE-M12-MONITORING-WORKBOOK"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Changelog"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "value": {
            "date": "={{ $now.toFormat('yyyy-MM-dd') }}",
            "version": "={{ $('Prompt version').first().json.version }}",
            "change": "={{ $('Prompt version').first().json.change }}",
            "score": "={{ $json.sum_correct }}",
            "out_of": "={{ $json.count_item }}",
            "kept": "pending",
            "by": ""
          },
          "schema": [
            {
              "id": "date",
              "displayName": "date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "version",
              "displayName": "version",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "change",
              "displayName": "change",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "score",
              "displayName": "score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "out_of",
              "displayName": "out_of",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "kept",
              "displayName": "kept",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "by",
              "displayName": "by",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "id": "7f862fe6-4bc0-4818-959e-c2254d5d4f87",
      "name": "Append changelog",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1680,
        140
      ]
    },
    {
      "parameters": {
        "content": "## M12 Golden set scorer (lab part B)\nReads the **Golden set** tab, runs every e-mail through **Classify** with the prompt in that node, and compares the answer with the agreed label. One **Scores** row per item (compare per item!) and one **Changelog** row with the total.\n\nStep 3: Execute workflow as it is (v1). Step 4: in **Prompt version** set version `v2` and describe the change; in **Classify** replace the rules with the v2 text (sticky below). Step 5: Execute again, compare v1 and v2 in Scores, set `kept` in Changelog.",
        "width": 760,
        "height": 250,
        "color": 5
      },
      "id": "1a8ce85c-a1ba-4239-8f58-fabbe15b4807",
      "name": "Note 79a1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -400
      ]
    },
    {
      "parameters": {
        "content": "## Prompt v2 (one change: definitions + one example per category, none from the golden set)\n```\nYou classify incoming customer emails for a small software company.\nRead the email below and reply with exactly one label from this list:\nbilling, technical, sales, unsure\nRules:\n- billing: invoices, payments, refunds, cancellations, tax documents, and any change to an EXISTING subscription (seats, plan, billing period)\n- technical: errors, slowness, login or two-factor problems, how-to questions, bug and security reports about the product\n- sales: pricing, quotes, demos, a NEW workspace or new customer (even from an existing client), partnerships and resellers\n- unsure: not about our product (job applications, events, invitations), or a case two teams must handle together (for example a payment problem that locked an account)\nExamples:\n- \"Our card expired, please update it and re-run the payment\" -> billing\n- \"The mobile app crashes when I open notifications\" -> technical\n- \"Can you send a quote for 100 seats for our new office?\" -> sales\n- \"Invitation to speak at our meetup next month\" -> unsure\nReply with the label, a vertical bar, and a confidence from 1 (a guess) to 5 (certain), for example: billing|4\nNothing else: no punctuation, no explanation.\n```",
        "width": 760,
        "height": 470,
        "color": 4
      },
      "id": "bfaf245a-fd57-4b58-8b86-ca855ce98981",
      "name": "Note c725",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        760,
        -620
      ]
    }
  ],
  "connections": {
    "Run once": {
      "main": [
        [
          {
            "node": "Read golden set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read golden set": {
      "main": [
        [
          {
            "node": "Only golden rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Only golden rows": {
      "main": [
        [
          {
            "node": "Prompt version",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prompt version": {
      "main": [
        [
          {
            "node": "Classify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini (flash)": {
      "ai_languageModel": [
        [
          {
            "node": "Classify",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Classify": {
      "main": [
        [
          {
            "node": "Compare",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compare": {
      "main": [
        [
          {
            "node": "Append scores",
            "type": "main",
            "index": 0
          },
          {
            "node": "Add up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add up": {
      "main": [
        [
          {
            "node": "Append changelog",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Amman"
  },
  "meta": {}
}