Sub topic 9
Grounding Responses with Knowledge and CRM Data
This chapter assumes you know the basics of Salesforce objects and records, have read the earlier chapters on topics, instructions, and actions, and have a general idea of how a large language model (LLM) generates text. You do not need Data Cloud experience.
What grounding means
A large language model produces fluent text from patterns learned in training. It does not know your return policy, your customer's open cases, or your product catalog. Left alone, it may answer anyway, and the answer may be wrong.
Grounding is the practice of giving the model trusted, relevant data at the moment it answers, and instructing it to base its reply on that data. The data is added to the prompt. The model is not retrained. This pattern is also called retrieval-augmented generation (RAG) when the data is found by searching a content store first.
Agentforce grounds an agent from two kinds of source:
- Unstructured content, such as Knowledge articles, PDFs, and help-site pages. This answers "how does our process work?"
- Structured CRM data, such as a case, an order, or an account. This answers "what is true for this customer right now?"
The same grounding model applies to service agents and employee agents. What differs is whose data each can see, which the identity and access chapter covers.
Where grounding data enters the agent loop
Grounding is not a separate step bolted onto the agent. It happens inside the loop you saw in the reasoning engine chapter. The engine selects a topic, then picks an action. That action returns data, and the data becomes part of the context for the final response.
The reasoning engine decides which action to call based on your topic instructions and the action descriptions. Good grounding therefore depends on clear instructions and well-described actions, not only on good data.
Grounding with knowledge
For unstructured content, Agentforce uses a retrieval approach. Content is indexed ahead of time. At question time, the agent searches the index, retrieves the most relevant passages, and passes them to the model with the question.
Sources
Common knowledge sources include:
- Salesforce Knowledge articles.
- Uploaded files, such as PDFs and text documents.
- Web content ingested through Data Cloud.
In current Agentforce setups, you group sources in an Agentforce Data Library. The library builds a search index in Data Cloud, and you attach it to the agent. The standard Answer Questions with Knowledge action searches that index. Exact setup screens and names change between releases, so check the current Salesforce documentation before you follow a click-by-click guide.
What makes retrieval work
Retrieval quality depends on your content more than on any setting.
- Write articles that answer one question each. A long article that covers ten topics gives the retriever vague passages.
- Use the words your customers use. Search matches on meaning and on keywords, so titles like "Return an item" help more than "RMA Procedure v3".
- Remove outdated articles. The agent cannot tell that a retired policy is retired unless the content is unpublished or marked as expired.
- Keep article visibility in mind. Content that the user may not see should not reach the answer. Configure audience and data category visibility deliberately, and test with a representative user.
Grounding with CRM data
Knowledge cannot tell an agent the status of one customer's order. For that, the agent needs an action that reads records. You build these actions with Flow or Apex, or reuse standard actions that query records.
An action returns only the fields you design it to return. This makes the action an important control point. A narrow action that returns an order status exposes less than a broad action that returns the whole order row.
An Apex example
The following invocable method returns a short case summary for a case number. It uses with sharing and WITH USER_MODE, so the query respects the running user's sharing rules, object permissions, and field-level security. It is bulk-safe because it queries once for all requests.
public with sharing class GetCaseContextAction {
public class Request {
@InvocableVariable(label='Case Number' required=true)
public String caseNumber;
}
public class Response {
@InvocableVariable(label='Case Summary')
public String summary;
}
@InvocableMethod(
label='Get Case Context'
description='Returns the subject, status, and priority of a case for a given case number'
)
public static List<Response> getContext(List<Request> requests) {
Set<String> caseNumbers = new Set<String>();
for (Request r : requests) {
caseNumbers.add(r.caseNumber);
}
Map<String, Case> casesByNumber = new Map<String, Case>();
for (Case c : [
SELECT CaseNumber, Subject, Status, Priority
FROM Case
WHERE CaseNumber IN :caseNumbers
WITH USER_MODE
]) {
casesByNumber.put(c.CaseNumber, c);
}
List<Response> results = new List<Response>();
for (Request r : requests) {
Response res = new Response();
Case c = casesByNumber.get(r.caseNumber);
if (c == null) {
res.summary = 'Case not found';
} else {
String priority = c.Priority == null ? 'Not set' : c.Priority;
res.summary = 'Subject: ' + c.Subject
+ '; Status: ' + c.Status
+ '; Priority: ' + priority;
}
results.add(res);
}
return results;
}
}Notice three design choices. The method returns a plain-language string, which the model can use directly. It returns an explicit Case not found value instead of an empty result, so the instructions can tell the agent what to do. It names its fields narrowly, so nothing extra reaches the prompt.
Other ways to bring in CRM data
- Flow actions can use Get Records elements and return variables. Flow suits admins and simple lookups.
- Prompt templates can include merge fields from a record, which grounds a generated draft in that record's data.
- Data Cloud can supply unified profile data, such as data from several systems, when the CRM alone does not hold the full picture.
Telling the agent to use grounding
Data in the prompt does not guarantee that the model uses it. Your topic instructions must direct the agent to rely on retrieved data and to say so when it has none. Here is an example topic that combines both kinds of grounding.
Topic: Returns Help
Classification description: Customer asks how returns work or whether a specific order can be returned.
Scope: Explain the return policy and check the status of a single order.
Instructions:
- For questions about the return policy, use the Answer Questions with Knowledge action and base the reply only on the articles it returns.
- For questions about a specific order, ask for the order number, then call the Get Order Status action.
- Do not state return windows, fees, or eligibility from memory.
- If the knowledge action returns no relevant article, say you do not have that information and offer to connect the customer with a human agent.
- Do not discuss refunds that were already issued. Hand those to a human agent.The key lines are the ones that forbid answers from memory and define the no-result path. Without them, the model fills gaps with plausible text.
Failure modes and how to spot them
| Symptom | Likely cause | What to check |
|---|---|---|
| Agent answers confidently but incorrectly | Instructions allow answers from general knowledge | Add "base the reply only on returned data" and a no-result path |
| Agent says "I don't know" for questions your articles cover | Poor retrieval, or the article is not indexed or not visible | Article status, index refresh, audience and visibility, wording of the title |
| Agent cites a retired policy | Old article still published and indexed | Archive the article and refresh the index |
| Action returns blank values | Field-level security hides the field from the running user | Run the action as that user and compare permissions |
| Employee sees data a customer should not | Action runs in system mode, or the wrong user context is used | Use `with sharing` and `WITH USER_MODE`, and review the agent's identity settings |
| Wrong action chosen for a question | Vague action descriptions | Rewrite the labels and descriptions so each states when to use it |
Grounding and the Trust Layer
Retrieved passages and record fields are placed into the prompt, and the prompt passes through the Einstein Trust Layer before it reaches the model. The Trust Layer can mask sensitive values, and it checks responses before they are returned. The next chapters cover this layer in detail. For now, remember two points. Grounding data is only safe to send if the action returned it with the right permissions in the first place. The Trust Layer is a second control, not a replacement for correct access design.
A practical checklist
- Decide which questions need knowledge and which need record data. Many topics need both.
- Clean the content: one question per article, current, visible to the right audience.
- Build narrow actions that return only the fields the topic needs, in user mode.
- Write instructions that require the agent to rely on returned data, and give a defined fallback for no result.
- Test with real phrasing, including questions your content cannot answer.
Exercise
A service agent answers return-policy questions correctly in testing, but a tester asks about a policy your articles do not mention and the agent invents a 60-day window. Name two changes you would make, one to the topic instructions and one to your testing approach.
Show answer
In the instructions, forbid answers from memory, require replies to be based only on the returned articles, and add a fallback for the no-result case, such as saying the information is unavailable and offering a human agent. In testing, add questions that fall just outside the content, so you can confirm the agent uses the fallback instead of guessing.
Exercise
Why does the GetCaseContextAction return 'Case not found' for a missing case instead of returning an empty string, and why does it use WITH USER_MODE?
Show answer
An explicit value gives the topic instructions something definite to react to, so the agent can follow a defined path instead of guessing. WITH USER_MODE makes the query enforce the running user's object permissions, field-level security, and sharing, so the agent cannot return data the user is not allowed to see.