Anatomy of a Great Prompt

Reviewed & published by Brayan K

Great prompts are built from a handful of parts: a role, a task, context, a format, constraints, and examples. Learn these six and you can assemble a strong prompt for almost anything.

Part of the free Prompt Engineering course at LearnCodingFast — hands-on lessons with worked examples and the output they print, plus practice exercises and a quick quiz.

You won’t need all six every time. The trick is to include the parts that remove the guesswork for your particular request — the more ambiguous the job, the more parts you add.

What You'll Learn in This Lesson

1 The six building blocks

Most strong prompts mix some of these ingredients. Use the ones your task needs:

PartExample
🎭 Role“Act as a friendly nutrition coach.”
🎯 Task“Plan three quick weekday lunches.”
🧰 Context“I’m vegetarian and short on time.”
📐 Format“Give it as a 3-row table.”
🚧 Constraints“Under 15 minutes, no nuts.”
📎 Examples“Match the style of this sample.”

Think of it like stacking layers. Each layer you add removes one more thing the AI would otherwise have to guess.

2 Watch a prompt come together

Same goal — a lunch idea — but the strong version layers in the parts:

No role, no constraints, no format. You’ll get a generic list.

Five parts, almost nothing left to guess.

Try it for real

A prompt is not one lump of text — it is six labelled pieces stuck together, and you can hold each one separately. Build the whole thing here, then delete FORMAT and CONSTRAINTS and read the difference. Nothing is hidden: the second prompt still asks the question, it just stops saying how long the answer should be and what the model may use.

# The six blocks, as code. Each is just a labelled string; the prompt is their sum.
# Comment one out and re-run to see exactly what the model loses.

parts = {
    "ROLE":        "You are a support agent for a UK bicycle shop.",
    "TASK":        "Answer the customer's question.",
    "CONTEXT":     "Policy: repairs are free within 12 months of purchase.",
    "FORMAT":      "Reply in two sentences, no bullet points.",
    "CONSTRAINTS": "Use only the policy text. If it is not covered, say so.",
    "EXAMPLE":     'Q: "Is my puncture covered?" -> A: "Punctures are wear and tear, so they are not covered."',
}

def build(selected):
    return "\n\n".join(f"{k}:\n{parts[k]}" for k in selected)

full = build(list(parts))
print("=== FULL PROMPT ===")
print(full)
print()
print("characters:", len(full))

# Now drop the two blocks beginners most often forget.
without = build([k for k in parts if k not in ("CONSTRAINTS", "FORMAT")])
print()
print("=== SAME PROMPT, NO FORMAT AND NO CONSTRAINTS ===")
print(without)
print()
print("characters:", len(without))
print()
print("Nothing here is magic: the second prompt still asks the question. What it")
print("stops doing is telling the model how long to be and what it may use, which")
print("is why replies to it drift in length and invent policy that does not exist.")
# 🎯 YOUR TURN — assemble a prompt from the six blocks.

parts = {
    "ROLE":        "You are a librarian at a city library.",
    "TASK":        "Answer the reader's question about borrowing.",
    "CONTEXT":     "Policy: adults may borrow 12 books for 3 weeks.",
    "FORMAT":      "Reply in one sentence.",
    "CONSTRAINTS": "Use only the policy text.",
}

# 1) Join each block as  "NAME:\n<text>"  with a blank line between blocks.
def build(selected):
    return "\n\n".join(f"{k}:\n{parts[___]}" for k in selected)
    # 👉 replace ___ with  k

# 2) Build the prompt from every block, in the order they appear above.
prompt = build(list(___))
# 👉 replace ___ with  parts

print(prompt)
print()
print("blocks:", len(prompt.split("\n\n")))

# ✅ Expected output:
# ROLE:
# You are a librarian at a city library.
#
# TASK:
# Answer the reader's question about borrowing.
#
# CONTEXT:
# Policy: adults may borrow 12 books for 3 weeks.
#
# FORMAT:
# Reply in one sentence.
#
# CONSTRAINTS:
# Use only the policy text.
#
# blocks: 5

Common Mistakes (and the fix)

⏱ Test Yourself — Timed Quiz

10 quick questions, 12 seconds each. Instant feedback — beat the clock!

🎉 Lesson Complete

Practice quiz

What are the building blocks of a great prompt covered here?

  • Role, task, context, format, constraints, examples
  • Only the task
  • Color, font, size
  • Username and password

Answer: Role, task, context, format, constraints, examples. A strong prompt often combines role, task, context, format, constraints, and examples.

The 'task' part of a prompt is…

  • Who the AI should pretend to be
  • The clear action you want the AI to do
  • The word count
  • The list of examples

Answer: The clear action you want the AI to do. The task states the action: summarize, write, explain, compare, and so on.

Giving a 'role' means…

  • Telling the AI who to act as, like a teacher or chef
  • Setting the temperature
  • Choosing the font
  • Pasting an error

Answer: Telling the AI who to act as, like a teacher or chef. A role, such as 'act as a nutritionist', shapes the perspective and tone.

Why include a 'format' instruction?

  • It slows the AI down
  • So the answer comes back in the shape you want, like a table or 5 bullets
  • It is required by law
  • It hides the answer

Answer: So the answer comes back in the shape you want, like a table or 5 bullets. Specifying format gives you a tidy, ready-to-use result.

'Constraints' in a prompt are…

  • The limits and rules, like 'under 100 words' or 'no jargon'
  • The AI's mood
  • The login time
  • A type of token

Answer: The limits and rules, like 'under 100 words' or 'no jargon'. Constraints set boundaries the answer must respect.

Adding 'context' to a prompt means…

  • Adding background the AI needs to do the task well
  • Making it longer for no reason
  • Choosing a color
  • Repeating the task twice

Answer: Adding background the AI needs to do the task well. Context is the relevant background: audience, situation, goal, and details.

Including an 'example' helps because…

  • It shows the AI the style or pattern you want
  • It confuses the model
  • It is decorative only
  • It removes the task

Answer: It shows the AI the style or pattern you want. An example demonstrates the desired style or structure to copy.

Do you need all six parts in every prompt?

  • Yes, always all six
  • No — use the ones that reduce ambiguity for your task
  • Never use more than one
  • Only role and password

Answer: No — use the ones that reduce ambiguity for your task. Use the parts that remove guesswork; simple tasks need fewer.

Which prompt is best structured?

  • fix this
  • Act as an editor. Rewrite this paragraph to be clearer, under 80 words, in plain English, like the example below.
  • make it good
  • do the thing

Answer: Act as an editor. Rewrite this paragraph to be clearer, under 80 words, in plain English, like the example below.. It has a role, task, constraints, format, and an example reference.

The biggest payoff of structuring prompts is…

  • Longer answers
  • Fewer rounds of back-and-forth and more on-target results
  • Brighter colors
  • Faster typing

Answer: Fewer rounds of back-and-forth and more on-target results. Structure removes ambiguity, so you reach a good answer faster.

Continue this course

Frequently asked questions

What are the parts of a great prompt?

A strong prompt usually combines six building blocks: a role (who the AI should act as), the task (what to do), context (background it needs), format (the shape of the answer), constraints (rules and limits), and examples (a sample of the style you want). You rarely need all six at once, but the more ambiguous your request, the more of them help.

Do I have to include every part every time?

No. Use the pieces that remove guesswork for your specific task. A quick question may only need a clear task. A trickier request, like rewriting copy for a specific audience in a specific format, benefits from adding role, context, format, and constraints. Think of them as ingredients you mix to taste.

What is the difference between context and constraints?

Context is the background the AI needs to do the job well, such as the audience, the situation, or your goal. Constraints are the rules and limits the answer must respect, such as a word count, a banned-jargon rule, or 'no new tools'. Context informs the task; constraints bound it.

Why do examples help so much?

An example shows the model the exact style, tone, or structure you want, which is far clearer than describing it in words. If you paste one good sample and say 'match this style', the AI can copy the pattern directly instead of guessing what 'good' looks like to you.