{
  "name": "05 · Customer Support / AI Reply Copilot with Guardrails",
  "active": false,
  "nodes": [
    {
      "id": "eabfcb60-928e-4aa8-a7ed-fd70f7ff92e6",
      "name": "📘 Guide",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -640,
        -120
      ],
      "parameters": {
        "content": "## 05 · Customer Support · AI Reply Copilot with Guardrails\n\n### What this does\nDrafts replies from KB snippets, runs hallucination/PII checks, and posts draft to agent for approve-send.\n\n### Setup checklist\n1. KB search HTTP\n2. LLM\n3. Helpdesk draft API\n\n### How to test locally\nPOST `support-ai-draft` with `{ \"ticketId\":\"1\", \"message\":\"...\" }`\n\n### Tips\n- Keep credentials in n8n Credentials (never hardcode secrets).\n- Use **Test URL** on the Webhook while developing.\n- Activate only after credentials + destinations are configured.\n",
        "width": 560,
        "height": 560,
        "color": 2
      }
    },
    {
      "id": "e125f4dc-7876-45e9-82b4-f9fdb7064d1e",
      "name": "⚙️ Config",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -640,
        480
      ],
      "parameters": {
        "content": "## Config map\n\n- **Webhook path:** `support-ai-draft`\n- **Replace** all `https://httpbin.org/...` calls with real integrations.\n- **Credentials:** create in n8n → Credentials, then select on HTTP nodes.\n- **Activate** workflow only after a successful Test execution.\n\n### Local files\nShared host folder is mounted at `/files` inside n8n.",
        "width": 560,
        "height": 320,
        "color": 2
      }
    },
    {
      "id": "5012351e-faf7-4fd9-9c3c-dcbc8ee705a2",
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        200
      ],
      "webhookId": "6c297696-2ea1-4cfe-a9b0-c196163a54a9",
      "parameters": {
        "httpMethod": "POST",
        "path": "support-ai-draft",
        "responseMode": "responseNode",
        "options": {}
      }
    },
    {
      "id": "f1ebf7bc-4557-4c44-8eda-a208b81e6322",
      "name": "Build Prompt Context",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        280,
        200
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "system",
              "value": "You are an expert operator for: AI Reply Copilot with Guardrails",
              "type": "string"
            },
            {
              "id": "2",
              "name": "userInput",
              "value": "={{ $json.body || $json }}",
              "type": "object"
            },
            {
              "id": "3",
              "name": "model",
              "value": "gpt-4.1-mini",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "a12b736f-b0e3-4a81-8da5-e53292fb2ad3",
      "name": "AI Transform (swap for LLM node)",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        560,
        200
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const ctx = $input.first().json;\nconst input = ctx.userInput || {};\n// Placeholder \"model\" output — replace this Code node with OpenAI/Anthropic node.\nconst draft = {\n  summary: `Generated by AI Reply Copilot with Guardrails`,\n  bullets: Object.keys(input).slice(0, 8).map(k => `${k}: ${JSON.stringify(input[k]).slice(0,120)}`),\n  score: Math.round(60 + Math.random()*40),\n  recommendations: ['Review tone', 'Add CTA', 'Fact-check claims'],\n};\nreturn [{ json: { ...ctx, ai: draft, ready: draft.score >= 70 } }];"
      }
    },
    {
      "id": "197d50dc-aded-443c-925d-7350af74c36f",
      "name": "Quality Gate",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        840,
        200
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "b5a18372-2806-416b-b717-47f96046ea1a",
              "leftValue": "={{ $json.ready }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "c1332326-9dd3-4b2b-bf64-29708f705120",
      "name": "Persist / Publish",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        80
      ],
      "parameters": {
        "method": "POST",
        "url": "https://httpbin.org/post",
        "options": {},
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}"
      }
    },
    {
      "id": "11ea69bf-544c-47eb-ad61-c3a1e041a17b",
      "name": "Needs Human Review",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1120,
        320
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "1",
              "name": "review",
              "value": true,
              "type": "boolean"
            },
            {
              "id": "2",
              "name": "reason",
              "value": "AI quality score below threshold",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "ba71c01f-8424-4deb-8787-19cb82e532c5",
      "name": "Webhook Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1400,
        200
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Build Prompt Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Prompt Context": {
      "main": [
        [
          {
            "node": "AI Transform (swap for LLM node)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Transform (swap for LLM node)": {
      "main": [
        [
          {
            "node": "Quality Gate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Quality Gate": {
      "main": [
        [
          {
            "node": "Persist / Publish",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Needs Human Review",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Persist / Publish": {
      "main": [
        [
          {
            "node": "Webhook Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs Human Review": {
      "main": [
        [
          {
            "node": "Webhook Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "callerPolicy": "workflowsFromSameOwner"
  },
  "tags": [],
  "meta": {
    "templateCredsSetupCompleted": true,
    "description": "Drafts replies from KB snippets, runs hallucination/PII checks, and posts draft to agent for approve-send."
  },
  "pinData": {}
}