The same AI model can give a vague, generic answer or a precise, useful one. Usually the difference is the prompt. Good prompting isn't about magic phrases. It's about giving the model what a smart new colleague would need to do the job well.
1. Be specific about the task
Models can't read your mind. Say exactly what you want, who it's for and what "good" looks like.
| Vague | Specific |
|---|---|
| Write about capacitors. | Write a 300-word introduction to capacitors for 14-year-olds who know what voltage is. Use one everyday analogy and end with a simple circuit they could build. |
| Fix my code. | This Python function should return the average of a list but crashes on an empty list. Fix it so it returns 0 for an empty list, and explain the change in one sentence. |
2. Give context and explain why
Background helps the model make sensible choices you didn't think to spell out. "Keep it short, because it will be read on a phone" works better than "keep it short", because the model understands the goal and can apply it to things you didn't mention.
3. Show examples
One or two examples of the output you want are often more effective than a paragraph of description. Models copy patterns closely, so make your examples varied and exactly in the format you want back.
Turn each product into a one-line description.
Example:
Product: 10k resistor, 1/4 W, pack of 100
Description: A hundred everyday 10 kΩ quarter-watt resistors for breadboard projects.
Product: Raspberry Pi Pico 2 W
Description:
4. Structure long prompts
When a prompt contains instructions plus documents, data or code, separate them clearly so the model can tell them apart. Headings work, and Anthropic recommends XML-style tags for Claude:
<instructions>
Summarise the customer's problem in one sentence, then list the steps they've already tried.
</instructions>
<email>
...the customer's email...
</email>
For long documents, put the document first and your question at the end.
5. Ask for the format you need
If your code will read the answer, say exactly what shape it should be: "Reply with only a JSON object with the keys name and price." Many APIs can also guarantee valid JSON with a feature called structured outputs. See JSON for beginners.
6. Say what to do, not only what to avoid
"Write in plain, flowing paragraphs" works better than "don't use bullet points". Telling the model the behaviour you want gives it something to aim at.
7. Let it think on hard problems
For maths, logic or tricky decisions, asking the model to work through the problem before answering often improves accuracy. Many current models have a built-in "thinking" or "reasoning" mode that does this for you.
8. Test and improve
Treat a prompt like code. Try it on several realistic inputs, including awkward ones, look at where it goes wrong, and change one thing at a time. Keep a few test cases so you can check that a fix for one problem hasn't broken something else.
A quick checklist
- Have I said who the output is for, and why?
- Would a smart person new to this task have everything they need?
- Have I shown an example of a good answer?
- Have I said what format I want back?
- Have I tested it on more than one input?
Going deeper
Treat prompts like code
For anything beyond a one-off chat, keep prompts in files under version control, with a note of what each change was for. Build templates with clearly marked slots for variable content, and keep the fixed instructions at the start, which also makes them cacheable. See prompt caching.
Measure with an evaluation set
An eval is a fixed set of test inputs with a way to score the outputs. Scoring can be exact (did the JSON have the right fields?), rule-based (is the answer under 50 words?), or done by another model following a written rubric. Run the whole set after every prompt change. Small wording changes can fix one case and quietly break another, and only an eval shows that.
Split complex jobs into steps
One giant prompt that extracts, analyses, decides and writes is hard to debug. A chain of smaller prompts, each with one job and its own checks, is usually more reliable, and lets you use cheaper models for the simple steps.
Long documents
- Put long documents near the top of the prompt and your instructions and question after them.
- Wrap each document in tags with its source, such as
<document source="manual.pdf">, so the model can cite it. - For accuracy, ask the model to quote the relevant passages first, then answer based on those quotes.
Prompt injection
When a prompt includes outside content, such as emails, web pages or user uploads, that content might contain instructions aimed at the model ("ignore your previous instructions…"). Clearly separate trusted instructions from untrusted data, tell the model to treat the data only as information, limit what actions the model can take, and check outputs before acting on them. No prompt wording makes injection impossible, so the safest defence is limiting what a successful attack could do.
Know when prompting isn't the answer
If a model needs facts it doesn't have, add them with retrieval (RAG) rather than longer instructions. If it needs to calculate or look things up, give it tools (agents). If it needs to follow a strict format, use structured outputs.
Sources
The main references behind this guide. Numbers we worked out ourselves, such as the code outputs, come from running the code.