Home »
AI Prompts Tutorial
Context-Based Prompts
Context-based prompting is a technique in which additional background information is provided to an AI model before or along with the main instruction. The context helps the AI understand the situation, purpose, audience, or requirements of the task.
Context can make a prompt more specific because the AI model receives information about what the task is about and how the response should be prepared.
In this chapter, you will learn what context-based prompts are, how they work, different types of context, practical examples, and best practices for writing context-based prompts.
What Is a Context-Based Prompt?
A context-based prompt provides relevant background information along with an instruction or task.
For example:
I am creating a programming tutorial for beginners.
Explain Python functions using simple English and include two examples.
The information about the programming tutorial and beginners provides context for the task.
Another example is:
The reader has basic knowledge of HTML and CSS but has never used JavaScript.
Explain JavaScript variables using simple examples.
The information about the reader's existing knowledge helps define the level of the response.
How Do Context-Based Prompts Work?
A context-based prompt usually combines background information with a specific instruction.
Context
|
v
Instruction
|
v
AI Model
|
v
Generated Response
For example:
Context:
The content is intended for college students who are new to databases.
Instruction:
Explain relational databases and describe tables, rows, columns,
primary keys, and foreign keys.
The AI model uses the context to understand the intended audience and the instruction to determine the task.
Types of Context in AI Prompts
Different types of information can be used as context depending on the task.
Audience Context
Audience context tells the AI model who will read or use the response.
For example:
The audience consists of high school students with no programming experience.
Explain what artificial intelligence is using simple English.
The response can then be written at an appropriate level for the intended audience.
Purpose Context
Purpose context explains why the content or response is needed.
For example:
I am preparing a presentation for a college seminar.
Explain the main applications of artificial intelligence
and provide five short points that can be used on slides.
The purpose helps the AI model understand how the response will be used.
Background Context
Background context provides information that the AI model should know before performing the task.
For example:
The company provides online programming courses for beginners.
The main audience is students learning Python for the first time.
Write five course description ideas for Python beginners.
The company and audience information provides background for the requested content.
Technical Context
Technical context provides information about technologies, platforms, tools, or environments involved in the task.
For example:
The application is built using React and Node.js.
The database is MySQL.
The application needs user authentication.
Suggest a basic authentication architecture for this application.
The technical information helps define the environment in which the task should be performed.
Business Context
Business context provides information about an organization, product, customer, market, or business objective.
For example:
We operate an online education platform for programming students.
Our target audience is college students and working professionals.
Create five ideas for improving student engagement.
The business information helps the AI model generate ideas relevant to the specified situation.
Content Context
Content context provides existing material that the AI model needs to understand or process.
For example:
The following paragraph is part of a beginner programming tutorial.
Rewrite it in simpler English without changing its meaning:
"Encapsulation is an object-oriented programming concept
that restricts direct access to an object's internal state."
The existing content provides the context needed for the rewriting task.
Context-Based Prompts for Learning
Context-based prompts are useful for creating personalized learning material.
For example:
I understand basic Python syntax but have never worked with classes.
Explain Python classes and objects.
Start with the basic concept and then provide two simple examples.
The learner's existing knowledge gives the AI model context about where to begin.
Context-Based Prompts for Content Writing
Context can help generate content that matches a specific audience and purpose.
For example:
I am writing a beginner-friendly technology blog.
The readers have basic computer knowledge but are not programmers.
Write a 600-word introduction to machine learning.
Use simple English and include practical examples.
The context provides information about the website, audience, topic, and writing requirements.
Context-Based Prompts for Programming
Programming tasks often require technical context because the solution can depend on the programming language, framework, database, or environment.
For example:
I am developing a web application using Python and Flask.
The application uses MySQL as the database.
I need to retrieve all users from the users table.
Write a Flask route that retrieves and displays the users.
The technical context helps the AI model understand the environment before generating the code.
Context-Based Prompts for Debugging
When asking an AI model to identify programming problems, providing the relevant environment and expected behavior can make the task clearer.
For example:
This Python program is designed to calculate the average of numbers.
The program should accept a list of numbers and return the average.
The following code returns an incorrect result:
numbers = [10, 20, 30]
average = sum(numbers) / len(numbers)
Explain what the code does and suggest improvements.
The context explains the purpose of the code and the expected behavior.
Context-Based Prompts for Marketing
Marketing tasks often require information about the product, audience, brand, and objective.
For example:
We are launching an online Python course for college students.
The course is designed for beginners and includes practical projects.
Create five promotional headlines for the course.
Use a professional and engaging tone.
The context helps the AI model create marketing content that matches the product and audience.
Context-Based Prompts for Data Analysis
Data analysis tasks can require information about the data, business objective, and expected result.
For example:
The following sales data belongs to an online education platform.
The goal is to identify which courses generate the most revenue.
Analyze the data and identify the top three courses by revenue.
Present the results in a table.
The context explains the purpose of the analysis and helps define the expected result.
Context-Based Prompts for Research
Research prompts can include information about the research topic, audience, scope, and objective.
For example:
I am researching the use of artificial intelligence in education.
The research is intended for undergraduate students.
Identify five major applications of AI in education.
For each application, provide a short explanation and one example.
The context helps narrow the scope of the research task.
Context-Based Prompts for Customer Support
Customer support responses often require information about the customer, product, issue, and desired resolution.
For example:
The customer purchased an online Python course.
The customer has completed the first three modules but cannot access
the fourth module.
Write a polite customer support response explaining that the issue
has been reported and the support team is checking the account.
The context provides the information needed to create an appropriate response.
Context-Based Prompt Structure
A context-based prompt can follow a simple structure:
Context:
Provide the relevant background information.
Task:
Clearly describe what the AI should do.
Requirements:
Specify important rules or details.
Output:
Describe how the response should be presented.
For example:
Context:
The article is intended for beginner programmers.
The readers understand basic programming concepts but have never used APIs.
Task:
Explain REST APIs.
Requirements:
Explain REST, HTTP methods, and status codes.
Include one practical example.
Output:
Use headings, short paragraphs, and a simple table.
Context vs Instruction
Context and instruction have different purposes in a prompt.
| Component |
Purpose |
Example |
| Context |
Provides background information. |
The audience consists of beginner programmers. |
| Instruction |
Defines the task. |
Explain Python functions. |
| Requirements |
Defines additional rules. |
Use simple English and include two examples. |
| Output |
Defines how the response should be presented. |
Use headings and short paragraphs. |
How to Write an Effective Context-Based Prompt
Start by providing only the context that is relevant to the task.
For example, instead of:
I work for a company. We have many customers. We sell software.
Our team works remotely. We have offices in different locations.
Write a customer support email about a delayed order.
A more focused prompt could be:
We sell software subscriptions to small businesses.
A customer's subscription activation has been delayed.
Write a polite customer support email explaining the delay
and confirming that the issue is being investigated.
The second prompt provides relevant context without unnecessary information.
Use Relevant Context
Only include information that can help the AI model understand or complete the task.
For example:
The tutorial is written for beginners who know basic Java syntax.
Explain Java inheritance with a simple example.
The information about the audience and their existing knowledge is relevant to the task.
Keep Context Organized
For complex tasks, separate context from the main instruction.
For example:
Context:
The website publishes programming tutorials for beginners.
The article should be easy to understand and technically accurate.
Task:
Write an introduction to Java inheritance.
Requirements:
Use simple English.
Include one practical example.
Avoid unnecessary advanced terminology.
This structure makes the prompt easier to understand and modify.
Best Practices for Context-Based Prompts
Follow these practices when creating context-based prompts:
- Provide context that is relevant to the task.
- Clearly separate context from instructions when the prompt is complex.
- Include information about the target audience when relevant.
- Explain the purpose of the task when it affects the response.
- Provide important technical or business background.
- Avoid unnecessary information.
- Specify the expected output when the format is important.
- Use clear and direct language.
- Review the generated response to ensure that the provided context was correctly used.
- Update the context when the requirements or situation changes.
Example of an Effective Context-Based Prompt
The following prompt combines context, audience, task, requirements, and output format:
Context:
I am creating a beginner-friendly programming tutorial.
The readers understand basic Python syntax but have never used APIs.
Task:
Explain what REST APIs are and how they work.
Requirements:
Explain HTTP methods, status codes, and API requests.
Use simple English and include one practical example.
Output:
Use headings, short paragraphs, and a simple code example.
This prompt provides the AI model with enough context to understand the audience, purpose, technical level, task, and expected response.
Advertisement
Advertisement