Sub topic 1
Why prompts need grounding
A large language model (LLM) writes fluent text, but it knows nothing about your customers, your cases, or your orders. This chapter explains what goes wrong when a prompt lacks your data, what grounding is, and how Salesforce Prompt Builder supplies that data. The later chapters build each technique in detail.
Prerequisites
This chapter assumes you already know the following:
- The basic Salesforce data model: objects, fields, and relationships such as the lookup from a Case to an Account.
- Where Setup is and how permission sets grant access to objects and fields.
- What a prompt for an LLM is: text you send to the model, which returns generated text.
- The basics of Flow Builder, and enough Apex to read a class with an
@InvocableMethod.
You do not need to have used Prompt Builder before. You also don't need to write any Apex in this chapter. You only need to recognize it when it appears.
What an LLM does and does not know
An LLM is trained on a large body of text, and training ends at a fixed date. When you send it a prompt, it predicts a likely continuation of that text. Two consequences follow.
- It has no access to your org. Your Salesforce data is not in its training set, and the model cannot query it on its own.
- It is built to produce plausible text, not to confirm that the text is true. When it lacks a fact, it often fills the gap with something that sounds right.
Suppose you ask a model to "summarize this case for the next agent" and send only those words. The model has no case to summarize. It may reply that it needs more information. It may also invent a customer name, a product, and a problem, and present them as fact. The second outcome is the dangerous one, because the output looks finished and nothing marks it as made up.
What grounding means
Grounding is the practice of adding relevant, trustworthy data to a prompt at the moment you send it, so the model bases its answer on that data instead of on guesses. The grounded data is context, and the model is asked to work from it.
Compare two versions of the same request.
Ungrounded:
Write a two-sentence summary of the support case for the agent taking over.
Grounded:
Write a two-sentence summary of the support case below for the agent taking over.
Case subject: Invoice total does not match order
Status: Escalated
Priority: High
Description: Customer was charged 1,240 USD but the order confirmation shows 1,024 USD.In the first version the model must invent a case. In the second it only has to compress text it can see. The task is the same. What changed is that the facts are now in the prompt.
Grounding does not retrain the model or change its weights. The model is unchanged. You are choosing what it reads before it answers, which is why grounding is cheap to update: edit the template or the data source, and the next call uses the new version.
Failure modes that grounding addresses
Ungrounded prompts fail in a few predictable ways. Knowing them helps you decide what a template needs.
| Failure | What it looks like | How grounding helps |
|---|---|---|
| Fabrication | The model invents names, dates, amounts, or policies | The real values are in the prompt, so the model can copy them |
| Generic output | A reply that could apply to any customer | Account, contact, and case details make the text specific |
| Stale knowledge | The model cites facts that were true at training time | The prompt carries current record values |
| Missing business context | The model ignores that the customer is a key account or a recent complainer | Related data such as account tier or recent orders is inserted |
| Inconsistency | Two runs on the same record give different facts | Both runs read the same supplied data |
Grounding reduces these problems but does not remove them. A model can still misread, ignore, or embellish supplied data. Later chapters cover instructions that tell the model what to do when a value is missing, and how to preview the result so you can catch these errors before users do.
Where the data comes from in Prompt Builder
Prompt Builder is the Salesforce tool for creating and managing prompt templates. A prompt template is a saved prompt with placeholders. When the template runs, Salesforce replaces each placeholder with real data, and the filled-in text is what goes to the model. This filling-in step is called resolving the prompt.
Prompt Builder offers three main ways to bring data into a template. They differ in how much logic they can run.
- Merge fields. A placeholder such as
{!$Input:Case.Subject}is replaced with the value of that field on the record the template runs against. Merge fields can also follow a relationship to a parent record, for example{!$Input:Case.Account.Name}. This is the simplest option and needs no code. - Flow resources. A flow can look up records, loop over them, filter them, and build a text result. The template inserts that text with a reference such as
{!$Flow:Get_Recent_Orders.Prompt}. Use this when the data needs queries or logic that a single field reference cannot express. - Apex resources. An invocable Apex method can do work that a flow cannot do cleanly, and it returns text for the template. Use this when you need custom queries, calculations, or calls to existing Apex code.
You will see the exact syntax and setup steps in the chapters on each technique. For now, hold on to the idea that all three do the same job: produce text that ends up inside the prompt before the model sees it.
A first look at a grounded template
Here is a template body that uses only merge fields. It is an example from the plan for this tutorial.
You are a support assistant. Summarize the case below in two sentences for an agent taking over.
Case subject: {!$Input:Case.Subject}
Status: {!$Input:Case.Status}
Priority: {!$Input:Case.Priority}
Description: {!$Input:Case.Description}
If a value above is empty, say it is not provided. Do not guess.The template has two kinds of content. The lines starting with a label and a merge field are the grounding. The first sentence and the last line are instructions. Both matter. The grounding gives the model facts, and the instructions tell it what to do with them, including what to do when a fact is absent. Without the last line, an empty Description field would leave the model free to fill the gap itself.
The grounding path from record to model
The diagram shows what happens each time a grounded template runs.
Notice that the model is the last step. Everything before it is data preparation that happens inside Salesforce, under your control. That is where you decide what the model is allowed to know.
Grounding and trust
Putting data into a prompt creates a responsibility to decide which data and for whom. Three points matter even at this early stage.
- The user's access still applies. Grounded data should come from what the running user may see. The example Apex method in later chapters uses
WITH USER_MODEin its query for this reason. If a field is hidden from the user, a careless resource could leak it into the prompt and then into the response. - Data quality becomes output quality. If the Description field is blank, misspelled, or outdated, the summary will be too. Grounding makes the model faithful to your data, including its flaws.
- More is not better. A prompt has a size limit, and extra irrelevant text can distract the model. Choose the fields that bear on the task.
A later chapter covers permissions, data quality, and size limits in full.
A worked example: choosing what to ground
Say you want a template that drafts a reply to a customer who wrote in about a late order. Work through the grounding before writing any instructions.
- State the task: draft a polite reply that addresses the delay.
- List the facts the reply needs: the customer's name, the order number, the order date, the promised delivery date, and the current status.
- For each fact, find where it lives in Salesforce. The customer's name is on the Contact, reached from the Case. The order details are on related Order records.
- Match each fact to a technique. The name and case fields are direct or relationship merge fields. The most recent orders need a query and a limit, so they suit a Flow or Apex resource.
- Decide what the model should do when a fact is missing, and write that into the instructions.
This sequence is the habit the rest of the tutorial builds: start from the task, identify the facts, locate them, pick the simplest resource that can fetch them, and tell the model how to handle gaps.
Common mistakes
- Writing instructions and no data. A detailed role description ("You are an expert support agent...") does not replace the case details. Without them the model still guesses.
- Asking the model to recall data it was never given. A request such as "Mention the customer's last order" fails if the order is not in the prompt.
- Grounding too broadly. Dumping every field of a record into the template wastes space and can expose data the task does not need.
- No rule for empty values. Blank fields resolve to blank text. Unless the instructions say what to do, the model may invent a value.
- Skipping the check. Not previewing the resolved prompt means you never see what the model actually received. Later chapters show how to preview and test it.
What comes next
The chapters that follow build on this foundation in order. You will learn how prompt templates and their types are organized, how a template is tied to an input record, how to insert field values with merge fields, and how to follow relationships to related records. After that you will build Flow and Apex resources, compare the three approaches, and test the resolved prompt.
Exercise
A teammate writes a template that says "Summarize the customer's open issues" and contains no merge fields, Flow, or Apex resources. They are surprised that the output names issues that do not exist in Salesforce. Explain why this happens and name two changes that would fix it.
Show answer
The prompt contains no customer data, so the model has nothing to summarize and generates plausible-sounding issues instead. Two fixes: add merge fields for the case fields (such as subject, status, and description) so the real values are inserted, and add an instruction such as "If a value is empty, say it is not provided. Do not guess." You could also add a Flow or Apex resource that returns the customer's open cases as text.
Exercise
For a template that drafts a reply about a late order, classify each fact by the simplest technique that could supply it: (a) the case Subject, (b) the Account name, (c) the three most recent orders for the account, filtered to those not yet delivered.
Show answer
(a) A merge field on the input record, such as {!$Input:Case.Subject}. (b) A relationship merge field, such as {!$Input:Case.Account.Name}. (c) A Flow or Apex resource, because it needs a query with a filter and a limit, which a merge field cannot express. A Flow is the simpler choice if it can do the query and text formatting. Apex is for cases that Flow cannot handle cleanly.