Prompt Basics
A prompt is everything you send to a model: instructions, background information, examples and the input to work on. Because the model generates the most plausible continuation of that text, the prompt is your main steering wheel. Prompt engineering is the practice of writing prompts that get reliable, useful results — less magic words, more clear communication.
Note: The playgrounds in this section build and inspect prompts with plain Python. They do not call a model; where a model's answer is shown, it is described as typical behaviour, not a recorded run.
The parts of a good prompt
| Part | Purpose | Example |
|---|---|---|
| Role / context | who the model should be, who the audience is | "You help customers of a bicycle shop." |
| Task | what to do, as a clear instruction | "Summarise the review below." |
| Input data | the material to work on, clearly separated | the review text inside <review> tags |
| Constraints | length, tone, things to avoid | "At most 2 sentences. Neutral tone." |
| Output format | how the answer should look | "Reply as JSON with keys sentiment and summary." |
| Examples (optional) | show what you want | one or two input → output pairs |
Not every prompt needs every part, but checking the list is a quick way to find what is missing.
Building a prompt from parts
Treat prompts like code: assemble them from named pieces so that each piece can be changed and tested on its own.
def build_prompt(task, data, context="", constraints=(), output_format=""):
parts = []
if context:
parts.append(context)
parts.append(task)
if constraints:
parts.append("Rules:\n" + "\n".join(f"- {c}" for c in constraints))
if output_format:
parts.append(f"Output format: {output_format}")
parts.append(f"<input>\n{data}\n</input>")
return "\n\n".join(parts)
prompt = build_prompt(
context="You help the support team of a bicycle shop.",
task="Summarise the customer review below for the team.",
data="Bought the City 3 last month. Gears are smooth but the saddle is painful after 20 minutes.",
constraints=["At most 2 sentences", "Mention any product problem explicitly"],
output_format="plain text",
)
print(prompt)You help the support team of a bicycle shop.
Summarise the customer review below for the team.
Rules:
- At most 2 sentences
- Mention any product problem explicitly
Output format: plain text
<input>
Bought the City 3 last month. Gears are smooth but the saddle is painful after 20 minutes.
</input>
Vague vs. specific
Compare two prompts for the same job. The first leaves the model to guess the audience, length and focus; the second makes those choices explicit. A small checker can flag missing pieces:
CHECKS = {
"audience": ["for ", "audience", "team", "beginner", "customer"],
"length": ["sentence", "words", "bullet", "short", "at most"],
"format": ["json", "list", "table", "bullet", "plain text"],
"input marked": ["<", '"""', "###"],
}
def review_prompt(prompt):
low = prompt.lower()
return [name for name, hints in CHECKS.items() if not any(h in low for h in hints)]
vague = "Summarise this: Bought the City 3 last month. Saddle hurts."
specific = ("Summarise the review for our support team in at most 2 sentences, as plain text.\n"
"<review>Bought the City 3 last month. Saddle hurts.</review>")
for name, p in [("vague", vague), ("specific", specific)]:
missing = review_prompt(p)
print(f"{name:<8} missing: {', '.join(missing) if missing else 'nothing'}")vague missing: audience, length, format, input marked
specific missing: nothing
This keyword checker is deliberately crude — it is a reminder of what to think about, not a quality score. With the vague prompt a model will typically produce a reasonable summary, but its length and focus will vary from run to run; with the specific one, you get answers that are easier to use and to test.
Prompts are iterative
Good prompts are rarely written in one go. A practical loop:
- Write a first version and run it on a handful of realistic inputs, including awkward ones.
- Look at the failures: was the instruction ambiguous? Was information missing? Was the format unclear?
- Change one thing at a time and re-run the same inputs.
- Keep the inputs as a small test set (see Evaluating LLM Apps) so you can tell whether a change helped.
versions = {
"v1": "Summarise the review.",
"v2": "Summarise the review in at most 2 sentences.",
"v3": "Summarise the review in at most 2 sentences. Mention any product problem explicitly.",
}
for name, text in versions.items():
print(f"{name} ({len(text.split()):>2} words): {text}")v1 ( 3 words): Summarise the review.
v2 ( 8 words): Summarise the review in at most 2 sentences.
v3 (13 words): Summarise the review in at most 2 sentences. Mention any product problem explicitly.
What prompts can't do
A prompt cannot give the model knowledge it doesn't have (recent events, your private data) — you must put that information into the prompt. Nor can it guarantee correctness: even a perfect prompt gets a probabilistic answer. For anything important, validate the output in code or have a person check it.
Tip: Write prompts for a smart new colleague who knows nothing about your project. If a person would need to ask a clarifying question, the model probably needs that information too.
Test yourself
Which part of a prompt tells the model what the answer should look like?
- Role
- Input data
- Output format
- Temperature
Why separate input data from instructions, e.g. with tags?
- Tags make the prompt shorter
- So the model can tell which text is the material to work on and which is the instruction
- Models ignore text outside tags
- It is required by all APIs
What is a good way to improve a prompt?
- Change many things at once and hope
- Change one thing at a time and re-run the same set of test inputs
- Always make it longer
- Add the word 'please' several times