Prompt Engineering Basics: Roles, Clear Instructions, Context, Output Format and the Prompt Checklist
What Is a Prompt?
A prompt is the text you send to a model. A better prompt gives a better answer. Think of the model as a very fast helper who knows nothing about your situation unless you tell it.
The Roles
| Role | Used for |
|---|---|
| system | Rules and behavior that apply to the whole chat, such as tone and limits |
| user | The person's request |
| assistant | The model's earlier replies, sent back as history |
The Five Parts of a Good Prompt
- Task: what to do, in one clear sentence
- Context: facts the model needs
- Rules: limits, such as length or things to avoid
- Format: how the answer should look
- Examples (optional): one or two samples
Before and After
| Weak prompt | Better prompt |
|---|---|
| Tell me about our refund policy | You are a support agent. Using only the policy text below, explain the refund rules to a customer in 3 short bullet points. If the answer is not in the text, say 'I do not know'. |
| Fix this code | Find the bug in this Python function, explain it in one sentence, then show the fixed code only. |
Build a Prompt in Code
python
def build_prompt(task, context, rules, fmt):
return (f"Task: {task}\n\nContext:\n{context}\n\n"
f"Rules:\n- " + "\n- ".join(rules) + f"\n\nFormat: {fmt}")
p = build_prompt(
task="Summarize the customer email.",
context="Hi, my order #123 arrived broken. I want a replacement.",
rules=["Max 20 words", "Do not invent facts"],
fmt="One sentence",
)
print(p)
Result
Task: Summarize the customer email. | | Context: | Hi, my order #123 arrived broken. I want a replacement. | | Rules: | - Max 20 words | - Do not invent facts | | Format: One sentence
Tips That Work
- Be specific about the audience and length
- Say what to do, not only what to avoid
- Put long documents inside clear markers such as
<document> ... </document> - Ask for a format you can parse, such as JSON or a list
- If something fails, change one thing and test again
Keep prompts in files Store prompts as text files or constants so you can version and test them like code.
Do not put secrets in prompts Anything in a prompt can leak in an answer. Keep keys and private data out.
Practice
- Rewrite a vague prompt of your own using the five parts
- Run both versions and compare
- Save the winner in a file
Conclusion
Clear task, context, rules and format make prompts reliable. Test and version them like code.
Quick Summary: Roles; five parts; before and after; template; tips.

