cd /news/ai-agents/how-to-route-rag-results-into-busine… · home › topics › ai-agents › article
[ARTICLE · art-182386] src=pub.towardsai.net ↗ pub= topic=ai-agents verified=true sentiment=· neutral

How to Route Rag Results Into Business Applications Or Emails

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.

recommendation

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.

more in playbook: Retrieval and RAG
by read4 min views1 publishedDec 5, 2026

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.

Here 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.

A 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.

Picture 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.

Routing RAG results means doing those same five jobs for an AI answer.

Start with the label. A sorting office does not open every letter to decide where it goes; it reads the label.

Software 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:

{ “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”]}

Each 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.

One 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.

Next comes sorting. With the fields in place, routing is a few simple rules. In Python:

def route(answer):  if not answer["answer_found"]:    return "human"  if answer["category"] == "billing":    return "review"  if answer["category"] == "general":    return "auto_send"return "human"

The last line matters most. Anything the rules do not recognise goes to a person. Make the safe path your default.

This is the checking desk, often called human-in-the-loop. Send an answer to a person first in three cases:

Maya’s email goes to review. It involves money, and 45 days falls outside the standard refund window.

Delivery 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.

Then 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.

In code, each stage is its own script, plus a separate connection for every app. In n8n, each stage is a node in one visual workflow, and Gmail, Slack, and Zendesk are ready-made nodes.

This walkthrough assumes your policy documents are already stored in a vector store.

Here is the prompt for step 4:

Reply 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) }}

Parse the answer in a chain, not an agent: The n8n docs note that structured output parsing is often unreliable with agents. That is why this workflow uses a Basic LLM Chain.

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.

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 }}.

Handle returns: Turn on Retry On Fail in the settings of the Gmail and Zendesk nodes. Then build a second workflow that starts with an Error Trigger node and posts to Slack. Publish it, and select it under Error workflow in the main workflow’s settings. It only runs for automatic executions, so a manual test will not trigger it.

For a larger version of this pattern, see the n8n template “Draft and review grounded support email replies with Gmail, OpenAI and Claude.”

How to Route Rag Results Into Business Applications Or Emails was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.

── more in #ai-agents 4 stories · sorted by recency
── more on @n8n 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-to-route-rag-res…] indexed:0 read:4min 2026-12-05 · —