{
  "name": "Country",
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "44a69fcd-4886-4f25-843c-9ab37bf2166c",
              "name": "given_country",
              "value": "={{ $json.query.given_country }}",
              "type": "string"
            },
            {
              "id": "db037e62-c4b8-4445-9ee0-508e2e665007",
              "name": "correct_country",
              "value": "={{ $json.query.correct_country }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        224,
        0
      ],
      "id": "bb66b03e-8f11-47ce-b7f9-30631398bd44",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Compare these country names:\n\ngiven_country: \"{{ $json.given_country }}\"\ncorrect_country: \"{{$json.correct_country}}\"\n\nReturn ONLY the JSON object in the format { \"isMatch\": true | false }.",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "You are an expert for validating country names.\n\nRules for matching given_country to correct_country:\n1. Only respond in the following JSON format: { \"isMatch\": true | false }.\n2. Accept minor typos:\n   - For long country names (>7 letters), up to 3 character edits.\n   - For short country names (\u22647 letters), up to 2 character edits.\n   - Minor swaps or missing letters are allowed.\n3. Accept official names, ISO codes, translations, and common abbreviations.\n4. Reject:\n   - Fantasies, invented names, or unrelated words.\n   - Words that are clearly wrong even with minor typos.\n5. Always return false if uncertain.\n6. Do not add explanations or text outside the JSON object.\n\nYour output MUST be valid JSON matching the schema."
        }
      },
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        448,
        0
      ],
      "id": "1ce1ea21-9ed0-4ec8-9bc4-1a202b046f76",
      "name": "AI Agent"
    },
    {
      "parameters": {
        "schemaType": "manual",
        "inputSchema": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"isMatch\": {\n      \"type\": \"boolean\",\n      \"description\": \"True if given_country refers to the same country as correct_country.\"\n    }\n  },\n  \"required\": [\"isMatch\"]\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        592,
        240
      ],
      "id": "1a599357-2fa9-4730-ae82-1097b3255134",
      "name": "Structured Output Parser"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        448,
        240
      ],
      "id": "25192621-5ea2-4d65-9a9a-1db308563209",
      "name": "OpenAI Chat Model",
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "path": "/country-validation",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        -48,
        -32
      ],
      "id": "3d430ce4-c1a6-4062-a79c-e71646dfb227",
      "name": "Webhook"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -16,
        144
      ],
      "id": "c9fb42b6-24b9-41f4-adda-f95e83afd3d0",
      "name": "When clicking \u2018Execute workflow\u2019"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.4,
      "position": [
        832,
        0
      ],
      "id": "d0de0869-0c54-4f92-8f41-4622f9925b4f",
      "name": "Respond to Webhook"
    }
  ],
  "connections": {
    "Edit Fields": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "AI Agent",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e4e7aa4f-0b64-4fb8-a7c0-06ec01470831",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "jIuYvqrvjSA0L27P",
  "tags": []
}