Context Determination

Earn 25 points (50 with Pro) in two steps

  1. ① Read through the lesson — each section gets a ✓ as you scroll through it.
  2. ② When every section has a ✓, tap Complete lesson.

0 of 12 read · keep scrolling

✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro

Lesson: Context Determination in Prompt Engineering

Introduction: Why Context is the Foundation of Prompting

When we interact with large language models (LLMs), it is easy to treat them as simple search engines or automated typists. However, the true power of these models lies in their ability to reason, synthesize, and format information based on the specific constraints and background information we provide. This background information is what we call "context." Without clear, intentional context, an AI model is forced to guess your intent, often leading to generic, hallucinated, or irrelevant outputs.

Context determination is the process of defining the boundaries, the persona, the audience, and the objective of a prompt before the actual task is requested. Think of it like briefing a new employee on their first day. If you tell an employee, "Write a report," they will likely ask, "For whom? What is the goal? What tone should I use?" If you send that same request to an AI without context, you are essentially asking it to fly blind.

Mastering context determination is the single most effective way to transition from a casual user who gets inconsistent results to a professional user who treats the AI as a reliable tool. This lesson will guide you through the structural components of context, how to frame your objectives, and how to avoid the common pitfalls that plague most prompt engineering attempts.


Not read yet

The Anatomy of Context

To provide effective context, you must break down the request into its constituent parts. We can visualize this as a pyramid: the foundation is the persona/role, the middle is the audience/objective, and the top is the specific constraint. If any of these layers are missing, the structure becomes unstable.

1. Persona/Role Attribution

Assigning a persona tells the model which subset of its vast training data it should prioritize. If you ask for financial advice, you want the model to act like a Chartered Financial Analyst rather than a random internet forum user.

  • Example of weak context: "Explain how to invest money."
  • Example of strong context: "Act as a professional financial advisor with a focus on long-term retirement planning for middle-income earners. Explain the trade-offs between index funds and individual stock selection."

2. The Audience

The audience dictates the complexity, vocabulary, and structure of the output. Explaining quantum physics to a five-year-old requires a completely different approach than explaining it to a graduate physics student.

  • Example of weak context: "Explain black holes."
  • Example of strong context: "Explain the concept of black holes for a high school science newsletter. Use analogies related to gravity, but avoid heavy mathematical notation."

3. The Objective (The "Why")

The objective defines the output's purpose. Are you looking to persuade, inform, entertain, or troubleshoot? Defining the goal helps the model prioritize which information to include and which to omit.

Callout: The "Why" vs. The "What" The "What" is the task (e.g., "Write a blog post"). The "Why" is the objective (e.g., "Convince small business owners to switch to cloud-based accounting software to save time"). The "Why" allows the model to select persuasive arguments rather than just listing features.


Not read yet

Practical Implementation: Step-by-Step Context Crafting

To effectively determine context, follow this structured process every time you draft a prompt for a complex task.

Step 1: Identify the "Who"

Before typing the prompt, write down who the model should be. If you are struggling to define a role, use a descriptive adjective. Instead of "Act as a writer," use "Act as a concise technical writer who specializes in API documentation."

Step 2: Define the "To Whom"

Who is the final consumer of this information? If the output is for an internal team, you can use industry jargon. If it is for a customer-facing support page, you must use plain, empathetic language.

Step 3: Establish Constraints

Constraints are the "guardrails" of your prompt. These include word count, tone, formatting requirements, and forbidden topics.

Step 4: Assemble the Prompt

Combine these elements into a logical flow. Here is a template you can follow:

  1. Role: "You are a [Role]."
  2. Task: "Your task is to [Task]."
  3. Audience: "The audience is [Audience]."
  4. Constraints: "Please follow these rules: [Constraint 1, Constraint 2]."

Not read yet

Code-Based Context: Technical Examples

When working with LLMs via API, context is often handled through "System Messages." System messages are the primary way to define the model's behavior for the duration of the conversation.

Example: Setting a System Message in Python

# This is a conceptual example using a standard chat completion format
messages = [
    {"role": "system", "content": "You are a senior cybersecurity analyst. Your tone is professional, cautious, and technical. You always suggest risk mitigation strategies first."},
    {"role": "user", "content": "I'm seeing a lot of failed login attempts on my web server. What should I do?"}
]

# The model will now respond with the context of a security professional
# rather than a generic tech support assistant.

Explanation of the Code

In this example, the system role establishes the foundation. By setting the tone to "professional, cautious, and technical" and explicitly requesting "risk mitigation strategies," we narrow the model's focus. Without this system message, the model might provide basic advice like "change your password," which is insufficient for someone managing a web server.

Note: System messages are not suggestions; they are instructions. In most modern models (like GPT-4 or Claude 3), the system message is treated with higher priority than the user message. Use it for the core "identity" of the AI.


Not read yet

Best Practices for Context Determination

1. Be Explicit, Not Implicit

Do not assume the model knows what you mean by "good." Define "good." If you want a report to be "professional," define that as "using active voice, avoiding buzzwords, and keeping sentences under 20 words."

2. Provide Examples (Few-Shot Prompting)

One of the best ways to provide context is to show, not just tell. If you want a specific style, include 2-3 examples of that style within your prompt. This is known as "few-shot prompting."

3. Iterative Refinement

Your first prompt will rarely be perfect. If the model misses the mark, do not just re-run the prompt. Analyze the output to see where the context was lacking. Did it use the wrong tone? Add a constraint about tone. Was the information too shallow? Add a constraint about depth.

4. Use Delimiters

When providing large blocks of context, use delimiters like triple backticks (```), XML tags (), or dashes (---) to separate your instructions from the data you want the model to process. This prevents the model from getting confused about what is an instruction and what is content.


Not read yet

Common Pitfalls and How to Avoid Them

Pitfall 1: Overloading the Context

While context is important, giving the model a 5,000-word essay of instructions is counter-productive. This is known as "prompt bloating." If the prompt is too long, the model may experience "lost in the middle" phenomena, where it forgets the instructions in the center of your prompt.

  • Solution: Keep instructions concise. Group them into logical categories (e.g., "Role," "Format," "Style").

Pitfall 2: Conflicting Instructions

It is easy to accidentally give contradictory commands. For example, "Be very detailed and explain every nuance" followed by "Keep the response under 100 words." The model will struggle to reconcile these, often resulting in a truncated, poor-quality output.

  • Solution: Review your prompt for logical consistency. If you have competing needs, prioritize them (e.g., "Prioritize brevity, but include a summary of the most important technical nuances").

Pitfall 3: Assuming Shared Knowledge

The model does not know your specific company culture, internal acronyms, or the history of your current project unless you provide it.

  • Solution: Include a "Background Information" section in your prompt. Paste relevant snippets of internal documentation or project history if they are necessary for the task.

Not read yet

Quick Reference: Context Checklist

Use this table as a checklist before hitting enter on your next prompt.

Component Question to Ask Yourself
Persona Who is the ideal expert to answer this?
Audience Who is reading this, and what is their knowledge level?
Format Do I need a table, a list, code, or a narrative paragraph?
Constraints Are there length limits, specific words to avoid, or required inclusions?
Examples Can I provide a "before/after" or a sample of the desired output?

Deep Dive: The Art of Framing

Framing is the psychological aspect of context determination. How you frame a request can change the model's "confidence" level. For instance, telling a model "You are an expert who is never wrong" can actually lead to more hallucinations because the model is trying to maintain that persona of authority. Conversely, telling a model "You are a research assistant, and it is okay to say you don't know if the information isn't in the provided text" leads to much higher accuracy.

The Power of "Chain of Thought" Context

When you need the model to solve a complex logical problem, you should add a specific contextual instruction: "Think step-by-step." This is a form of context that dictates the reasoning process rather than the output format.

Callout: The "Step-by-Step" Advantage Research has shown that asking an LLM to "think step-by-step" significantly improves performance on logic, math, and coding tasks. This is because it forces the model to generate intermediate reasoning tokens, which effectively acts as a "scratchpad" for the model to organize its thoughts before committing to a final answer.

Example of Step-by-Step Context

  • Prompt: "Analyze this financial statement. Think step-by-step to calculate the debt-to-equity ratio, and then explain your findings for a non-financial stakeholder."

By explicitly asking for the steps, you are setting the context that the process of getting the answer is just as important as the answer itself.


Not read yet

Handling Ambiguity: When You Don't Know the Context

Sometimes, you may not have all the context required. In these cases, the best context is to instruct the model to ask you questions first. This is a highly effective way to handle complex tasks where you aren't sure what information the AI needs.

The "Consultant" Prompt Pattern

"You are an expert consultant. I need help with [Project Name]. I don't have all the requirements finalized. Please ask me 5-10 targeted questions to help you understand my needs better. Do not provide a solution until I have answered these questions."

This approach shifts the burden of context determination from you to the model. It is a powerful way to ensure that the final result is exactly what you need, rather than what you thought you needed.


Advanced Technique: Dynamic Context Injection

In programmatic applications, you might be pulling data from a database to inform the model. This is where context determination meets data engineering. You should never just dump raw database rows into a prompt. Instead, summarize the data or format it into a readable structure before feeding it to the model.

Code Example: Data Pre-processing for Context

# Instead of dumping raw JSON
def prepare_context(data):
    # Convert raw data into a readable summary
    summary = f"The user has {len(data)} active projects. "
    for item in data:
        summary += f"Project {item['name']} is in status {item['status']}. "
    return summary

# Now inject this summary into the prompt
context = prepare_context(user_projects)
prompt = f"Context: {context}\n\nTask: Suggest which project needs immediate attention."

By pre-processing the context, you remove the "noise" of raw data and highlight the "signal" for the model. This is a common industry standard for building useful AI applications.


Not read yet

Managing Tone and Style

Context is not just about facts; it is about the "vibe" of the output. If you are writing a marketing email, the context must specify whether the brand voice is "playful and energetic" or "sober and professional."

Tone Specification Table

Tone Contextual Cues
Professional Use formal grammar, avoid contractions, focus on business outcomes.
Conversational Use short sentences, active voice, relatable analogies, maybe a light joke.
Academic Use precise terminology, cite logical connections, maintain neutral perspective.
Empathetic Use first-person plural ("we"), validate the user's feelings, offer support.

When you provide these cues, the model adjusts its probability distribution for word selection. A "professional" context will increase the probability of words like "implement," "leverage," and "strategic," while a "conversational" context will favor "try," "help," and "easy."


Not read yet

Avoiding "Hallucinations" via Contextual Constraints

Hallucinations—where the model confidently states false information—often happen because the model is trying to be "helpful" by filling in gaps in its knowledge. You can use context to explicitly tell the model to stop doing this.

The "Strict Context" Constraint

"You are a helpful assistant. You must only answer based on the provided text. If the answer is not in the text, state 'I do not have enough information' and do not attempt to guess."

This simple instruction changes the model's behavior from "generative" (creating content) to "extractive" (summarizing content). This is essential for applications involving medical, legal, or financial data where accuracy is non-negotiable.


Industry Recommendations and Best Practices

  1. Iterate on the Prompt, Not the Model: If the model fails, 90% of the time the issue is your prompt's context, not the model's capability. Spend more time refining the prompt before switching to a larger or more expensive model.
  2. Version Control Your Prompts: Treat your prompts like code. Use a repository to store them, track versions, and document why you made changes. This is crucial for maintaining consistent output across a team.
  3. Use System-Level Prompts for Constants: If you have an instruction that applies to every single interaction (e.g., "Always write in JSON format"), put it in the system prompt rather than repeating it in every user prompt.
  4. Test for Edge Cases: Try to "break" your prompt. Ask the model to do something outside the context you provided to see how it handles it. If it fails, add a constraint to your context to handle that edge case.
  5. Documentation is Context: Keep a "Prompt Library" where you document the context for each task. This helps other team members understand why a prompt is structured the way it is.

Not read yet

Addressing Common Questions (FAQ)

Q: Does it matter if I put the context at the beginning or the end? A: Yes. Most modern models are sensitive to order. Putting your context at the beginning (the "System" or "Instruction" block) is generally more effective because it sets the stage for the rest of the conversation.

Q: How much context is too much? A: Modern models have large "context windows" (the amount of text they can hold in memory). However, even if they can hold 100,000 words, they perform better when you provide only the relevant information. Aim for the "Goldilocks zone"—enough to be complete, but not so much that it becomes cluttered.

Q: Can I use multiple personas in one prompt? A: It is generally better to stick to one clear persona. If you need multiple perspectives, it is more effective to run separate prompts for each persona and then use a final "synthesis" prompt to combine their outputs.

Q: What if the model ignores my context? A: If the model ignores your context, your instructions might be too subtle. Use stronger, more direct language. Instead of "Try to be professional," use "You must be professional. Do not use slang."


Not read yet

Key Takeaways for Effective Context Determination

  1. Context is the Foundation: The quality of your output is directly proportional to the quality of your input. Investing time in defining the context is the most important step in prompt engineering.
  2. The "Who, To Whom, Why" Framework: Always define your persona, your audience, and your objective before starting any task. This creates a clear roadmap for the AI.
  3. Constraints are Mandatory: Do not leave your prompts open-ended. Use specific constraints to define the tone, format, and boundaries of the response to prevent unwanted, generic, or hallucinated content.
  4. Use Examples (Few-Shot): When words are not enough to describe a style or format, provide concrete examples. This is the fastest way to align the model with your expectations.
  5. Iterate and Refine: Treat prompt engineering as an iterative process. Use the model's output to identify missing context and update your prompt accordingly.
  6. Prioritize Clarity: Avoid jargon and vague language in your instructions. Be as specific and literal as possible. If you want a table, say "Create a table with columns X and Y."
  7. System vs. User Roles: Use the system role for permanent, foundational instructions (the "identity" of the AI) and the user role for specific, task-based instructions.
  8. Test and Validate: Always test your prompts against edge cases. A robust prompt is one that performs well even when the user input is ambiguous or unexpected.

By internalizing these principles, you move beyond the trial-and-error approach to interacting with AI. You become a designer of intent, capable of extracting high-quality, reliable, and useful information from these powerful systems consistently. Whether you are automating a simple email or building a complex data analysis pipeline, the principles of context determination remain your most valuable tool.

Not read yet

Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.