In this article · 14 sections
- 01What a prompt is made of
- 021. Be specific and explicit
- 032. Give the model context
- 043. Show examples
- 054. Define the output format
- 065. Break complex tasks into steps
- 076. Set boundaries and handle uncertainty
- 087. Defend against prompt injection
- 098. Test with real cases
- 109. Version and manage prompts
- 1110. Consider cost and latency
- 12Common mistakes
- 13Checklist
- 14Final thoughts
Large language models respond to the instructions you give them, which means the quality of your prompts directly shapes the quality of your product’s AI features. Prompt engineering is not magic phrases. It is clear communication, structured thinking and careful testing. Product teams that treat prompts as part of the product, rather than a one-off string, ship more reliable features.
This guide covers the fundamentals. If you are earlier in the journey, start with what to consider before adding AI features.
What a prompt is made of
A prompt for a product feature usually contains several parts:
- Role and goal: what the model is doing and for whom
- Instructions: the task and the rules
- Context: background information or retrieved documents
- Examples: sample inputs and ideal outputs
- Input: the user’s actual request
- Output format: how the answer should be structured
Separate these clearly, for example with headings or delimiters, so the model can tell instructions from data.
1. Be specific and explicit
Vague prompts produce vague results.
- Weak: “Summarise this.”
- Stronger: “Summarise the following customer email in two sentences for a support agent. State the customer’s problem first, then the requested action.”
State the audience, length, tone and what to include or leave out. If something matters, say it.
2. Give the model context
Models only know what is in their training and in the prompt. Provide the facts they need, such as product details, policies or the user’s data, and tell them to rely on it. When accuracy matters, ground answers in your own documents and instruct the model to say when the answer is not in the provided material. Techniques that retrieve relevant documents and add them to the prompt are often called retrieval-augmented generation.
3. Show examples
Examples are one of the most effective tools. Giving a few sample inputs with the ideal outputs (few-shot prompting) teaches format, tone and edge-case handling better than description alone.
- Use examples that reflect your real data
- Cover variety, including difficult cases
- Keep them consistent in style
4. Define the output format
If software will use the output, make it predictable.
- Ask for a specific structure, such as JSON with named fields
- Provide the schema and an example
- Validate the result in code, and handle failures by retrying or falling back
- Many model APIs offer structured output features that enforce a schema, which is more reliable than asking nicely
5. Break complex tasks into steps
For multi-part problems, divide the work.
- Split into separate prompts (classify, then extract, then draft) so each is simple and testable
- Ask the model to reason through steps when it improves accuracy, and decide whether you need to show that reasoning to users
- Use code for deterministic work such as calculations, lookups and formatting, and reserve the model for language tasks
6. Set boundaries and handle uncertainty
- Tell the model what not to do, for example “Do not give legal or medical advice”
- Instruct it to ask a clarifying question or say it does not know instead of guessing
- Define behaviour for off-topic or inappropriate requests
- Remember that instructions are not guarantees. Add checks in your system as well.
7. Defend against prompt injection
Users, or documents the model reads, may contain instructions that try to override yours. Treat all external text as untrusted.
- Clearly delimit user input and tell the model to treat it as data
- Limit the model’s permissions and available actions
- Require confirmation before consequential actions
- Filter or review outputs where harm is possible
8. Test with real cases
Prompts should be tested like code.
- Build an evaluation set of realistic inputs, including edge cases and failures you have seen
- Define what a good answer looks like for each, with human review or clear criteria
- Run the set whenever you change the prompt, model or settings
- Track accuracy, format errors, tone, latency and cost
- Log real-world failures (with privacy care) and add them to the set
Do not judge a prompt from three examples you tried by hand.
9. Version and manage prompts
- Keep prompts in version control, not scattered across code
- Record which model and settings each version was tested with
- Review prompt changes like code changes
- Plan for model updates, since behaviour can shift when the provider changes a model
10. Consider cost and latency
Longer prompts and outputs cost more and take longer. Keep prompts concise, trim unneeded context, choose smaller models for simple tasks and stream outputs so users see progress. Measure cost per successful result, not just per request.
Common mistakes
- Treating prompts as magic spells
- Vague instructions
- No examples or format definition
- Testing on a handful of cases
- Ignoring injection risks
- Changing models without re-testing
Checklist
- Clear role, task and audience
- Relevant context included, with grounding for factual answers
- Examples covering normal and edge cases
- Output format defined and validated
- Complex tasks split into steps
- Boundaries and uncertainty handling specified
- Injection risks considered
- Evaluation set and regression testing in place
- Prompts versioned and reviewed
- Cost and latency measured
Final thoughts
Good prompts are clear, tested and maintained like any other part of the product. Write precisely, show examples, validate outputs and measure results. If you want help designing and shipping AI-powered features responsibly, see our app development service or contact us. You may also like our guide to using AI responsibly in design and development.