Prompt Engineering Tutorial menu

Adding Context

Context is the background information the AI needs so that it does not have to guess.

Why Context Matters

The AI knows a lot about the world in general, but nothing about your situation: your class, your shop, your client, your code. Context fills that gap.

Without context:

Example

text
Write a sale announcement.

With context:

Example

text
I run "Ali Mobiles", a small phone accessories shop in Saddar, Karachi.
Most customers are students aged 16-25. We are having a sale on
Friday and Saturday: 25% off on earbuds and power banks.
Write a short Instagram caption (under 40 words) with 3 hashtags.

The second version can produce a caption you can actually post.

What Context to Include

TypeExample
Who you are"I am a second-year BS Computer Science student"
Your goal"I want to understand this for tomorrow's quiz"
Your level"I know basic Python but not classes"
Facts the AI cannot knowprices, dates, names, your company's policy
Source materiala document, email, code or data you paste in
What you tried"I already tried restarting, it did not help"

Pasting Documents: Use Delimiters

When you paste text, separate it clearly from your instructions. Use quotes, triple dashes or tags:

Example

text
Summarise the email below in 3 bullet points, then list any
deadlines with their dates.

<email>
Dear students, the mid-term exams start on 4 November.
Submit your project proposals by 28 October to the coordinator.
The library will stay open until 9 pm during exam week.
</email>

Delimiters stop the AI from mixing up your instructions with the document, especially when the document itself contains instructions.

Building Context in Code

Apps often add context automatically. Here a program puts the shop's details and a question together:

Example

python
shop = {
    "name": "Ali Mobiles",
    "area": "Saddar, Karachi",
    "hours": "11 am to 10 pm, closed Sunday",
}
question = "Are you open on Sunday?"

context = "\n".join(f"{k}: {v}" for k, v in shop.items())
prompt = f"Shop details:\n{context}\n\nAnswer the customer: {question}"
print(prompt)
Output
Shop details:
name: Ali Mobiles
area: Saddar, Karachi
hours: 11 am to 10 pm, closed Sunday

Answer the customer: Are you open on Sunday?

Now the AI can answer correctly ("No, we are closed on Sunday") instead of guessing.

How Much is Too Much?

  • Include what is relevant to the task. A whole 50-page manual for a one-line question can bury the important part.
  • Put the most important instruction at the start or the end, not hidden in the middle of a long text.
  • If the document is long, say exactly which part to focus on.

Ask yourself: "If I gave this prompt to a smart person who has never met me, could they do the job?" If not, add the missing context.

Ask the AI What It Needs

You can let the AI ask for the context:

Example

text
I want a study plan for my matric exams. Before you make it,
ask me up to 5 questions about my subjects, time and weak areas.

Exercise

Exercise

Why should you use delimiters like <email> ... </email> when pasting a document?

Learn Prompt Engineering with a teacher

Join the AI & Prompt Engineering course at Workownix, online or in Orangi Town, Karachi, and get a certificate.

See the course Ask on WhatsApp