Sub topic 12
Grounding a prompt template with a retriever
This chapter shows how to connect a Data Cloud retriever to a prompt template in Prompt Builder, so the model answers from retrieved Knowledge excerpts. It assumes you can already do the following:
- Create a search index and a retriever over Knowledge content (earlier chapters).
- Navigate Setup and Prompt Builder as an administrator.
- Describe what a prompt template, an agent topic, and an action are.
What grounding a prompt template means
A prompt template is a reusable set of instructions with placeholders. Prompt Builder replaces the placeholders with real data when the template runs. This substitution is called grounding.
A retriever is one source of that data. When you add a retriever resource to a template, three things happen at run time:
- The template takes a query, usually the customer's question.
- The retriever searches the search index and returns the best-matching chunks.
- Prompt Builder inserts those chunks into the prompt text, and the model writes its answer from them.
The model never queries Data Cloud itself. The template runs the retrieval first and passes the results in as plain text. That means the quality of the answer depends on two things you control: what the retriever returns, and what the instructions tell the model to do with it.
Before you build the template
Check these items first. Most template problems that look like prompt problems are really data problems.
- The retriever returns results when tested on its own. Test it with a real question before you involve a prompt.
- The articles you expect are published. You can confirm which versions are live with this query:
SELECT Id, Title, UrlName, PublishStatus, Language, LastPublishedDate
FROM Knowledge__kav
WHERE PublishStatus = 'Online'
AND Language = 'en_US'
ORDER BY LastPublishedDate DESC
LIMIT 20- The retriever's returned fields include the ones you want the model to see. At minimum, return the chunk text and the article title. Add the article URL if you want the answer to cite sources.
- You have access to Prompt Builder and the permission to create templates in your org.
Build the template step by step
1. Choose the template type
In Prompt Builder, create a new template. Pick a type that fits the output you want. A Flex template is the general-purpose choice, because it lets you add any resources you need. Give the template a clear API name, such as Answer_From_Knowledge.
2. Add an input resource for the question
The template needs a value to search with. Add an input resource, for example a free-text input named CustomerQuestion. When an agent runs the template, it fills this input. When you test in Prompt Builder, you type a value in by hand.
3. Add the retriever resource
Insert a resource of the retriever type and select the retriever you created. Map its query to the CustomerQuestion input. Without this mapping, the retriever has nothing to search for and returns nothing.
If your retriever defines filters that accept runtime values, such as a language or product line, map those to inputs as well.
4. Write the instructions
Reference the resources inside the prompt text using merge-style placeholders. The wording matters as much as the wiring. This prompt restricts the model to the retrieved excerpts and defines what to do when retrieval finds nothing:
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>In Prompt Builder, the two bracketed lines are replaced by the retriever resource and the CustomerQuestion input that you insert from the resource picker. Do not type the brackets as literal text.
5. Preview with real questions
Use the preview pane and choose a sample input. Run at least three kinds of question:
- A question the articles answer clearly.
- A question the articles only partly answer.
- A question the articles do not cover at all.
The third case is the most important. A grounded template that invents an answer there has failed, even if the first two cases look good.
6. Save and activate
Save the template as a new version and activate it. Agents and flows can only use an active version. Edits after activation create a new draft, so the live behavior does not change until you activate again.
What the model actually receives
Preview shows the resolved prompt, with the retrieved text filled in. Read it. It is the quickest way to find out why an answer went wrong. Look for these patterns:
| What you see in the resolved prompt | Likely cause |
|---|---|
| The excerpts section is empty | The query mapping is missing, the filter excludes everything, or the index has no matching content |
| Excerpts are present but off-topic | The retriever's ranking is weak for this phrasing, or the index contains noisy chunks |
| The right article appears but the answer is wrong | The instruction is too loose, or the chunk cut off the key sentence |
| The same article appears several times | Multiple chunks from one article fill the result count |
| Old policy text appears | The index has not refreshed since the article changed |
Edge cases and common errors
- Empty retrieval, confident answer. If the instructions only say "answer the question," the model falls back on general knowledge when the excerpts are empty. Always include an explicit rule for the empty case, as the sample prompt does.
- Too many results. Raising the result count adds context but also adds noise and prompt length. Start small and increase only if answers miss relevant material.
- Query is the whole conversation. If an agent passes a long, multi-turn message as the query, retrieval quality drops. Prefer a short, focused question as the input.
- Hidden fields. If you did not include the title or URL in the retriever's returned fields, the instruction "mention the article title" cannot be followed. The model may then invent a title.
- Language mismatch. A retriever filtered to one language returns nothing for a question that matches only articles in another. Check the filter before blaming the index.
- Editing the wrong version. Changes to a draft do not affect agents using the active version. Confirm which version a test ran against.
Using the template from an agent
A prompt template is not an agent. To make an agent use it, you add an action that wraps the template and assign that action to a topic. The agent then decides when to call it, based on the topic's instructions. The next chapter covers the agent side in detail. For now, remember that the template's input (CustomerQuestion) becomes an action input that the agent must fill from the conversation.
Quick checklist
- The retriever works alone, with a real question.
- The query input is mapped to the retriever.
- Returned fields include the text and the title.
- The prompt limits the model to the excerpts and defines the empty case.
- The preview was run with answerable, partial, and unanswerable questions.
- The template version is saved and active.
Exercise
In preview, your grounded template answers a question that the Knowledge articles do not cover, and the answer sounds plausible. The resolved prompt shows an empty excerpts section. What is the most likely cause, and what two changes would you make?
Show answer
The instructions do not tell the model what to do when no excerpts are returned, so the model used its general knowledge. Add an explicit rule such as "If the excerpts do not contain the answer, say you could not find it and offer a human agent," and add "Do not use outside knowledge." Then rerun the unanswerable test question. Separately, check whether the empty result is expected: if the articles should have matched, verify the query mapping and any filters.
Exercise
The retriever returns the right article, but the answer cites no article title even though the prompt asks for one. What should you check?
Show answer
Check the retriever's returned fields. If the title field is not included, the resolved prompt does not contain it, so the model has nothing to cite. Add the title field to the returned fields, then preview again and read the resolved prompt to confirm the title appears next to each excerpt.