GENERATIVE AI • LESSON 4

What Is Context?

Context is the information given to an LLM so it can understand what you are talking about and produce a relevant answer.

CORE IDEA

Context gives the LLM the information it needs for the current request.

Think of context as the information the model can see while answering your question.

01

A Simple Example

Imagine you tell an AI:

"I am learning Python."

Then you ask:

"What should I learn first?"

The second question makes sense because the previous message provides context. The AI understands that you are asking about learning Python.

PREVIOUS INFORMATION "I am learning Python."
+
CURRENT QUESTION "What should I learn first?"
LLM Python learning advice

The previous information is part of the context.

02

Context vs Question

These are different things.

QUESTION

What the user asks now

"Where is my order?"

CONTEXT

Information needed to answer

Order #10025
Status: Shipped
Delivery: August 27

QUESTION + RELEVANT CONTEXT LLM ANSWER
03

Real-World Example — E-commerce

Imagine you are building an AI assistant for a Magento store.

A customer asks:

"Where is my order?"

The LLM alone does not know the customer's latest order status. Your application needs to retrieve the real order information first.

01 Customer "Where is my order?"
02 Magento Gets order information
03 Context Order #10025
Status: Shipped
Delivery: August 27
04 LLM Generates a natural-language answer
AI RESPONSE

Your order #10025 has been shipped and is expected to arrive on August 27.

Notice the important architecture:

MAGENTO DATABASE ORDER INFORMATION CONTEXT LLM HUMAN-FRIENDLY ANSWER
04

Where Can Context Come From?

In real GenAI applications, context can come from different sources.

01 Conversation

Previous messages in the conversation.

02 Database

Customer, order, product, or business data.

03 Documents

Company policies, PDFs, manuals, and knowledge bases.

04 APIs

Live information such as weather, prices, or shipping.

05

Context in a Python AI Application

A developer can combine relevant information with the user's question before sending it to the LLM.

from openai import OpenAI

client = OpenAI()

customer_context = """
Order: #10025
Status: Shipped
Expected delivery: August 27
"""

question = "Where is my order?"

prompt = f"""
Customer information:
{customer_context}

Customer question:
{question}

Answer the customer clearly and simply.
"""

response = client.responses.create(
    model="gpt-5.6",
    input=prompt
)

print(response.output_text)

The important part is not the Python syntax. The important idea is that the application gives the LLM the relevant information it needs.

CUSTOMER DATA + QUESTION PROMPT LLM ANSWER
06

Context vs Model Knowledge

Do not confuse what the model learned during training with the information your application provides for the current request.

MODEL KNOWLEDGE

Information learned during model training.

+
NEW CONTEXT

Information provided for this request.

ANSWER

Generated using both.

For example, your LLM may understand what Magento is, but it does not automatically know that order #10025 was shipped five minutes ago.

Your application must provide that current information as context.

REMEMBER THIS

Context is the information the LLM can use for the current request.

  • Context helps the LLM understand what the user is talking about.
  • Context can come from conversations, databases, documents, APIs, and tools.
  • The LLM's learned knowledge is different from the context provided by your application.
  • Real AI applications often retrieve relevant data and provide it to the LLM as context.
QUICK CHECK

Test Your Understanding

What is context?

Answer: Information provided to an LLM so it can understand and answer the current request.

Where can context come from?

Answer: Conversations, databases, documents, APIs, tools, and other relevant data sources.

Does an LLM automatically know a customer's latest order status?

Answer: No. The application normally retrieves the current order information and provides it as context.

LESSON 4 • TOPIC COMPLETE

You now understand what context is.

You know why context matters, how applications provide context to LLMs, and how databases, conversations, documents, and APIs can supply information for an AI response.

NEXT TOPIC

Conversation Context

Next, you will learn how LLM applications remember previous messages and use conversation history to understand follow-up questions.