Sub topic 10
Previewing and testing the resolved prompt
This chapter assumes you can build a prompt template with merge fields, a Flow resource, and an Apex resource. It covers how to check that a template sends what you think it sends, before any user depends on it.
What "resolved" means
A prompt template is a recipe. At run time Prompt Builder replaces each merge field and resource with real data. The result is the resolved prompt, which is the exact text sent to the large language model (LLM).
The model never sees {!$Input:Case.Subject}. It sees the case subject. If a field is empty, a relationship is broken, or a Flow returns nothing, the problem shows up in the resolved prompt first. Checking the resolved prompt separates two kinds of problem:
- Grounding problems. The right data did not reach the prompt.
- Instruction problems. The data arrived, but the model used it badly.
Look at the resolved text before you judge the model's answer. Rewording instructions will not fix a missing field.
The preview panel
Prompt Builder shows a preview next to the template editor. The workflow is the same for every template type:
- Open the template and select a record for the input, such as a specific Case.
- Run the preview.
- Read the resolved prompt. Prompt Builder shows it separately from the model's response.
- Read the response and judge it against the resolved prompt.
The labels and layout can differ between releases, so look for the two outputs: the text after resolution, and the text the model returned.
What to check in the resolved prompt
Compare the resolved prompt against the record itself. Open the Case in another tab and check each grounded value. For each template, go through these questions:
- Is every merge field replaced? A literal
{!...}left in the text, or a blank where a value should be, means the reference is wrong or the field is empty. - Is each value the right one? Make sure
Case.Account.Nameis the account of this case and not a leftover from a different record. - Is the Flow or Apex text present? A heading such as "Recent order history:" followed by nothing means the resource returned an empty string or null.
- Is the text in a shape the model can read? Long, unformatted blobs and raw IDs make poor grounding. Fix them in the resource, not in the instructions.
- Is anything unexpected included? Look for internal notes, sensitive values, or data the template should not expose.
Example: a template with a missing value
Take the case summary template from earlier chapters:
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.Preview it against a Case with no description. The resolved prompt will look like this:
Case subject: Printer offline in building 4
Status: New
Priority: High
Description:The empty Description: line is the expected result for a blank field. The last instruction in the template covers it. In the response, check that the model says the description is not provided and does not invent one. If it invents one, tighten the instruction. If it handles the gap, this test passes.
Build a set of test records
One happy-path record proves little. Pick or create several records that stress different parts of the template. Use a sandbox or a scratch org with fake data. Do not build test cases out of real customer records.
| Test record | What it tests |
|---|---|
| Fully populated record | Baseline. Every merge field resolves. |
| Record with blank optional fields | Whether instructions handle empty values. |
| Record with no parent (no Account or Contact) | Whether relationship fields resolve to blank without breaking the prompt. |
| Record with a very long text field | Size limits and truncation, covered in the next chapter. |
| Record with many related items | Whether Flow or Apex limits the output sensibly. |
| Record with no related items | Whether the "empty" message from Flow or Apex reads well. |
| Record with special characters or line breaks | Whether formatting survives in the resolved text. |
A relationship field such as {!$Input:Case.Account.Name} is a common source of silent blanks. When a Case has no Account, the lookup has no record to follow. Test this case on purpose.
Testing a Flow resource
A Flow resource contributes text through its output variable, referenced as {!$Flow:Get_Recent_Orders.Prompt}. Test it at two levels.
In Prompt Builder. Preview with records that give different Flow results: many orders, one order, and none. Check that the inserted text matches what you expect.
In Flow Builder. If the preview text is wrong, debug the Flow alone. Run it with the Debug option and supply the same record as input. Inspect these things:
- Whether the Get Records element found anything.
- What the loop built into the text variable.
- What value ended up in the output variable that the template reads.
A frequent bug is a text variable that is built correctly but never assigned to the output variable. The prompt then shows an empty section while the Flow looks fine in debug.
Also check how the Flow handles no results. If Get Records finds nothing, the output is blank, and the model gets a heading with no content. Set a fallback value such as "No recent orders." so the prompt carries a clear signal.
Testing an Apex resource
An Apex resource is an invocable method. Test it twice: in the preview, and with an Apex unit test. The unit test is the repeatable one. It runs without the LLM and will catch regressions when someone edits the class later.
This test covers the CaseOpenTaskGrounding class from the Apex chapter. It checks both the populated case and the empty case.
@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 returnsOpenTasksAsLines() {
Case c = new Case(Subject = 'Printer offline', Status = 'New', Origin = 'Phone');
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'),
'Prompt text should list the open task');
}
@IsTest
static void returnsFallbackWhenNoTasks() {
Case c = new Case(Subject = 'No tasks here', Status = 'New', Origin = 'Web');
insert c;
Test.startTest();
List<CaseOpenTaskGrounding.Response> results = run(c);
Test.stopTest();
System.assertEquals('No open tasks.', results[0].Prompt);
}
}The unit test runs as the user who runs the tests, usually an administrator. The method uses WITH USER_MODE, so a user with less access can get different results. To test that, use System.runAs with a user who has a restricted permission set, or log in as a representative user in a sandbox and run the preview.
Testing as different users
Grounded data depends on who is running the prompt. A user without access to a field, an object, or certain records does not get the same grounding as an administrator. This matters because:
- An administrator's preview can look perfect while a support agent's run is missing data.
- A template that exposes data to the wrong person is a security problem, not just a quality problem.
Test with at least one user who has the access level of your real audience. Compare the resolved prompts between that user and an administrator on the same record. Differences are expected and are not errors in themselves. Decide whether each difference is intended.
Reading the response
After the resolved prompt is right, judge the response. Use a short checklist:
- Faithful. Every claim in the response can be traced to a value in the resolved prompt.
- Complete. The response uses the fields the task needs and does not skip important ones.
- Honest about gaps. For blank inputs, it says so and does not fill in guesses.
- Right format. Length, tone, and structure match the instructions.
The model can produce a different response on each run, so run important cases more than once. If the response is faithful in most runs but invents a value in one, treat the instruction as too weak and strengthen it.
Change one thing at a time. If you edit an instruction and a Flow in the same step, you will not know which change fixed or broke the output.
Versions and activation
Prompt Builder templates have versions. Make changes in a draft version. Preview and test it fully. Activate it only when the checks pass. If a later change causes trouble, you can go back to an earlier version.
A sound release routine looks like this:
- Build and preview in a sandbox.
- Run Apex unit tests and debug the Flow with edge-case inputs.
- Preview as a representative user.
- Deploy to production and preview there with a safe record before wide use.
- Watch early real outputs for surprises.
Common mistakes
| Symptom | Likely cause | Where to look |
|---|---|---|
| A merge field shows as blank | The field is empty, or the user cannot read it | The record, then field access for the user |
| Parent data is missing | The record has no Account or Contact, or the relationship path is wrong | The record's lookup fields and the merge field path |
| Resource section is empty | Flow output variable never set, or Apex returned null | Flow debug, or the unit test |
| Output is correct for admin, wrong for agents | Permissions differ | Run the preview as an agent user |
| Response invents facts | Weak instruction about missing data | The prompt text, not the resource |
| The prompt is cut off or very long | Too much grounded text | Size limits, covered next |
Exercise
A support agent says the case summary never mentions the customer's account industry, but the template includes {!$Input:Case.Account.Industry} and your own preview shows it correctly. Name two checks you would run, and the order you would run them in.
Show answer
First, preview the same Case as a user with the agent's profile and permission sets, and read the resolved prompt to see whether the Industry line is blank. Your own preview ran with your access, which may be broader than the agent's. Second, open the Case and confirm it has an Account and that the Account's Industry field has a value. Either missing field-level access for the agent or a blank value would produce an empty Industry line. Check the resolved prompt first, because it shows whether the data reached the model before you consider changing instructions.
Exercise
Your Flow resource returns a text variable that is built correctly in Flow debug, but the resolved prompt shows an empty section under the heading. What is a likely cause, and what second problem should you guard against for records with no related data?
Show answer
The built text was probably never assigned to the output variable that the template reads, such as the one referenced as {!$Flow:GetRecentOrders.Prompt}. Check the final assignment in the Flow. The second problem is the empty case: when Get Records finds nothing, the output is blank, so add a fallback value such as "No recent orders." so the model receives a clear signal.
Exercise
Write the two things an Apex unit test for a grounding method should assert, based on the CaseOpenTaskGrounding example.
Show answer
It should assert that a case with open tasks produces text containing the task subject, and that a case with no open tasks produces the fallback text "No open tasks.". Testing both paths confirms the populated output and the empty-state message.