{
  "name": "M12 Reply judge",
  "nodes": [
    {
      "parameters": {},
      "id": "9b628961-9ac5-48ab-ad1e-3f665ef4fbd7",
      "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": "Drafts"
        },
        "options": {}
      },
      "id": "d5cbd6b6-bed5-45c3-8eff-0f755fc2da4c",
      "name": "Read drafts",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        220,
        0
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "97df7c08-b245-4203-8646-0c037dce31ad",
              "leftValue": "={{ $json.id }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "id": "4c2d4137-3ed9-4eb3-b175-5bd5a6d3a47c",
      "name": "Only draft rows",
      "type": "n8n-nodes-base.filter",
      "typeVersion": 2.2,
      "position": [
        440,
        0
      ]
    },
    {
      "parameters": {
        "text": "={{ \"Customer e-mail (subject: \" + $json.customer_subject + \"):\\n<<<\\n\" + $json.customer_email + \"\\n>>>\\n\\nDraft reply:\\n<<<\\n\" + $json.draft + \"\\n>>>\" }}",
        "schemaType": "fromAttributes",
        "attributes": {
          "attributes": [
            {
              "name": "answers_question",
              "type": "string",
              "description": "\"yes\" or \"no\": Answers the customer's actual question.",
              "required": true
            },
            {
              "name": "no_invented_facts",
              "type": "string",
              "description": "\"yes\" or \"no\": Contains no invented facts (prices, dates, policies).",
              "required": true
            },
            {
              "name": "tone_ok",
              "type": "string",
              "description": "\"yes\" or \"no\": Matches the tone guide (polite, brief, no jargon).",
              "required": true
            },
            {
              "name": "safe_to_send",
              "type": "string",
              "description": "\"yes\" or \"no\": Safe to send without legal or financial commitment.",
              "required": true
            },
            {
              "name": "reason",
              "type": "string",
              "description": "One line, at most 25 words: the main reason for any \"no\", or \"all four checks pass\".",
              "required": true
            }
          ]
        },
        "options": {
          "systemPromptTemplate": "You are a strict reviewer of customer-support reply drafts for a small software company. You apply a four-check rubric and answer each check with yes or no, then give a one-line reason. The support team may only say what happens next and that a colleague will follow up. Any promised refund, timing, discount, price, date or fix is an invented fact AND makes the draft unsafe to send. Tone: polite, brief, no jargon, addressed to the customer by name when the e-mail gives one. 'Answers the question' means the customer's actual request is addressed, not a generic thank-you."
        }
      },
      "id": "5c38451f-4272-40f0-aed3-f30c3afaef91",
      "name": "Judge",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        660,
        0
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.5-pro",
        "options": {
          "temperature": 0
        }
      },
      "id": "14541437-27a6-43ef-914d-c7bdbb1e4262",
      "name": "Gemini (pro)",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        700,
        240
      ],
      "credentials": {
        "googlePalmApi": {
          "id": null,
          "name": "",
          "__aiGatewayManaged": true
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "d6293bab-3ecb-4f25-9bcf-667bfa8ef4e9",
              "name": "run_at",
              "value": "={{ $now.toFormat('yyyy-MM-dd HH:mm:ss') }}",
              "type": "string"
            },
            {
              "id": "3448b492-5c97-4fb9-a367-4f0711a22202",
              "name": "id",
              "value": "={{ $('Only draft rows').item.json.id }}",
              "type": "number"
            },
            {
              "id": "dce2070e-8b81-4bf0-aa7e-7de1b23b9a8c",
              "name": "answers_question",
              "value": "={{ String($json.output.answers_question).trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "8505d7d4-5fcd-48c5-928e-c1ef76a98801",
              "name": "no_invented_facts",
              "value": "={{ String($json.output.no_invented_facts).trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "827b8faa-4e19-4dc8-9672-09dbd6363e85",
              "name": "tone_ok",
              "value": "={{ String($json.output.tone_ok).trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "274fc1d7-7911-4148-9b79-3977691ff2a2",
              "name": "safe_to_send",
              "value": "={{ String($json.output.safe_to_send).trim().toLowerCase() }}",
              "type": "string"
            },
            {
              "id": "9e0458d4-6abb-4a89-bd17-6d70a885ff61",
              "name": "judge_total",
              "value": "={{ (String($json.output.answers_question).trim().toLowerCase() === 'yes' ? 1 : 0) + (String($json.output.no_invented_facts).trim().toLowerCase() === 'yes' ? 1 : 0) + (String($json.output.tone_ok).trim().toLowerCase() === 'yes' ? 1 : 0) + (String($json.output.safe_to_send).trim().toLowerCase() === 'yes' ? 1 : 0) }}",
              "type": "number"
            },
            {
              "id": "24fbe589-b9c2-4b4f-9b00-aae0b1807963",
              "name": "human_total",
              "value": "={{ $('Only draft rows').item.json.human_total }}",
              "type": "number"
            },
            {
              "id": "2e2c74b0-4952-4a3b-af81-15687c7b6852",
              "name": "agree",
              "value": "={{ ((String($json.output.answers_question).trim().toLowerCase() === 'yes' ? 1 : 0) + (String($json.output.no_invented_facts).trim().toLowerCase() === 'yes' ? 1 : 0) + (String($json.output.tone_ok).trim().toLowerCase() === 'yes' ? 1 : 0) + (String($json.output.safe_to_send).trim().toLowerCase() === 'yes' ? 1 : 0)) === Number($('Only draft rows').item.json.human_total) ? 'yes' : 'no' }}",
              "type": "string"
            },
            {
              "id": "0884b49c-eaf5-48ab-a1a8-3b14c56d52c9",
              "name": "reason",
              "value": "={{ $json.output.reason }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "id": "9783e9d5-e21b-49f3-a71d-5ee1db31426c",
      "name": "Score",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        980,
        0
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "PICK-THE-M12-MONITORING-WORKBOOK"
        },
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": "Judge"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "value": {
            "run_at": "={{ $json.run_at }}",
            "id": "={{ $json.id }}",
            "answers_question": "={{ $json.answers_question }}",
            "no_invented_facts": "={{ $json.no_invented_facts }}",
            "tone_ok": "={{ $json.tone_ok }}",
            "safe_to_send": "={{ $json.safe_to_send }}",
            "judge_total": "={{ $json.judge_total }}",
            "human_total": "={{ $json.human_total }}",
            "agree": "={{ $json.agree }}",
            "reason": "={{ $json.reason }}"
          },
          "schema": [
            {
              "id": "run_at",
              "displayName": "run_at",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "id",
              "displayName": "id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "answers_question",
              "displayName": "answers_question",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "no_invented_facts",
              "displayName": "no_invented_facts",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "tone_ok",
              "displayName": "tone_ok",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "safe_to_send",
              "displayName": "safe_to_send",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "judge_total",
              "displayName": "judge_total",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "human_total",
              "displayName": "human_total",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "agree",
              "displayName": "agree",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "reason",
              "displayName": "reason",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {
          "cellFormat": "RAW"
        }
      },
      "id": "4acdb079-d2f8-458d-a3ec-6d8785c5f415",
      "name": "Append judge",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.5,
      "position": [
        1220,
        0
      ]
    },
    {
      "parameters": {
        "content": "## M12 Reply judge (lab part C)\nA second model applies the reply-draft rubric to every row of the **Drafts** tab and writes a **Judge** row: four yes/no checks, a total out of 4, the human total next to it, and `agree`.\n\nThe rule: a person scores the golden set; the judge scores everything else; a person checks a sample of the judge's scores each month. The judge is Gemini 2.5 Pro (Session 9: Flash-Lite as a critic invented objections).",
        "width": 720,
        "height": 220,
        "color": 5
      },
      "id": "167b9188-cc1b-4322-9c20-960d3aefd0e9",
      "name": "Note 5f27",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        -330
      ]
    }
  ],
  "connections": {
    "Run once": {
      "main": [
        [
          {
            "node": "Read drafts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read drafts": {
      "main": [
        [
          {
            "node": "Only draft rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Only draft rows": {
      "main": [
        [
          {
            "node": "Judge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini (pro)": {
      "ai_languageModel": [
        [
          {
            "node": "Judge",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Judge": {
      "main": [
        [
          {
            "node": "Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Score": {
      "main": [
        [
          {
            "node": "Append judge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1",
    "timezone": "Asia/Amman"
  },
  "meta": {}
}