{"slug": "how-to-route-rag-results-into-business-applications-or-emails", "title": "How to Route Rag Results Into Business Applications Or Emails", "summary": "An n8n guide lays out a five-stage pattern for routing retrieval-augmented generation (RAG) answers into business applications and email inboxes, using a customer refund request as its running example. The guide instructs builders to have the model return structured output with named fields — reply_text, category, answer_found and sources — then route on simple rules, defaulting anything unrecognized to a human reviewer, and to send answers to a person first when money, missing source documents or low confidence are involved. The guide recommends a plain yes-or-no answer_found field over a model-generated confidence score, noting that models tend to sound sure even when they are wrong.", "body_md": "Most RAG tutorials end when the AI gives a good answer. In a business, that is where the work starts. This guide shows you how to route RAG results: how to shape an answer, decide where it goes, get a human to check it when needed, and deliver it to an inbox or a business app. We will follow one example throughout: a customer asking for a refund.\n\nHere is the example: Maya uses a project management app called Relay. She emails support: “I bought the annual plan 45 days ago. Can I get a refund?” Relay’s policy gives a full refund within 30 days. After that, the billing team decides on a case-by-case basis.\n\nA RAG system can find that policy and write a good reply. But someone still has to send the reply, tell the billing team, and make sure nothing risky goes out unchecked. Routing does that work.\n\nPicture a sorting office: RAG writes the letter, but a letter that stays on the writer’s desk helps no one. So the sorting office does five jobs: it labels the letter, sorts it, checks it, delivers it, and handles returns.\n\nRouting RAG results means doing those same five jobs for an AI answer.\n\nStart with the label. A sorting office does not open every letter to decide where it goes; it reads the label.\n\nSoftware works the same way. A RAG answer is one block of text, and an app cannot tell which part is the reply, what the question is about, or whether it is safe to send. So you ask the model to return its answer as a short list of named fields, where each field holds one piece of information. This is called structured output. For Maya’s email, it looks like this:\n\n```\n{ “reply_text”: “Hi Maya, thanks for writing in. Full refunds cover the first 30 days, so I have passed your request to our billing team. They review requests like yours case by case and will follow up by email.”, “category”: “billing”, “answer_found”: true, “sources”: [“refund-policy.pdf”]}\n```\n\nEach field has a job: reply_text is the answer itself, category says what the question is about, answer_found says whether the documents actually covered the question, and sources lists the documents the answer came from, so a person can check it.\n\nOne tip from practice: ask for a plain yes or no in answer_found instead of a confidence score. Models tend to sound sure even when they are wrong, so a score they give themselves tells you little.\n\nNext comes sorting. With the fields in place, routing is a few simple rules. In Python:\n\n``` python\ndef route(answer):  if not answer[\"answer_found\"]:    return \"human\"  if answer[\"category\"] == \"billing\":    return \"review\"  if answer[\"category\"] == \"general\":    return \"auto_send\"return \"human\"\n```\n\nThe last line matters most. Anything the rules do not recognise goes to a person. Make the safe path your default.\n\nThis is the checking desk, often called [human-in-the-loop](https://blog.n8n.io/human-in-the-loop-automation). Send an answer to a person first in three cases:\n\nMaya’s email goes to review. It involves money, and 45 days falls outside the standard refund window.\n\nDelivery means writing to the real tools: sending the email, creating the ticket, posting the message. Keep the sources attached, so the person reading the answer can check it.\n\nThen plan for returns. Apps go down, requests time out, and tools reject data in the wrong shape. A good system retries, and if that fails, it alerts someone. An answer should never get lost quietly.\n\nIn code, each stage is its own script, plus a separate connection for every app. In [n8n](https://n8n.io/), each stage is a node in one visual workflow, and Gmail, Slack, and Zendesk are ready-made nodes.\n\nThis walkthrough assumes your policy documents are [already stored in a vector store](https://docs.n8n.io/build/integrate-ai/understand-ai-components/retrieve-relevant-context).\n\nHere is the prompt for step 4:\n\n```\nReply to this customer email, using only the policy passages.Set category to \"billing\" or \"general\".Set answer_found to false if the passages do not answer the question.Customer email:{{ $('Gmail Trigger').first().json.text }}Policy passages:{{ JSON.stringify($json.data) }}\n```\n\n**Parse the answer in a chain, not an agent:** The [n8n docs note](https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.outputparserstructured/common-issues) that structured output parsing is often unreliable with agents. That is why this workflow uses a Basic LLM Chain.\n\n**Name the categories in your prompt:** A JSON example only fixes the field names and types. The prompt has to list the allowed values, and the Switch fallback catches anything unexpected.\n\n**Read the reply from the right node:** After approval, the Slack node outputs only the decision. In the Gmail node, get the reply with {{ $(‘Basic LLM Chain’).first().json.output.reply_text }}.\n\n**Handle returns:** Turn on [*Retry On Fail*](https://docs.n8n.io/build/understand-workflows/workflow-components/work-with-nodes#node-settings) in the settings of the Gmail and Zendesk nodes. Then build a second workflow that starts with an [**Error Trigger**](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.errortrigger/) node and posts to Slack. Publish it, and select it under [*Error workflow*](https://docs.n8n.io/build/flow-logic/handle-errors-gracefully) in the main workflow’s settings. It only runs for automatic executions, so a manual test will not trigger it.\n\nFor a larger version of this pattern, see the n8n template “[Draft and review grounded support email replies with Gmail, OpenAI and Claude](https://n8n.io/workflows/18957-draft-and-review-grounded-support-email-replies-with-gmail-openai-and-claude/).”\n\n[How to Route Rag Results Into Business Applications Or Emails](https://pub.towardsai.net/how-to-route-rag-results-into-business-applications-or-emails-0b07b1980910) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/how-to-route-rag-results-into-business-applications-or-emails", "canonical_source": "https://pub.towardsai.net/how-to-route-rag-results-into-business-applications-or-emails-0b07b1980910?source=rss----98111c9905da---4", "published_at": "2026-12-05 10:46:14+00:00", "updated_at": "2026-12-05 11:13:04.218565+00:00", "lang": "en", "topics": ["ai-agents", "structured-data", "ai-tools"], "entities": ["n8n", "Gmail", "Slack", "Zendesk", "Relay"], "also_reported_by": [], "takeaway": "Have the model return structured output with reply_text, category, answer_found and sources fields, then route on simple rules with an unrecognized-answer fallback to a human, and prefer a plain yes/no answer_found over a self-reported confidence score.", "recommendation": {"advice": "Return RAG answers as structured fields including a yes/no answer_found and sources, route with rules that default to human review, and send money-related or unsourced answers to a person before delivery.", "playbook": "rag-retrieval", "playbook_url": "https://wpnews.pro/playbooks/rag-retrieval"}, "alternates": {"html": "https://wpnews.pro/news/how-to-route-rag-results-into-business-applications-or-emails", "markdown": "https://wpnews.pro/news/how-to-route-rag-results-into-business-applications-or-emails.md", "text": "https://wpnews.pro/news/how-to-route-rag-results-into-business-applications-or-emails.txt", "jsonld": "https://wpnews.pro/news/how-to-route-rag-results-into-business-applications-or-emails.jsonld"}}