Good prompt engineering means giving a language model clear instructions, the right context, examples of what you want, a defined output format and room to reason, then testing the prompt on realistic inputs like you would test code. The twelve techniques below cover most real needs; the most important habit is evaluation, not clever wording.
Why does prompting matter if models keep improving?
Better models need less coaxing, but they still can't read your mind. They don't know your audience, your company's rules, the format your code expects or which facts are authoritative. A prompt is a specification. Vague specifications produce vague software, and the same is true of prompts. Prompting is also the cheapest lever you have: it costs nothing to change and you can test it in minutes, so it's always the first thing to get right before reaching for retrieval or fine-tuning.
What are the core techniques?
1. Be specific about the task. "Summarise this" is weak. "Summarise this support ticket in three bullet points for a team lead: the customer's problem, what has been tried, and what is needed next" is strong.
2. Give context and audience. Say who the output is for and why: "for a first-year student with no maths background" changes everything about an explanation.
3. Assign a role carefully. "You are a senior tax accountant reviewing…" can focus style and vocabulary. It doesn't add knowledge the model lacks, so pair it with real context.
4. Separate instructions from data with delimiters. Put user content inside clear markers (for example, XML-style tags or triple quotes) and tell the model to treat it only as data. This improves accuracy and reduces the risk of prompt injection.
5. Show examples (few-shot). Two or three input-output pairs teach format and tone better than paragraphs of description. Make examples diverse, or the model will copy their quirks.
6. Specify the output format. Ask for JSON with named fields, a table with given columns, or a fixed template. In code, validate the output and retry on failure; many APIs also offer structured-output modes.
Which techniques help with reasoning?
7. Ask for step-by-step reasoning. For multi-step problems, asking the model to work through the steps before answering often improves accuracy. In applications, separate the reasoning from the final answer so you can show only the answer.
8. Break big tasks into a chain. Instead of one giant prompt, run steps: extract facts, then analyse, then write. Each step is easier to test and debug. This is the bridge to building agents.
9. Let the model check its work. A second pass, "check this answer against the source and list any unsupported claims", catches many errors, especially when the checker sees the source text.
Which techniques improve factual accuracy?
10. Ground answers in provided sources. Supply the relevant documents and instruct: "Answer only from the context below. If the answer isn't there, say you don't know." This is the heart of RAG and the strongest defence against hallucination.
11. Ask for citations. Request quotes or source IDs for each claim, then verify them in code where possible.
12. Give permission to be uncertain. Models tend to answer everything. Explicitly allowing "I don't know" or "not enough information" reduces confident fabrication.
How do the techniques compare?
| Technique | Best for | Cost |
|---|---|---|
| Clear task + audience | Everything | None |
| Few-shot examples | Format, tone, classification | Longer prompts |
| Structured output | Anything parsed by code | Validation logic |
| Step-by-step reasoning | Maths, logic, multi-step questions | More output tokens |
| Prompt chaining | Complex workflows | More calls, more latency |
| Grounding + citations | Factual Q&A | Retrieval system |
What do sampling settings do?
Temperature controls randomness: low values make outputs focused and repeatable (good for extraction, classification and code), higher values more varied (good for brainstorming). Top-p limits choices to the most probable tokens that together make up probability p. Max tokens caps length and cost. For production tasks that need consistency, start with a low temperature and change it only if tests show a benefit.
How do you test prompts properly?
- Collect 30–100 realistic inputs, including edge cases and tricky ones.
- Define pass criteria: correct fields, no unsupported facts, right tone, valid JSON.
- Run the prompt on all inputs and score the outputs, automatically where possible.
- Change one thing, rerun and compare. Keep a log of versions and scores.
- Rerun the suite whenever you change models; behaviour differs between versions.
An example scorecard layout, not measured results; set your own thresholds per task.
What are common prompt mistakes?
- Stuffing many unrelated instructions into one prompt.
- Contradictory rules ("be brief" and "explain in detail").
- Relying only on prompts for safety or permission checks that code should enforce.
- Judging a prompt on one or two outputs instead of a test set.
- Never re-testing after a model update.
How do prompts fit into real applications?
In production, prompts are templates filled with data from your system: the user's question, retrieved documents, account details, tool results. They live in version control next to the code, are reviewed like code, and are tested with the evaluation suite on every change. Treating them this way, rather than as text pasted into a chat window, is what separates hobby experiments from dependable products.
What does a well-structured prompt look like?
A reliable production prompt usually has the same sections in the same order:
- Role and goal: who the assistant is and what success means.
- Rules: what it must and must not do, including when to say "I don't know".
- Context: retrieved documents or account data, clearly delimited.
- Examples: two or three input-output pairs showing the desired style.
- Task input: the user's actual request, delimited as data.
- Output format: the exact structure expected, such as JSON fields.
Keeping this structure consistent makes prompts easier to review, debug and improve as a team, the same way coding conventions make code easier to maintain.
How do prompts differ across tasks?
Extraction tasks (pull the invoice number and amount) need strict formats, low temperature and validation. Classification tasks benefit most from few-shot examples covering every category, including tricky borderline cases. Writing tasks need audience, tone and length guidance plus a good example. Analytical tasks benefit from step-by-step reasoning and source grounding. Coding tasks need the relevant code, the language version and the conventions of your codebase. Treating every task with the same generic prompt is one of the most common reasons outputs disappoint.
Which prompt patterns are worth reusing?
A few patterns appear in almost every mature LLM application: a classifier prompt with labelled examples for each category; an extractor prompt that returns strict JSON with a null for anything missing; a grounded answerer that answers only from supplied context with citations; a critic prompt that reviews another output against a checklist; and a router prompt that decides which tool or workflow should handle a request. Keeping a small library of tested versions of these saves time on every new feature.
Is prompt engineering enough on its own?
Prompting is a core skill, but reliable products also need retrieval, evaluation, guardrails and software around the model. Read is a prompt engineering course enough? for the bigger picture. In Program Zero, prompt engineering, RAG and agents are taught together in the generative AI and LLM course, after you've learned how transformers work underneath.