Lesson 3 / 29
The Anatomy of a Good Prompt
Break a prompt into role, task, audience, rules, format and input.
Six building blocks
Reliable prompts usually contain: (1) a role or perspective ("support analyst"); (2) the task in one clear sentence; (3) the audience and purpose; (4) rules and constraints (length, tone, what to avoid, what to do when unsure); (5) the output format; and (6) the input itself, clearly separated from the instructions. Not every prompt needs all six, but checking this list quickly finds what is missing when output disappoints. Using a template also makes prompts consistent across a team.
A reusable template, run
I ran this plain-Python (standard library only) example. The template fills in role, task, audience, rules, format and input, and prints the final prompt (259 characters, about 65 tokens by the rough 4-characters-per-token rule).
from string import Template
PROMPT = Template("""You are a $role.
Task: $task
Audience: $audience
Rules:
$rules
Output format: $fmt
Input:
$text""")
rules = ["Use only the input text.", "Max 2 sentences.", "If unsure, say 'unknown'."]
p = PROMPT.substitute(
role="support analyst",
task="summarise the customer's complaint",
audience="a busy manager",
rules="\n".join(f"- {r}" for r in rules),
fmt="plain text",
text="My order 4821 arrived late and the box was damaged.",
)
print(p)
print("characters:", len(p), "| rough tokens:", round(len(p) / 4))
Output:
You are a support analyst. Task: summarise the customer's complaint Audience: a busy manager Rules: - Use only the input text. - Max 2 sentences. - If unsure, say 'unknown'. Output format: plain text Input: My order 4821 arrived late and the box was damaged. characters: 259 | rough tokens: 65
Quick check: Why separate the input from the instructions?
- Because models cannot read inputs
- To hide the prompt
- To save a token
- So the model can tell what to do from what to process
Answer
So the model can tell what to do from what to process — Clear separation avoids confusion and reduces injection risk.