Sub topic 15
Testing grounded answers
This chapter assumes you have a search index, a retriever, and an agent or prompt template that uses them. It also assumes you know how topics and actions work in Agentforce. Testing a grounded answer means checking two things separately: what the retriever returned, and what the model did with it.
Test in layers
A bad answer can come from three places. Test them in this order, because each layer depends on the one before it.
- Content. Confirm the article is published and in the right language. The SOQL query below lists the versions that are available to ingest.
- Retrieval. Confirm the retriever returns the right chunks for a sample question.
- Generation. Confirm the agent or prompt template uses only those chunks.
SELECT Id, Title, UrlName, PublishStatus, Language, LastPublishedDate
FROM Knowledge__kav
WHERE PublishStatus = 'Online'
AND Language = 'en_US'
ORDER BY LastPublishedDate DESC
LIMIT 20Build a test set
Write a small set of questions before you start. Include these kinds:
- Answerable questions whose answer sits in one article.
- Paraphrases that avoid the article's exact wording.
- Multi-article questions that need more than one chunk.
- Unanswerable questions that no article covers.
- Out-of-scope questions that a customer might ask but the agent should not answer.
For each question, record the article you expect and the answer you expect. Reuse the same set after every change to the index, retriever, or instructions.
Check the retriever first
Use the test feature on the retriever in Data Cloud. Enter a question and read the returned chunks and their fields. Look at four things:
- Is the expected article in the results?
- Is it ranked near the top?
- Do the returned fields include the title and URL you need for citation?
- Do any filters remove results you wanted?
If the right chunk is missing here, no prompt change will fix it.
Check the generated answer
Next, run the same questions through the prompt template preview or the agent. Prompt Builder shows the resolved prompt, so you can see exactly which excerpts were inserted. The agent testing tools show which topic and action the agent chose. Then judge each answer against three questions:
| Check | Pass means |
|---|---|
| Faithful | Every claim appears in a returned excerpt |
| Complete | The answer includes the details the article gives |
| Safe fallback | With no relevant excerpt, the agent says so and offers a human |
The unanswerable questions matter most. A grounded agent should decline them. If it answers anyway, the instructions are not restricting it enough.
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.Common errors
- Testing only questions you know work. Include unanswerable ones.
- Judging fluency, not faithfulness. A confident, well-written answer can still come from the model's general knowledge.
- Changing several things at once. Change one setting, then rerun the whole test set.
- Testing as an admin. Your access may differ from a customer's or agent's, so results may not match what real users see.
Exercise
Your agent gives a correct-sounding answer to a question that no published article covers. Which layer do you check first, and what do you change?
Show answer
Check generation first, because the retriever test will probably show weak or irrelevant chunks. The agent is filling the gap from the model's general knowledge. Tighten the topic or prompt instructions so the reply uses only returned articles, and add an explicit fallback that says the information is unavailable and offers escalation. Then rerun the full test set.