AI Engineering Tutorial · Prompting · Lesson 8 of 25

Writing Clear Prompts

Prompts that work: context, a specific task, constraints and a defined output format.

Create a free account to save this page, take notes and track your progress. Sign in

Be specific

Models do best with the instructions you would give a capable new colleague: context (who the users are, what the data is), the task, constraints and the output format. Vague prompts get generic answers.

Weak Strong
"Summarise this." "Summarise this support ticket for the on-call engineer in 3 bullet points: problem, impact, what the customer tried."
"Is this review positive?" "Classify the review's sentiment as positive, negative or mixed. Reply with one word."

Structure long prompts

Separate instructions from data with clear markers such as XML-style tags, so the model knows what is an instruction and what is content:

<ticket>...customer text...</ticket>
Summarise the ticket above in 3 bullet points: problem, impact, what the customer tried.
A prompt with context, task, constraints and formatTry it yourself
def build_prompt(ticket):
    return (f"<ticket>\n{ticket.strip()}\n</ticket>\n"
            "Summarise the ticket above for the on-call engineer in exactly 3 bullet points:\n"
            "- Problem\n- Impact\n- What the customer already tried\n"
            "If something is unknown, write 'unknown'.")

print(build_prompt("Checkout fails with error 502 since 9am. All EU customers affected. Cleared cache, no change."))

Output

<ticket>
Checkout fails with error 502 since 9am. All EU customers affected. Cleared cache, no change.
</ticket>
Summarise the ticket above for the on-call engineer in exactly 3 bullet points:
- Problem
- Impact
- What the customer already tried
If something is unknown, write 'unknown'.

Test yourself

Why wrap user-supplied text in tags like <ticket>...</ticket>?

  1. To make the prompt shorter
  2. To separate data from instructions so the model treats it as content
  3. Tags are required by the API
  4. To hide it from the model
Show answer

Answer: To separate data from instructions so the model treats it as content

Clear delimiters help the model distinguish what to do from what to work on.

Was this page helpful?