Section 2 · Prompt Engineering · 20% of exam
2.6 Best Practices for Writing Effective Prompts
Exam objective
Explain how to write clear and effective instructions for prompt templates and improve output through iterative testing.
An effective prompt tells the model what task to perform, what context to use, what constraints to follow, and what a useful result looks like. In Prompt Builder, the template should be written for a specific business need rather than as a broad request to be helpful. Clear instructions reduce ambiguity, while grounding supplies the facts the model should use. Neither good wording nor rich context alone guarantees a correct answer; both need to work together.
Structure the instructions
State the role or task in plain language. Identify the intended audience and purpose if they affect tone or content. Tell the model which supplied context is relevant and what to do with it. Specify the desired format, such as a short paragraph, a list of next steps, or a structured set of fields, when the calling feature expects one. Set useful boundaries: do not add facts absent from the context, do not expose confidential information in the output, and say when the available information is insufficient.
Use precise terminology and avoid contradictory directions. If the model should prioritize one source over another, state that priority. For a summary, explain whether to include chronology, unresolved issues, or outcomes. For an email draft, specify the recipient relationship, goal, and relevant details, while keeping the language appropriate for the organization's voice. Avoid overloading a template with unrelated tasks; split distinct tasks when they need different context or output rules.
Add examples selectively
Examples can show a desired format or level of detail, but they should be representative and should not introduce facts that the template could repeat incorrectly. If a strict output schema is required, describe its fields and constraints clearly, and validate the result in the calling system. Do not use examples to replace actual grounding. A sample response that looks correct does not supply the current customer's facts.
Iterate through testing
Prompt engineering is iterative. Preview the resolved prompt, test it with different records and inputs, inspect where it follows or misses the instructions, and refine one issue at a time. Look for unsupported claims, irrelevant retrieved text, inconsistent tone, missing edge-case handling, and format deviations. A prompt may behave differently when fields are blank or when context is much longer than the typical example. Keep a test set of realistic cases so revisions can be compared rather than judged from memory.
Measure quality against the business requirement. For example, a case summary can be evaluated for factual coverage, readability, and whether it omits sensitive or irrelevant details. A customer response can be evaluated for groundedness, tone, completeness, and adherence to policy. If the result is wrong because the source data is missing, fix the resource or data preparation; adding more wording may not solve it. If the result violates a deterministic business rule, enforce that rule in Flow, Apex, validation, or another appropriate control rather than relying only on the prompt.
Make one instruction change at a time, then test the same scenarios again. This helps identify whether the change improved the output or introduced a new problem.
LLM responses are probabilistic. Strong instructions and grounding can improve quality, but they do not make output perfectly repeatable.
Extra concept: Prompt templates are part of a larger workflow. Consider where a human reviews the output, what happens if the prompt fails, and how the team will monitor output quality after launch. Official reference: Salesforce Trailhead, Prompt Builder Basics - https://trailhead.salesforce.com/content/learn/modules/prompt-builder-basics
Key takeaways
- Define task, context, constraints, audience, and output format explicitly.
- Use examples to clarify style or format, not to substitute for current grounded data.
- Test diverse cases and correct the real cause of poor output.
