Prompt Basics

Generative AI · Lesson 5 of 28 6 min read Updated

A prompt is the instruction you give an AI model. The same model can give a vague, generic answer or an excellent, ready-to-use one, and the difference is usually the prompt. Writing good prompts is called prompt engineering, but most of it is simply clear communication: the same skills that help you brief a new colleague.

In this lesson you will learn the five parts of a strong prompt, see weak prompts turned into strong ones, and build a small Python helper that assembles and checks prompts.

Why vague prompts fail

Imagine asking a new office assistant, "Write something about the meeting." They do not know which meeting, who will read it, how long it should be or what it is for. They will guess, and the guess will probably be wrong.

An AI model is in the same position, except it will not ask; it will confidently guess. Compare these two prompts:

Text
Write about the meeting.
Text
Write a short email to the 12 members of our Lucknow sales team summarising
today's meeting. Key decisions: the Diwali offer starts on 20 October, and
weekly reports move from Friday to Monday. Keep it under 120 words, friendly
but professional, and end with a reminder to reply if anything is unclear.

The second prompt leaves nothing important to guess. It will almost always produce an email you can send after a quick check.

The five parts of a strong prompt

PartQuestion it answersExample
TaskWhat exactly should the model do?"Write an email", "Summarise", "List 5 ideas"
ContextWhat background does it need?Facts, the document, the situation
AudienceWho will read the result?"first-year students", "a bank manager"
ConstraintsWhat limits apply?Length, tone, language, things to avoid
FormatWhat shape should the answer take?Bullet points, a table, three paragraphs, JSON

You do not need all five every time. A quick question ("What is the capital of Sikkim?") needs only the task. But for anything you plan to use, running through these five parts is the fastest way to a good result.

Some practical rules:

  • Start with a clear verb: write, summarise, explain, compare, list, rewrite, translate, check.
  • Be specific about numbers: "5 bullet points" beats "a few points"; "under 120 words" beats "short".
  • Say what you want, not only what you do not want. "Use simple words a 12-year-old knows" works better than "don't be complicated".
  • Separate your instructions from pasted material. Put the pasted text between clear markers, such as triple quotes or tags like <notice> and </notice>, so the model knows where your data starts and ends.

A prompt builder in Python

Writing the five parts as separate pieces makes prompts easier to reuse. This helper joins whichever parts you supply into one prompt:

PythonRun it yourself
def build_prompt(task, context="", audience="", constraints="", fmt=""):
    parts = [task]
    if context:
        parts.append(f"Context: {context}")
    if audience:
        parts.append(f"Audience: {audience}")
    if constraints:
        parts.append(f"Constraints: {constraints}")
    if fmt:
        parts.append(f"Format: {fmt}")
    return "\n".join(parts)

prompt = build_prompt(
    task="Write a notice announcing the inter-college cricket trials.",
    context="Trials are on Saturday at 7 am on the main ground in Rohtak. Bring your own kit.",
    audience="Students of all years",
    constraints="Under 80 words, energetic but clear, no emojis",
    fmt="A heading line, then 3 short sentences",
)
print(prompt)
Output
Write a notice announcing the inter-college cricket trials.
Context: Trials are on Saturday at 7 am on the main ground in Rohtak. Bring your own kit.
Audience: Students of all years
Constraints: Under 80 words, energetic but clear, no emojis
Format: A heading line, then 3 short sentences

You can paste the printed prompt into any assistant. Labels such as "Context:" and "Format:" are not magic words; they simply make the prompt easy for both you and the model to read.

Checking a prompt before you send it

You can even automate a rough checklist. The function below looks for signs of each part and reports what seems to be missing. It is a simple keyword check, not real understanding, but it builds a good habit.

PythonRun it yourself
import re

checks = {
    "a number (length or count)": r"\d",
    "an audience": r"\b(for|audience|students|customers|team|readers)\b",
    "a format": r"\b(bullet|table|list|paragraph|email|json|heading)s?\b",
}

def review(prompt):
    missing = [name for name, pattern in checks.items()
               if not re.search(pattern, prompt, re.IGNORECASE)]
    return "looks complete" if not missing else "missing " + ", ".join(missing)

prompts = [
    "Tell me about saving money.",
    "Explain 5 ways to save money for college students, as a bullet list.",
    "Write an email to my team about the new leave policy.",
]
for p in prompts:
    print(f"{p!r}: {review(p)}")
Output
'Tell me about saving money.': missing a number (length or count), an audience, a format
'Explain 5 ways to save money for college students, as a bullet list.': looks complete
'Write an email to my team about the new leave policy.': missing a number (length or count)

The third prompt names the audience (the team) and the format (an email), but says nothing about length, so the reply might be three lines or three pages.

Common mistakes

  • One-line prompts for important work. Spend one extra minute on context and constraints; it saves ten minutes of editing.
  • Several unrelated tasks in one prompt. Split them, or number them clearly.
  • Hiding the real goal. Say why you need something ("for a 2-minute speech", "to print on one A4 page"), because purpose shapes the answer.
  • Accepting the first answer. Treat it as a draft and ask for changes, as you will learn in Refining Prompts & Prompt Templates.

Key points

  • A prompt is the instruction you give a model; clear prompts get usable answers.
  • The five parts are task, context, audience, constraints and format.
  • Use specific numbers, start with a verb, and say what you want rather than what you do not want.
  • Mark pasted material clearly, with triple quotes or tags, so it is separate from instructions.
  • Building prompts from named parts makes them easy to check and reuse.

Exercise

Use build_prompt to create a prompt that asks for a polite WhatsApp-style message to a landlord in Pune, asking to delay this month's rent of ₹14,500 by 5 days because a salary is late. Include all five parts, then run the review checker on your prompt and make sure it reports "looks complete".

Show solution
Python
import re

def build_prompt(task, context="", audience="", constraints="", fmt=""):
    parts = [task]
    if context:
        parts.append(f"Context: {context}")
    if audience:
        parts.append(f"Audience: {audience}")
    if constraints:
        parts.append(f"Constraints: {constraints}")
    if fmt:
        parts.append(f"Format: {fmt}")
    return "\n".join(parts)

checks = {
    "a number (length or count)": r"\d",
    "an audience": r"\b(for|audience|students|customers|team|readers)\b",
    "a format": r"\b(bullet|table|list|paragraph|email|json|heading)s?\b",
}

def review(prompt):
    missing = [name for name, pattern in checks.items()
               if not re.search(pattern, prompt, re.IGNORECASE)]
    return "looks complete" if not missing else "missing " + ", ".join(missing)

prompt = build_prompt(
    task="Write a polite message asking my landlord to let me pay this month's rent 5 days late.",
    context="Rent is ₹14,500. My salary is delayed this month. I have always paid on time.",
    audience="My landlord in Pune, an older man who prefers respectful language",
    constraints="Under 60 words, warm and respectful, no excuses beyond the salary delay",
    fmt="One short paragraph suitable for a chat message",
)
print(prompt)
print(review(prompt))
Output
Write a polite message asking my landlord to let me pay this month's rent 5 days late.
Context: Rent is ₹14,500. My salary is delayed this month. I have always paid on time.
Audience: My landlord in Pune, an older man who prefers respectful language
Constraints: Under 60 words, warm and respectful, no excuses beyond the salary delay
Format: One short paragraph suitable for a chat message
looks complete

All five parts are present, so the model knows the facts, the reader, the limits and the shape of the answer.

Quick Quiz

1. Which prompt is most likely to give a usable result?

2. Why should you put pasted text between markers such as triple quotes or tags?

3. Which is the better constraint?

4. What can you do when you are unsure what context the model needs?

Learn Generative AI with a mentor

Free lessons get you started. Our AI Training & Workshops training adds real projects and code reviews from working developers.

  • Project-based learning
  • Mentor code reviews
  • Free counselling call