Prompt Engineering Prompt Structure

A good prompt structure turns a guess into a specification. Most effective prompts contain the same building blocks: a clear task, relevant context, constraints, optional examples and the output format.

The Building Blocks

  • Task - what to do, as a direct instruction ("Summarise", "Classify", "Rewrite").
  • Context - who the audience is, background facts, why the task exists.
  • Input - the data to work on, clearly separated.
  • Constraints - length, tone, language, things to avoid.
  • Examples - one or more input/output pairs (optional).
  • Output format - exact shape of the answer.

Use Delimiters

Separate instructions from data with clear markers such as XML-style tags, triple quotes or headings. This prevents the model from confusing your data with your instructions.

Summarise the customer email below for a support agent.
Use at most 3 bullet points. Note the customer's mood at the end.

<email>
Hi, I ordered a blender two weeks ago (order #5521) and it still hasn't arrived.
The tracking page hasn't updated in 6 days. I need it for a party on Saturday!
</email>
Sample response:
- Order #5521 (blender) placed two weeks ago, not delivered.
- Tracking has not updated for 6 days.
- Customer needs it before Saturday.
Mood: frustrated and anxious about the deadline.

Be Specific and Positive

Say what to do rather than only what not to do, and quantify where you can.

Weak:   Don't make it too long and don't be boring.
Better: Write 80-100 words in an upbeat tone, opening with a question.
(the second version gives the model measurable targets)

A Reusable Template

# Role
You are {role}.

# Task
{task}

# Context
{context}

# Rules
- {rule 1}
- {rule 2}

# Output format
{format}

# Input
<input>
{input}
</input>
(fill in the braces for each use case)

Put long documents first and the specific question at the end; many models answer better when the instruction sits close to where they start writing.

Frequently asked questions

How long should a prompt be?

As long as needed to remove ambiguity. Short prompts are fine for simple tasks; complex tasks often need several paragraphs.

Do XML tags work with every model?

Most modern models handle tags, markdown headings or triple quotes well. Pick one style and use it consistently.

Should I say please to an AI?

Politeness does not hurt, but clarity matters far more than courtesy words.