{
  "name": "Jev · ticket routing with a confidence threshold",
  "nodes": [
    {
      "id": "n1",
      "name": "Note n1",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -80,
        -380
      ],
      "parameters": {
        "content": "## 1. Credential\nCreate a **Header Auth** credential:\n- Name: `Authorization`\n- Value: `Bearer YOUR_JEV_KEY`\n\nSelect it in the **Jev: department and urgency** node.",
        "width": 380,
        "height": 260
      }
    },
    {
      "id": "n2",
      "name": "Note n2",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        320,
        -380
      ],
      "parameters": {
        "content": "## 2. Before production\n- Calibrate the threshold on your tickets, in your language.\n- Start in shadow mode: log without acting.\n- Pseudonymise personal data before sending: Jev is hosted in the United States.\n\nFull guide: https://jevmigration.com/en/blog/jev-n8n/",
        "width": 380,
        "height": 260
      }
    },
    {
      "id": "trigger",
      "name": "Test workflow",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        0
      ],
      "parameters": {}
    },
    {
      "id": "input",
      "name": "Ticket and settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        0
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "input-0",
              "name": "ticket",
              "value": "Hi, my September invoice shows up twice on my statement. Can you refund the duplicate?",
              "type": "string"
            },
            {
              "id": "input-1",
              "name": "threshold",
              "value": 0.6,
              "type": "number"
            },
            {
              "id": "input-2",
              "name": "model",
              "value": "jev-1.13.0",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "jev",
      "name": "Jev: department and urgency",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        440,
        0
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 1000,
      "onError": "continueErrorOutput",
      "parameters": {
        "method": "POST",
        "url": "https://api.typesafe.ai/v1/systemone",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"state\": {{ JSON.stringify($json.ticket) }},\n  \"model\": \"{{ $json.model }}\",\n  \"questions\": {\n    \"department\": {\n      \"type\": \"choice\",\n      \"instructions\": \"Which team should handle this ticket?\",\n      \"criteria\": {\n        \"billing\": \"Payments, invoices, refunds\",\n        \"technical\": \"Bugs, outages, integrations\",\n        \"sales\": \"Pricing, quotes, new accounts\"\n      }\n    },\n    \"urgent\": {\n      \"type\": \"noul\",\n      \"instructions\": \"Does the message express urgency?\"\n    }\n  }\n}",
        "options": {
          "timeout": 5000
        }
      }
    },
    {
      "id": "log",
      "name": "Decision log",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        680,
        -100
      ],
      "parameters": {
        "mode": "manual",
        "assignments": {
          "assignments": [
            {
              "id": "log-0",
              "name": "model_version",
              "value": "={{ $json.model }}",
              "type": "string"
            },
            {
              "id": "log-1",
              "name": "department",
              "value": "={{ $json.answers.department.choice }}",
              "type": "string"
            },
            {
              "id": "log-2",
              "name": "confidence",
              "value": "={{ $json.answers.department.confidence }}",
              "type": "number"
            },
            {
              "id": "log-3",
              "name": "probabilities",
              "value": "={{ $json.answers.department.probabilities }}",
              "type": "object"
            },
            {
              "id": "log-4",
              "name": "urgency",
              "value": "={{ $json.answers.urgent.noul }}",
              "type": "number"
            },
            {
              "id": "log-5",
              "name": "threshold",
              "value": "={{ $('Ticket and settings').item.json.threshold }}",
              "type": "number"
            },
            {
              "id": "log-6",
              "name": "decided_by",
              "value": "={{ $json.answers.department.confidence >= $('Ticket and settings').item.json.threshold ? 'jev' : 'llm' }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "gate",
      "name": "Is Jev sure enough?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        900,
        -100
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "gate-0",
              "leftValue": "={{ $json.decided_by }}",
              "rightValue": "jev",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      }
    },
    {
      "id": "route",
      "name": "Route by department",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        1120,
        -200
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "route-0",
                    "leftValue": "={{ $json.department }}",
                    "rightValue": "billing",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Billing"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "route-1",
                    "leftValue": "={{ $json.department }}",
                    "rightValue": "technical",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Technical"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "route-2",
                    "leftValue": "={{ $json.department }}",
                    "rightValue": "sales",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Sales"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "out-0",
      "name": "Billing",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1360,
        -320
      ],
      "parameters": {}
    },
    {
      "id": "out-1",
      "name": "Technical",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1360,
        -200
      ],
      "parameters": {}
    },
    {
      "id": "out-2",
      "name": "Sales",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1360,
        -80
      ],
      "parameters": {}
    },
    {
      "id": "fallback",
      "name": "Fallback: your current LLM",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1120,
        120
      ],
      "parameters": {}
    }
  ],
  "connections": {
    "Test workflow": {
      "main": [
        [
          {
            "node": "Ticket and settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ticket and settings": {
      "main": [
        [
          {
            "node": "Jev: department and urgency",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Jev: department and urgency": {
      "main": [
        [
          {
            "node": "Decision log",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fallback: your current LLM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decision log": {
      "main": [
        [
          {
            "node": "Is Jev sure enough?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Jev sure enough?": {
      "main": [
        [
          {
            "node": "Route by department",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fallback: your current LLM",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route by department": {
      "main": [
        [
          {
            "node": "Billing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Technical",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Sales",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
