Early-bird price on the GenAI & Agentic AI Engineer Bootcamp batch. Grab a seat →

A prompt works when it tells the model four things: who it should act as (role), what it needs to know (context), what good output looks like (examples) and what shape the answer should take (format). Add a clear task and the source material, and most weak answers improve at once. You do not need special phrases or tricks; you need to write the brief you would give a capable new colleague.

Key takeaways

  • A model only knows what is in the prompt and what it absorbed in training. Anything you leave out, it guesses.
  • Role, context, examples and format are the four parts that remove the most guessing.
  • Explain why you want something, not only what. Vendors report that stating the reason gives more targeted answers.
  • Examples steer tone and layout more reliably than adjectives such as "professional" or "concise".
  • Prompting is trial and error. Test a prompt on several real inputs before you rely on it.

For the background on why wording matters so much, see generative AI explained.

Why does the structure of a prompt matter?

A language model writes by continuing from the text it is given. A one-line request leaves the audience, purpose, length, tone and facts undefined, so the model fills them in with the most typical choice. The result reads fluently and fits nobody in particular.

Anthropic's prompting guide suggests thinking of the model as "a brilliant but new employee who lacks context on your norms and workflows". It also gives a practical test: show your prompt to a colleague with minimal context and ask them to follow it. If they would be confused, the model will be too.

What are the four parts of a good prompt?

A stack shows the parts of a prompt from top to bottom: role, context and source material, examples, the task, and the output format.

PartWhat it answersExample line
RoleWho is writing?"You are a customer support lead at an online electronics shop."
ContextWhat is the situation, and why does it matter?"The customer's order is nine days late. We want to keep them as a customer."
ExamplesWhat does good output look like?Two past replies that match your house style.
FormatWhat shape should the answer take?"Under 120 words. Plain text. No bullet points."

Role

A role sets the level of expertise and the tone. Anthropic's guide notes that setting a role "focuses" the model's behaviour and tone, and that even a single sentence makes a difference. Be specific: "a payroll specialist explaining a payslip to a new graduate" works better than "an expert".

A role does not give the model knowledge it lacks. Calling it a tax lawyer will change the vocabulary, not the accuracy.

Context

Context is the background a person would need: the audience, the goal, the constraints and the source material. Two habits help most.

Say why. Anthropic's guide gives the example of replacing a bare rule such as "never use ellipses" with the reason behind it, and reports that explaining the motivation helps the model deliver more targeted responses.

Supply the facts. If the answer depends on a policy, a transcript or a spreadsheet, paste or attach it and tell the model to use it. This is also the main protection against invented details, as explained in why AI models hallucinate and how grounding reduces it.

Examples

Showing is more reliable than describing. Anthropic calls examples "one of the most reliable ways" to steer format, tone and structure, and recommends three to five that are relevant to the real task and varied enough that the model does not copy an accidental pattern. OpenAI's guidance says the same thing in its own words: show a diverse range of possible inputs with the desired outputs.

The trade-off is that a model can copy examples too closely. If all three samples open with "Thank you for reaching out", every reply will.

Format

State the length, layout and anything to leave out. "A table with columns for risk, owner and due date" is a format. "Make it clear" is not. If another program will read the output, name the exact structure you need.

How should I lay out a longer prompt?

Once a prompt contains instructions, background, examples and a document, the model needs to tell them apart. Both major vendors recommend visible separators:

  • Anthropic recommends XML-style tags such as <instructions>, <context> and <example>, and says wrapping each type of content in its own tag reduces misinterpretation.
  • OpenAI notes that Markdown headers and lists help mark distinct sections of a prompt.

Either works. Pick one and be consistent.

For long documents, order matters. Anthropic advises placing long material near the top of the prompt, above the instructions and the question, and reports that putting the question at the end can improve response quality by up to 30 per cent in its tests, especially with several documents.

If you are building an application, there is one more layer. Standing instructions go in a system or developer message, and the user's request goes in a user message. OpenAI's documentation states that developer messages are prioritised ahead of user messages.

A before-and-after example

A support agent needs to reply to a customer whose order is late. The details below are invented for the example.

Before

Write a reply to this customer about their late order.

The likely result is a long, generic apology with placeholders such as "[order number]", a made-up delivery date or none at all, and a tone that may not match the company.

After

<role>
You are a customer support lead at Kaveri Electronics, an online shop.
</role>

<context>
Customer: Meera Iyer. Order KE-48213, a 65 W laptop charger.
Promised delivery: 12 November. Today is 21 November.
Cause: the courier's regional hub was closed for flood repairs.
New confirmed delivery date: 24 November.
We are refunding the Rs 99 shipping fee. No other compensation is approved.
We want to keep this customer, so be direct and do not make excuses.
</context>

<example>
Hi Arjun, your order KE-47102 is late, and I am sorry. It was held at
the courier's hub and will now reach you on 3 October. I have refunded
your shipping fee. Reply here if it has not arrived by then.
</example>

<task>
Write a reply to Meera's message below.
</task>

<format>
Under 110 words. Plain text, no bullet points.
Give the new date in the first two sentences.
Do not promise anything that is not listed in the context.
</format>

<customer_message>
It has been over a week. Where is my charger? This is my second email.
</customer_message>

What changed

Problem in the first promptFix in the second
No facts, so the model invents or leaves gapsOrder number, dates, cause and refund are supplied
No toneRole, reason and one example set the voice
No limitsWord count, layout and "do not promise" rule
Instructions and customer text mixed togetherEach part sits in its own labelled section

The second prompt is longer, and that is the trade-off. It takes two minutes to write and uses more tokens. For a one-off email that may not be worth it. For a reply you will send in some form fifty times a month, it is, because you write the structure once and change only the context.

How do I reuse a prompt that works?

Turn it into a template with fixed parts and changing parts. In a chat tool, that can be a saved note with blanks. In code, it can be a small function. This Python example joins the parts and skips any that are empty:

def build_prompt(role, context, examples, task, output_format):
    parts = {
        "role": role,
        "context": context,
        "examples": examples,
        "task": task,
        "format": output_format,
    }
    sections = [
        f"<{name}>\n{text.strip()}\n</{name}>"
        for name, text in parts.items()
        if text and text.strip()
    ]
    return "\n\n".join(sections)


prompt = build_prompt(
    role="You are a customer support lead at Kaveri Electronics.",
    context="Order KE-48213 is 9 days late. New delivery date: 24 November.",
    examples="",
    task="Write a reply to the customer's message.",
    output_format="Under 110 words. Plain text.",
)
print(prompt)

Running it prints four labelled sections, with the empty examples section left out. Teams that depend on prompts in production go further and store them under version control; see prompt versioning: treating prompts like code.

How do I know my prompt is good enough?

OpenAI's documentation is frank that model output is non-deterministic, so prompting involves trial and error. One good answer proves little.

  • Test on five to ten real inputs, including an awkward one: an angry message, a missing field, a question the source does not answer.
  • Change one thing at a time so you know what helped.
  • Re-test when the model changes. A prompt tuned for one model version can behave differently on the next. OpenAI recommends pinning production applications to a specific model snapshot and building evaluations that measure prompt behaviour.
  • Watch the length. Every example and document you add uses tokens and can crowd out what matters; see tokens and context windows.

What can a prompt not fix?

  • Missing information. No wording makes a model know your sales figures. Supply them.
  • Tasks beyond the model. Exact arithmetic on a large table, or guaranteed identical output every time, needs a tool or code, not a better sentence.
  • The need for review. A strong prompt lowers the error rate. It does not make the output safe to send unchecked when the stakes are high.

Common questions

Do I need to say "please" or use special keywords?

No. Politeness does no harm, but clarity is what changes the result. Neither Anthropic's nor OpenAI's guidance relies on magic words; both stress clear instructions, context and examples.

How long should a prompt be?

As long as the brief needs and no longer. A short question is fine for a simple fact or a quick rewrite. A task with an audience, constraints and source material deserves a few paragraphs.

Should I ask the model to think step by step?

Many current models have a built-in reasoning mode, so the phrase matters less than it once did. For multi-step problems it still helps to ask the model to show its working, because you can then see where the reasoning went wrong.

Does the same prompt work on every model?

Mostly, but not exactly. The four-part structure carries across vendors. Details such as preferred separators, default answer length and how literally instructions are followed differ, so test again when you switch.

Free download: The AI fundamentals field guide

How large language models work, why they get things wrong, how to write a prompt that works and how to judge a tool before your team adopts it. Plain English, no coding. See what’s inside.