Sub topic 3
Grounding a Prompt Template with a Retriever
Assume you know Salesforce Knowledge, Data Cloud data objects, and the basics of Agentforce topics and actions. This chapter focuses on connecting retrieved content to a prompt and controlling the answer that follows.
Grounding a Prompt Template with a Retriever
A retriever searches an indexed data source and returns relevant chunks, such as Knowledge article text. In Prompt Builder, add the retriever as a resource. The prompt template then receives the results as context.
Answer the customer's question using only the Knowledge excerpts below.
If the excerpts do not answer the question, say that you could not find the answer
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>
Question:
<customer question>The retriever should return the fields the model needs, such as article title, article URL, language, and chunk text. Limit the result count so irrelevant content does not crowd out the best matches.
Letting an Agent Answer from Knowledge
An Agentforce agent can use a knowledge action that invokes the retriever or an Agentforce Data Library. Configure the action for the appropriate Knowledge content and expose it in the topic that handles product or policy questions. The action supplies search results before the agent generates its reply.
Writing Instructions That Keep Answers Grounded
State the source boundary directly:
- Use only the returned articles.
- Do not guess or fill gaps with general knowledge.
- Say when no relevant article was found.
- Offer escalation when the answer is missing.
- Identify the article used when useful.
Instructions reduce unsupported answers, but they do not replace testing.
> callout warning > Grounding does not make incorrect source content correct. Review article ownership, publication status, and audience before enabling retrieval.
Testing Grounded Answers
Test questions with known answers, missing answers, synonyms, and conflicting articles. Check whether the response uses the expected article, refuses unsupported claims, and cites the correct title. Record retrieval and answer failures separately. A correct answer cannot compensate for an unauthorized result.
Fixing Poor or Stale Results
Missing results often indicate unpublished articles, failed ingestion, incorrect language filters, or a search index that has not refreshed. Irrelevant results can come from weak chunking, broad filters, or too many returned chunks. Check the source record, ingestion status, index configuration, retriever filters, and result fields in that order.
Access, Masking, and Governance
Apply sharing rules and filters before content reaches the prompt. Return only fields needed for the task. Mask sensitive values where required, and review how the Einstein Trust Layer handles prompts, responses, and data retention. Test with users who have different permissions.
Exercise
What should the agent do when the retriever returns no relevant article?
Show answer
It should say that it could not find the information, avoid guessing, and offer escalation to a human agent.