AI Engineering Tutorial · Prompting · Lesson 8 of 25
Writing Clear Prompts
Prompts that work: context, a specific task, constraints and a defined output format.
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.
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'.
See Prompt engineering overview and Use XML tags.
Test yourself
Why wrap user-supplied text in tags like <ticket>...</ticket>?
To make the prompt shorterTo separate data from instructions so the model treats it as contentTags are required by the APITo 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.