1Purpose first
Why prompting still matters, and what has moved.
I started my AI learning journey with prompt engineering. It is not out of date. On many real workloads you cannot always fine-tune a model or wire in fresh context, so the prompt is still the first lever you reach for.
Some older tactics have since moved out of the prompt text and into the API itself. This page keeps the ones that still hold and shows the modern version where the API now does the job.
2The tactics at a glance
What each tactic is and why it matters.
| Tactic | What it is | Why it matters |
|---|---|---|
| Use delimiters | Mark where the input text starts and ends | Keeps content separate from instructions |
| Ask for structured output | Get JSON that matches a schema | Replies a program can use directly |
| Check conditions first | Verify an assumption before answering | Stops the model inventing structure |
| Few-shot prompting | Show worked examples | Consistent tone and format |
| Give the model time to think | Solve independently before judging | Avoids rubber-stamping a wrong answer |
| Dictate the output format | Spell out the exact fields | Output usable without a human reading it |
| Know hallucination exists | Models can sound sure about things that are not real | The core risk in enterprise use |
| Reduce hallucination | Ground the answer in source text | Answers you can trace to evidence |
| Iterate | Refine a prompt in a loop | Prompts rarely work the first time |
3Use delimiters
Keep content separate from instructions.
What it is. Mark exactly where the input text starts and ends, using triple quotes, backticks, angle brackets or XML-style tags, so the model can tell your instructions apart from the material to work on.
Why it matters. When user-supplied text is mixed into a prompt, the model can mistake it for instructions. Clear boundaries keep content as content.
<instructions>
Summarise the customer message in one sentence.
</instructions>
<customer_message>
{message}
</customer_message>
Anthropic's guidance recommends consistent, descriptive XML tags for exactly this, especially when a prompt mixes instructions, context, examples and inputs.
4Ask for structured output
From free text to data.
What it is. Get the reply as JSON that matches a schema you define, so it loads straight into a dictionary.
Why it matters. It turns a chat reply into something a pipeline can use, with no string-splitting. Asking for JSON in plain words only requests the format. Providers now let you enforce a schema instead.
response = client.messages.create(
model="MODEL_ID_FROM_THE_DOCS",
max_tokens=300,
messages=[{"role": "user", "content": message}],
output_config={
"format": {
"type": "json_schema",
"schema": {
"type": "object",
"properties": {
"category": {"type": "string"},
"urgent": {"type": "boolean"},
},
"required": ["category", "urgent"],
"additionalProperties": False,
},
}
},
)
OpenAI offers the same idea: a JSON schema with strict turned on. Its older "JSON mode" only guarantees valid JSON, not that your fields exist.
5Check conditions first
Validate before generating.
What it is. Before the model does the task, have it check that the input actually meets the condition the task assumes.
Why it matters. It stops the model inventing structure that was never there. This is validation before generation.
You will be given text in triple quotes. If it contains a sequence of instructions,
rewrite them as numbered steps. If it does not, write exactly: "No steps provided."
"""{text}"""
A paragraph describing a sunny afternoon should come back as "No steps provided", not as made-up steps. You can then test for that exact reply in code.
6Few-shot prompting
Show, do not only tell.
What it is. Show the model a worked example of what a good answer looks like, instead of only describing it.
Why it matters. For tone and format consistency, such as a ticket summary or an escalation template, one good example often does more than paragraphs of instruction.
<examples>
<example>
Message: "My invoice shows the wrong amount."
Reply: "Thanks for flagging this. I've sent it to our billing team, who will correct it within two working days."
</example>
</examples>
Write a reply in the same style for this message:
<message>{message}</message>
One example is the minimum. Anthropic's guidance suggests several well-chosen, varied examples (it mentions three to five) wrapped in their own tags, so the model picks up the pattern and not an accident of one example.
7Give the model time to think
Verdicts after reasoning.
What it is. Have the model work out its own solution first, and only then judge someone else's answer.
Why it matters. A model that jumps straight to a verdict is more likely to wave through a wrong answer. In a grading or validation setup, the safer design is: solve independently, then compare.
First work out your own solution to the problem. Then compare your solution to the student's. Only then decide whether the student's solution is correct.
8Dictate the output format
Fields you can parse.
What it is. Spell out the exact fields and order you want in the reply.
Why it matters. It makes the output usable downstream without a person reading every response.
Use this format: Question: <the question> Student solution: <the student's answer> Actual solution: <your own worked answer> Matches: yes or no Grade: correct or incorrect
Naming the fields means a program can parse each line reliably. Where a provider offers enforced structured output (see above), prefer that to free-text formatting.
9Hallucination is a limit
Confident, fluent and wrong.
What it is. A language model can produce fluent, confident text about things that are not real. Ask about a product that does not exist and it will often describe it anyway.
Tell me about the AeroGlide X900 toothbrush. (a product I made up for this example)
Why it matters in an organisation. An ungrounded model can invent a policy, a number or a contract clause with the same confidence as a correct answer. The risk is not that it sounds unsure. The risk is that it does not.
10Reducing hallucination
Ground the answer in source text.
What it is. Ground the answer in real source text. Find the relevant passage first, then answer only from it.
Why it matters. The difference between "tell me about X" and "using only the text below, tell me about X" is the difference between an answer and a guess.
<document>
{policy_text}
</document>
First quote the sentences from the document that are relevant to the question.
Then answer using only those quotes. If the document does not contain the answer,
say "I can't find that in the document."
Question: {question}
Anthropic's guidance for long documents recommends exactly this quote-first step. It is the manual version of what retrieval-augmented systems (RAG) automate. It is worth knowing by hand before you trust a framework to do it for you.
11Prompting is iterative
A loop, not a one-shot write.
A prompt is rarely right the first time. Treat it as a loop you tune against real examples.
| If the output is… | Try… |
|---|---|
| Too long | State a limit, for example a number of sentences or words |
| Too technical | Name the audience and the level |
| Focused on the wrong thing | Say what to focus on and what to leave out |
| Hard to use downstream | Specify a format, or use enforced structured output |
12Check yourself
Short questions and one line to remember.
Do delimiters fully protect against prompt injection?
No. They help the model separate instructions from content, but you should also limit what the model can do and validate its output in code.
What is the difference between asking for JSON and using structured outputs?
Asking only requests the format. Structured outputs enforce a schema you supply, so the fields you need are there.
Why solve a problem independently before judging someone else's answer?
Because a model that goes straight to a verdict tends to agree with whatever it was shown. Working it out first gives it something to compare against.
What is the quote-first technique for?
Reducing made-up answers by forcing the model to find evidence in the source before it answers.