Sub topic 10
Previewing and testing the resolved prompt
This chapter assumes you can build a prompt template with record merge fields. It also assumes you know the basics of Flow Builder and read Apex comfortably. Here you will check what the model actually receives before anyone uses the template.
Why the resolved prompt matters
A prompt template holds placeholders such as {!$Input:Case.Subject}. At run time, Salesforce replaces each placeholder with real data. The result is the resolved prompt, which is the text sent to the model.
Most grounding bugs show up in the resolved prompt, not in the template. A merge field can resolve to blank. A Flow can return the wrong records. A relationship can point at a record the user cannot see. If you read only the template, you will miss all of these.
The model's response can hide the same problems. A fluent answer may still rest on missing data. Read the resolved prompt first, then judge the response.
Previewing in Prompt Builder
Prompt Builder has a preview area next to the template editor. The steps are:
- Open the template and save your latest edits.
- In the preview area, choose a record for the template input. For a Case template, pick a Case.
- Run the preview.
- Read the resolution first. It shows the prompt text with all values filled in.
- Then read the response, which is the model's output for that resolved prompt.
The exact labels in the interface can change between releases. The pattern stays the same: one view shows the resolved prompt and another shows the model's answer.
What to check in the resolution
Work through the resolved text with a short checklist.
- Placeholders are gone. Raw text such as
{!$Input:Case.Subject}means the merge field did not resolve. Check the spelling and the object name. - Values are correct. Compare a few values with the record page.
- Empty fields are visible. If
Descriptionis blank, the prompt should show it so your "say it is not provided" instruction can apply. - Related data appears. Fields such as
{!$Input:Case.Account.Name}should show the parent's value. - Flow and Apex text is present. The inserted block should match what the Flow or method returns for that record.
- Length is reasonable. A very long block may crowd out your instructions or be cut off.
Testing with varied records
One passing preview proves little. Test a small set of records on purpose:
| Record type | What it tests |
|---|---|
| Complete record | The normal path works. |
| Record with blank fields | Your "do not guess" instruction holds. |
| Record with no related data | Flow and Apex return a sensible fallback. |
| Record with a very long description | Size limits and truncation. |
| Record with unusual characters | Quotes, line breaks, and non-English text come through intact. |
The sample Apex method returns No open tasks. when it finds nothing. The empty-related-data case checks that this fallback appears in the resolved prompt.
Testing the pieces separately
When the resolved prompt is wrong, find which part produced the bad text.
Flow resources
Open the Flow in Flow Builder and use debug with a test record. Confirm that the output variable your template reads, such as Prompt, holds the text you expect. Fix the Flow first, then preview the template again.
Apex resources
Write an Apex test for the invocable method. It runs faster than clicking through previews, and it keeps working after later changes. This test covers the CaseOpenTaskGrounding class from earlier in this tutorial.
@IsTest
private class CaseOpenTaskGroundingTest {
private static List<CaseOpenTaskGrounding.Response> run(Case c) {
CaseOpenTaskGrounding.Request req = new CaseOpenTaskGrounding.Request();
req.RelatedEntity = c;
return CaseOpenTaskGrounding.getOpenTasks(
new List<CaseOpenTaskGrounding.Request>{ req }
);
}
@IsTest
static void listsOpenTasks() {
Case c = new Case(Subject = 'Printer down', Status = 'New');
insert c;
insert new Task(
Subject = 'Call customer',
WhatId = c.Id,
ActivityDate = Date.today().addDays(2)
);
Test.startTest();
List<CaseOpenTaskGrounding.Response> results = run(c);
Test.stopTest();
System.assertEquals(1, results.size());
System.assert(results[0].Prompt.contains('Call customer'));
}
@IsTest
static void returnsFallbackWhenNoTasks() {
Case c = new Case(Subject = 'No tasks', Status = 'New');
insert c;
List<CaseOpenTaskGrounding.Response> results = run(c);
System.assertEquals('No open tasks.', results[0].Prompt);
}
}Testing as different users
Grounding runs with the permissions of the person using the template. The Apex example uses WITH USER_MODE, so a user without access to Task data gets an error or less data than you saw as an admin.
Your own preview may look perfect because administrators can see almost everything. Log in as, or test with, a user who has the permission set your real audience will have. Compare the resolved prompts. Any difference points to a field-level or object-level access gap.
Common mistakes
- Judging only the model's response and never reading the resolution.
- Previewing one record and assuming it represents all of them.
- Editing instructions to hide a data problem that belongs in the Flow or Apex.
- Forgetting to save the template before previewing, so the preview shows old text.
Exercise
A preview response says "The customer is in the healthcare industry," but the Account record has no Industry value. What should you check first, and why?
Show answer
Check the resolved prompt. If it shows an empty Industry, the model guessed, so strengthen the instruction to say a missing value is not provided. If the resolved prompt contains "healthcare", find where that text came from, such as the Flow or Apex output, because the data source is wrong.
Exercise
Your Apex grounding method works in an administrator's preview, but a service agent's resolved prompt lacks the task list. Name one likely cause and one way to confirm it.
Show answer
The agent likely lacks access to Task records or fields, and WITH USER_MODE enforces that. Confirm by previewing or testing as a user with the agent's permission set and comparing the resolved prompts.