Sub topic 15
Testing Grounded Answers
This chapter assumes you have a working search index and retriever over Knowledge content, and that you have connected them to a prompt template or an agent knowledge action. You should know what topics, actions, and instructions are in an Agentforce agent. It covers how to test whether answers are actually grounded, at three levels: the retriever, the prompt template, and the agent.
Why test in layers
A grounded answer passes through several stages. Each stage can fail on its own, and a failure in an early stage looks like a "bad answer" at the end.
- A Knowledge article is published and ingested.
- The search index chunks and embeds it.
- The retriever returns chunks for a query.
- The prompt template or agent action passes the chunks to the model.
- The model writes a reply under your instructions.
If you only test the final reply, you cannot tell whether the retriever missed the article or the model ignored it. Test from the bottom up. Confirm the retriever first, then the prompt, then the agent.
Build a test question set first
Write the questions before you start tuning. Otherwise you will adjust the system until your favorite question works and miss the rest. A useful set contains four kinds of questions:
| Question type | Example intent | What a pass looks like |
|---|---|---|
| Direct | Wording close to an article title | The right article is returned and cited |
| Paraphrased | Same need, different words | The same article is still returned |
| Out of scope | Topic no article covers | The agent says it cannot find the answer and offers escalation |
| Restricted | Content the tester should not see | Nothing from that article appears |
Record each question, the article you expect, and the expected behavior. Aim for at least five or ten questions per article group, and keep the set in a spreadsheet so you can rerun it after every change.
Layer 0: Confirm the source content
Before testing retrieval, confirm that the article is available to ingest. The query below lists the most recently published English article versions.
SELECT Id, Title, UrlName, PublishStatus, Language, LastPublishedDate
FROM Knowledge__kav
WHERE PublishStatus = 'Online'
AND Language = 'en_US'
ORDER BY LastPublishedDate DESC
LIMIT 20If an article you expect is missing, or its LastPublishedDate is older than your latest edit, the problem is upstream of everything else. Draft articles and articles in other languages are not in this result, and they are common reasons for "the agent doesn't know this."
Layer 1: Test the retriever
In Data Cloud, open the retriever and use its test option to enter a query. Review the returned chunks, not only the top one. For each question in your set, check:
- Relevance. Is the chunk from the article you expected?
- Rank. Is the right chunk near the top, or buried below unrelated ones?
- Completeness. Does the chunk contain the actual answer, or only the heading? A chunk that was split mid-procedure may hold half of the steps.
- Returned fields. Are the fields you need, such as the title and URL name, present so the model can cite them?
- Filters. Does a filter, such as language or article type, remove a result you expected?
Note the result count setting too. If the correct chunk sits at position six and the retriever returns five, the model never sees it. Raising the count helps, but it adds noise and tokens, so change it deliberately and retest the out-of-scope questions afterward.
Run your paraphrased questions here. Hybrid search can find a match on exact keywords, and vector search can find a match on meaning. A paraphrase that fails while the direct question succeeds suggests the content uses different vocabulary than your users do.
Layer 2: Test the prompt template
In Prompt Builder, add the retriever as a resource and preview the template with sample inputs. The preview shows the resolved prompt, which is the text sent to the model after the retriever results are inserted. Read it carefully. This is the quickest way to see what the model actually receives.
A grounding prompt like this one restricts the model to the excerpts and defines the empty-result behavior:
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>Preview it with each question type and check:
- With a direct question, does the reply match the excerpt and name the article?
- With an out-of-scope question, does the reply decline rather than invent an answer? This is the most important check. A model that answers an uncovered question is using its general knowledge.
- Does the reply add details that appear in no excerpt, such as a number, a deadline, or a step? Compare it line by line with the excerpts.
> Treat unsupported specifics as a failure even when they sound plausible.
Plausible but unsupported details are the main way ungrounded answers slip through, because they read as correct.
Layer 3: Test the agent
Next, test in the agent builder's conversation preview. Here a new set of failures appears, because the agent must choose the right topic and action before any retrieval happens. A sample topic instruction that keeps replies tied 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.When you run your question set through the agent, check these points in the preview's reasoning or action details, where available:
- Was the correct topic selected?
- Was the knowledge action actually called? If not, the reply came from the model alone.
- What query did the agent pass to the action? A rewritten query can drift from the customer's wording.
- Did the reply match the returned content?
Test freshness
Grounded answers are only as current as the index. To test freshness:
- Edit and republish an article, changing one distinctive fact.
- Ask a question about that fact immediately and note the answer.
- Ask again after the next index refresh and compare.
A delay between publishing and retrieval is expected, since ingestion and indexing run on a schedule or on a refresh. Record how long it takes in your environment so you can set expectations with stakeholders. Also test an archived or unpublished article. Its content should stop appearing after the next refresh.
Test access and masking
Run the restricted questions as a user who should not see the content, not as an administrator. An admin test can pass while a real user gets different results. Also try a question that includes sensitive input, such as an email address or a phone number, and check the preview to see whether masking is applied before the text reaches the model, as configured in your Trust Layer settings. Details of governance are covered in a later chapter. Here the aim is only to include these cases in your regular test run.
Scoring and recording results
Give every test a simple verdict so you can compare runs.
| Verdict | Meaning |
|---|---|
| Grounded | The reply is supported by the returned excerpts |
| Partially grounded | The reply is correct but adds unsupported detail |
| Ungrounded | The reply uses outside knowledge or invents facts |
| Correct refusal | No article covers it and the agent declined |
| Missed | An article exists but was not retrieved or used |
Track the counts by verdict after each change to content, chunking, the retriever, or instructions. If "Missed" rises after a change, look at retrieval. If "Ungrounded" rises, look at the instructions. Language models can vary between runs, so run important questions more than once before you decide a fix worked.
Common mistakes
- Testing only with questions copied from article titles, which hides vocabulary gaps.
- Skipping out-of-scope questions, so the fallback behavior is never exercised.
- Testing as an administrator and missing sharing problems.
- Changing several settings at once, then not knowing which one helped.
- Judging by fluency rather than by comparing the reply with the excerpts.
Exercise
A customer asks about a refund window that no article covers. The agent replies with a confident 30-day window. The retriever test for that question returned five unrelated chunks. Which layer should you fix first, and what should the agent have done?
Show answer
Start with the instructions at the prompt and agent layers, because the retriever behaved correctly by returning only weakly related chunks, and the model used general knowledge instead. The agent should have said it could not find the information and offered escalation. Strengthen the "only use the excerpts" and empty-result wording, then retest. Confirm in the preview that the knowledge action ran and that the reply contains no detail missing from the excerpts.
Exercise
Why should a test run include a question about a fact that exists only in your own articles?
Show answer
A fact only your content contains cannot be answered from the model's general knowledge. If the agent gives that fact correctly, it must have used the retrieved articles. If it cannot, retrieval or the action call failed. A generic question can pass for the wrong reason.