Prompt Engineering Best Practices That Work in Production
Prompt engineering best practices are simple habits: write clear instructions, show examples, test every change and version your prompts like code.
On this page
Short answer
Prompt engineering best practices are the habits that keep prompts working once they leave your notebook and run in production. They cover how you write instructions, how you show the model what good output looks like, how you test each change, and how you track versions so a working prompt does not quietly break. Good practice turns prompt writing from guesswork into a repeatable process.
What are prompt engineering best practices?
Prompt engineering best practices are the working habits that make prompts reliable in real use. A prompt that works once in a test is not the same as a prompt that works every day, for many users, on messy input. The practices below close that gap.
They fall into four groups. First, write instructions a stranger could follow: clear, specific and ordered. Second, show the model what you want with examples, not just words. Third, test every change against a fixed set of cases before it ships. Fourth, treat prompts as code: version them, review changes and roll back when a change makes things worse.
These habits matter because prompts are part of your product, not a side note. When a prompt changes, the behaviour of the feature changes with it. Teams that follow these practices can change a prompt on a Tuesday and know by Wednesday whether it helped or hurt, because they measured it. The explainer in what prompt engineering is covers the basics; this article covers the practices that keep prompts working over time.
Write instructions like a checklist
Write instructions the way you would write a checklist for a new colleague: short steps, in order, with nothing left unsaid. Start with the role, then the task, then the constraints, then the output format. If a step matters, write it down; do not assume the model will guess it.
Be specific about the output. Say how long it should be, what format to use, and what to include or leave out. 'Summarise this ticket' gives you a paragraph of any length and any focus. 'Summarise this ticket in three sentences: what the customer wants, what has been tried, and what happens next' gives you something you can use.
Put the most important rule where the model cannot miss it, and repeat it if it is critical. A rule buried in the middle of a long prompt is easy to miss, especially when the input is long. Keep the prompt as short as the task allows, and move long background material into the data the model reads, not into the instructions.
Use plain words and avoid clever phrasing. The model follows the literal meaning of your words, so a vague instruction such as 'make it sound professional' produces uneven results. A concrete instruction such as 'use short sentences and no slang' produces the same result every time.
Show the model what good output looks like
Showing examples is usually more effective than adding more words to the instructions. A model that sees two or three examples of the output you want will copy the format, tone and level of detail far more reliably than one that only reads a description of it.
Pick examples that cover the range of cases, not just the easy ones. Include one example of a short input, one of a long input, and one of an awkward case, such as a message with missing information. If the model only sees clean examples, it will struggle with the messy input that real users send.
Keep examples short and consistent. Each example should show the input and the exact output you want, with no extra commentary. If your examples disagree with each other, for instance one uses bullet points and another uses paragraphs, the model will pick one at random.
Update the examples when the task changes. An example that shows an old format will keep pulling the model back to that format, even after you change the instructions. When you change the output format, change the examples in the same edit, and check the result on your test set.
Test prompts like code
Test prompts the way you test code: with a fixed set of cases that you run every time something changes. A test set of 20 to 50 real examples, covering the common cases and the awkward ones, is enough for most features and far better than trying a prompt once and shipping it.
| Test case type | What to include | What good looks like |
|---|---|---|
| Typical input | The most common real examples | Correct, well formatted output |
| Long input | The longest real examples | Nothing important dropped |
| Missing data | Inputs with gaps or blanks | Asks for the missing piece |
| Ambiguous input | Requests with two readings | Picks the likely reading and says so |
| Hostile input | Text that tries to steer the model | Ignores the injected instruction |
| Edge format | Odd characters, lists, tables | Format stays clean |
Score each case with a simple pass or fail, and write down what failed. A prompt that passes 45 of 50 cases is good; a prompt that passes 50 of 50 on a test set you built yourself may just mean the test set is too easy. Add the cases that fail in production to the set, so the same failure cannot come back unnoticed.
Run the test set after every change, even a small one. A one-word change can shift the model's behaviour in ways you cannot predict, and the test set is the only way to see it before users do.
Version and review your prompts
Version your prompts the way you version code. Give each prompt a version number, keep the old versions, and write a short note when you change one, saying what you changed and why. When a change makes things worse, you can go back to the version that worked.
Review prompt changes like code changes. A second person should read the new prompt, run the test set and check the results before it ships. Two pairs of eyes catch the vague instruction, the missing example and the rule that contradicts another rule, all of which are easy to miss when you wrote the prompt yourself.
Keep prompts in one place, not scattered across notebooks, documents and chat logs. A single file or a small prompt store, with each prompt named and dated, means the team always knows which version is live and who changed it last. Teams building larger LLM features usually keep prompts with the code they belong to, which is why LLM development work treats prompts as part of the product, not as a side note.
Track how prompts perform over time. Log the prompt version with each output, so that when users report a problem you can see which version produced it. Without that link, you cannot tell whether a bad output came from a bad prompt, bad input or a model change.
Plan for bad output
Plan for bad output, because even a good prompt will produce it sometimes. A model can hallucinate a fact, miss a key detail, or return the right answer in the wrong format. Your system should catch these cases before the user sees them.
Start with the cheap checks. Verify the format: is the output the right length, in the right structure, with the fields you asked for? Then verify the facts you can check: dates, prices, names and numbers against your own data, not against the model's memory.
Decide what happens when a check fails. The usual options are to retry with a clearer prompt, to fall back to a simpler template, or to hand the case to a human. Pick one in advance for each failure type, so the system does not silently show a wrong answer.
Keep a human in the loop where the stakes are high. Drafts, summaries and suggestions can go to a human for a quick check; actions such as sending a message or changing a record should need approval. The prompt is only one part of the system, and the checks around it are what make it safe to use, as explained in prompt engineering vs fine-tuning, which also covers when prompting alone is not enough.
Example (hypothetical): fixing a support drafting prompt
Example (hypothetical): a support team uses a prompt to draft replies to customer tickets. The first version says 'draft a helpful reply to this ticket'. The drafts come back in different lengths, some miss the customer's question, and a few invent policy details that do not exist.
The team rewrites the prompt as a checklist: read the ticket, answer the customer's question first, use only the policy facts in the provided list, keep the reply under 120 words, and end with the next step. They add two examples, one short ticket and one long one, showing the exact format they want.
They build a test set of 40 real tickets, including 5 with missing information and 3 with angry wording, and score each draft as pass or fail. The first version passes 22 of 40. After the rewrite and two rounds of fixes, it passes 37 of 40, and the 3 failures are all tickets where the customer asked about a policy the team had not added to the fact list.
The team adds the missing policy facts and the 3 failed tickets to the test set, versions the prompt as v3, and logs the version with every draft. Review time falls from about 4 minutes per draft to about 1 minute, because the drafts now need small edits instead of rewrites. Across 40 drafts a day, that saves roughly 2 hours of review time.
What are the common mistakes?
The most common prompt engineering mistakes are writing vague instructions, skipping tests, and letting prompts drift without version control.
- Vague instructions. 'Make it good' or 'be helpful' means something different every time, so the output varies for no reason.
- No examples. Describing the format in words is weaker than showing two or three examples of it.
- Testing once and shipping. A prompt that works on one example can fail on the next, and you will only find out from users.
- Long prompts with buried rules. The longer the prompt, the easier it is for the model to miss the rule that matters most.
- No version control. Changing a prompt without keeping the old version means you cannot go back when the change makes things worse.
- Trusting the output blindly. A confident-sounding answer can still be wrong, so check facts and format before showing it to users.
Key takeaways
- Write instructions like a checklist: short, ordered and specific
- Examples beat descriptions for showing the model what you want
- A fixed test set turns prompt changes from guesses into measurements
- Version prompts like code so you can roll back a bad change
- Check format and facts before showing model output to users
Frequently asked questions
How long should a prompt be?
As short as the task allows. A short prompt with clear instructions and two or three examples usually beats a long prompt with every detail spelled out. Long prompts bury the rules that matter and cost more to run. If your prompt keeps growing, move background material into the data the model reads.
How many examples should I include in a prompt?
Two or three examples are enough for most tasks. Pick examples that cover the range of cases, including one awkward case, and keep them short and consistent with each other. More examples help only when the task has many different shapes, and each extra example adds cost and length.
Should I test prompts with real user data?
Yes, but remove personal information first. Real examples show the messy input your users actually send, which is what breaks prompts in production. A test set built only from clean, made-up examples will pass in testing and fail in use.
When is prompt engineering not enough?
Prompting cannot teach a model facts it does not know, fix a task that needs reliable arithmetic, or guarantee a specific format every time. When the model keeps failing on the same cases, consider fine-tuning, retrieval from your own data, or a structured tool that does the hard part instead of the model.
How do I know if a prompt change helped?
Run the same test set before and after the change and compare the pass rate. A change that raises the pass rate from 40 to 47 out of 50 helped. A change that raises it on easy cases but breaks hard ones did not. Never judge a change by trying one example.
Do prompts need to change when the model changes?
Yes, sometimes. A new model version can respond differently to the same prompt, so re-run your test set after a model update. If the pass rate falls, adjust the prompt and version the change. Keeping the test set fixed is what makes this check possible.