Sub topic 13
Prompt design best practices and common pitfalls
This chapter assumes you know Salesforce objects, records and fields. It also assumes you have built at least one prompt template in Prompt Builder and know the four template types: Sales Email, Field Generation, Record Summary and Flex. Prompt Builder requires Einstein generative AI to be enabled in the org.
A working model for a good prompt
A prompt template sends your text to a large language model after Salesforce replaces each merge field with a real value. The model only knows what the prompt tells it. Most weak output comes from one of three causes: missing context, vague instructions, or unclear limits on what the model may say.
A reliable prompt answers four questions:
- Who is the output for, and what is its purpose?
- What data should it use? Supply this through merge fields.
- What shape should the output take, such as length, tone and format?
- What should the model do when data is missing?
The diagram shows how these parts combine.
Practices that work
Ground the prompt in record data
Use merge fields instead of asking the model to recall facts. Match the syntax to the template type and input name, for example {!$Input:Contact.FirstName} for a Contact input.
State the limits explicitly
Tell the model what it must not do. The Sales Email example in this tutorial says "do not invent product details". That one line reduces made-up claims.
Handle empty fields
A merge field with no value resolves to nothing, and the model may fill the gap with a guess. Add a rule such as "If a value is empty, leave it out instead of guessing."
Using the information below, write a one-sentence description of this account for a sales rep.
Account name: {!$Input:Account.Name}
Industry: {!$Input:Account.Industry}
Annual revenue: {!$Input:Account.AnnualRevenue}
If a value is empty, leave it out instead of guessing.Set the format and length
Give a number, such as "under 120 words" or "three bullet points". Models follow concrete limits better than words like "short".
Keep one job per template
A template that writes an email, summarizes a case and classifies priority is hard to test. Split it into separate templates, each matched to the right type.
Common pitfalls
| Pitfall | Effect | Fix |
|---|---|---|
| Vague instruction such as "write something good" | Inconsistent tone and length | State audience, purpose and length |
| No rule for empty fields | Invented or awkward text | Add a missing-data instruction |
| Wrong merge field syntax for the input name | Field does not resolve | Check the input name and use the field picker |
| Too many merge fields, including long text | Noisy prompt, slower and less focused output | Include only fields the task needs |
| Testing on one record | Hidden failures on sparse records | Preview with several records, including incomplete ones |
| Editing an active version directly | No way to compare or roll back | Save a new version and compare |
Respect the limits of generation
Generated text is a draft. The model can still produce errors, so a person should review sales emails before sending. Do not use a prompt to make decisions that need a guaranteed correct answer, such as calculating a discount. Use a formula or Flow for that and pass the result into the prompt.
An iteration routine
- Write the first version with the four questions answered.
- Preview it against a complete record and a sparse record.
- Change one thing at a time, so you know which change helped.
- Save a new version for each meaningful change.
- Activate the version only after the previews look consistent.
Exercise
A Field Generation template sometimes writes "The company has an annual revenue of ." for accounts with no revenue value. Name the cause and the fix.
Show answer
The AnnualRevenue merge field resolves to an empty value, and the prompt has no rule for missing data. Add an instruction such as "If a value is empty, leave it out instead of guessing", then preview the template on an account with no revenue to confirm it.
Exercise
A single template is meant to draft a follow-up email and also decide whether the opportunity is high priority. Why is this a poor design, and what would you do instead?
Show answer
One template with two jobs is hard to test and gives mixed results. Make a Sales Email template for the email. Calculate priority with a formula field or Flow, then pass the result into the prompt as input.