Sub topic 14
Writing instructions that keep answers grounded
This chapter assumes you have built a search index and a retriever over Knowledge content. It also assumes you have seen where a retriever plugs into a prompt template and into an agent's knowledge action. Here the focus is the natural-language instructions that tell the model what to do with the retrieved text.
Why instructions matter after retrieval works
A retriever returns excerpts. It does not force the model to use them. The model still reads your instructions and decides how to combine the excerpts with everything else it knows. If the instructions are loose, it can blend the excerpts with general knowledge, fill gaps with plausible guesses, or answer when the excerpts are empty.
Grounding instructions do three jobs:
- Limit the source of the answer to the retrieved content.
- Define what happens when the content does not contain the answer.
- Make the answer checkable, for example by naming the article it relied on.
Instructions are guidance to a probabilistic model. They reduce ungrounded answers but do not guarantee anything. Treat them as one layer, and verify behavior with the testing described in the next chapter.
Where instructions live
Grounding text can be written in two places, and they work together.
| Location | What it controls | Typical content |
|---|---|---|
| Prompt template (Prompt Builder) | One generation step, with retriever results inserted into the text | Source restriction, fallback wording, citation rule, tone |
| Agent topic instructions | When and how the agent calls its knowledge action, and what it does with the result | When to look up, base the reply only on returned articles, escalation |
A prompt template shapes a single model call. Topic instructions shape the agent's decisions across a conversation, including whether it retrieves at all. If you only harden the template, the agent can still skip the lookup and answer from general knowledge. If you only harden the topic, the template used inside the action may still allow outside knowledge.
Anatomy of a grounded prompt template
The template below restricts the source, defines a fallback, and asks for a citation. The bracketed lines stand for the retriever and input resources you add in Prompt Builder.
Answer the customer's question using only the knowledge article excerpts provided below.
If the excerpts do not contain the answer, say you could not find it and offer to connect the customer with a human agent.
Do not use outside knowledge. Mention the article title when you rely on an excerpt.
Excerpts:
<retriever results inserted here by the prompt template>
Question:
<customer question inserted here>Each line has a purpose:
- "using only the knowledge article excerpts" names the permitted source.
- "If the excerpts do not contain the answer" defines the empty-retrieval case explicitly. Without it, the model improvises.
- "Do not use outside knowledge" closes the common loophole directly.
- "Mention the article title" gives reviewers a way to check the answer against the source.
The excerpts come before the question. Keeping the retrieved data in a clearly labeled block helps the model tell evidence from the request.
Anatomy of agent topic instructions
For an agent, the instruction connects the reply to the knowledge action.
When a customer asks a product or policy question, use the knowledge action to look up the answer.
Base your reply only on the returned articles.
If no relevant article is returned, do not guess. Tell the customer you do not have that information and offer escalation.The first line says when to retrieve, so lookup is a rule and not an option. The second line limits the source. The third line handles the no-result case and gives the agent somewhere to send the customer.
flowchart TDWeak and strong instructions
Most grounding failures come from instructions that sound reasonable but leave a gap.
| Weak instruction | Problem | Stronger version |
|---|---|---|
| "Be helpful and answer the customer's question." | Rewards answering even without evidence | "Answer only if the excerpts support it." |
| "Use the articles when possible." | "When possible" permits outside knowledge | "Use only the articles. Do not use outside knowledge." |
| "Don't make things up." | States a goal but no behavior | "If no excerpt answers the question, say so and offer escalation." |
| "Cite your sources." | Unclear what counts as a source | "Mention the article title when you rely on an excerpt." |
| "Answer questions about our products." | No trigger for retrieval | "When a customer asks a product or policy question, use the knowledge action." |
The pattern: name the source, name the trigger, name the failure case, and say what to do in it.
Common errors
Missing fallback. The most frequent gap. When retrieval returns nothing or returns weak matches, an instruction with no fallback leaves the model to choose its own behavior, and it usually chooses to answer.
Conflicting layers. A template says "use only the excerpts" while a topic instruction says "always give the customer a complete answer." The model has to resolve the conflict, and it may favor completeness. Read the template, topic instructions, and any agent-level instructions together and remove contradictions.
Over-long instruction lists. Dozens of rules dilute each other. Keep the grounding rules short and put them where they apply. Move tone and formatting preferences elsewhere.
Expecting instructions to fix retrieval. If the right article is never retrieved, no wording will make the answer correct. A strict "only use the excerpts" instruction with poor retrieval produces more "I could not find it" replies. That is the correct behavior, but it points to a retrieval problem such as filters, chunking, or stale content. The troubleshooting chapter covers those.
Treating instructions as access control. "Do not reveal restricted articles" does not secure anything. What the model can see is decided by what the retriever returns and by sharing and governance settings, covered in the last chapter. Never rely on a prompt to hide content that should not be retrieved.
Overly rigid refusal. If the fallback is too strict, the agent may refuse when an excerpt partly answers the question. Decide whether partial answers are acceptable. If they are, say so: "If the excerpts answer only part of the question, answer that part and say what is missing."
Working through a revision
Start from this first draft of a topic instruction:
Help customers with questions about returns. Look in the knowledge articles if you need to, and be friendly.Review it against the checklist:
- Trigger: "if you need to" leaves retrieval to the model's judgment.
- Source: nothing prevents using general return-policy knowledge.
- Failure case: nothing is said about no results.
- Verifiability: no citation rule.
A revised version:
When a customer asks about returns, refunds, or exchanges, use the knowledge action to look up the answer.
Base your reply only on the returned articles and name the article title you used.
If no relevant article is returned, do not guess. Say you do not have that information and offer to connect the customer with a human agent.
Keep the tone friendly and brief.Tone is kept, but it comes last and does not compete with the grounding rules.
Iterating on instructions
Change one thing at a time and re-run the same test questions. Include three kinds of question: ones the articles answer, ones they only partly answer, and ones they do not cover at all. The third kind is the most revealing, because a well-grounded agent should use the fallback. The next chapter shows how to test systematically.
Exercise
An agent's topic instruction reads: "Answer product questions using our knowledge articles when possible, and always give the customer a complete answer." In testing, it answers a question about a discontinued product that no article covers. Name two problems in the instruction and rewrite it.
Show answer
Problems: (1) "when possible" allows outside knowledge, and there is no rule that retrieval must happen; (2) "always give a complete answer" conflicts with grounding and no fallback exists for missing articles. Rewrite: "When a customer asks a product question, use the knowledge action to look up the answer. Base your reply only on the returned articles and name the article title you used. If no relevant article is returned, do not guess. Say you do not have that information and offer escalation."
Exercise
Retrieval for a question returns an irrelevant article, and the agent, which has a strict "use only the excerpts" instruction, replies "I could not find it." Is the instruction the problem? Where should you look next?
Show answer
No. The instruction behaved correctly by refusing to answer from irrelevant content. Look at retrieval: the search index content and freshness, the chunking, the retriever's filters, returned fields, and result count.