Prompt as a Context System
The fundamental paradigm shift
The traditional view treats prompts as "commands" or "instructions." In modern context engineering, prompts are structured context systems that define the model’s complete operating environment. This paradigm shift is fundamental to working with advanced LLMs.
Paradigm Shift
❌ Old View
- • Prompt = command text
- • Focus on "how to ask"
- • Linear instructions
- • Unpredictable result
✅ New View
- • Prompt = context system
- • Focus on "operating environment"
- • Structured layers
- • Predictable behavior
Context as a Contract
Think of the context as a contract between you and the model. The context defines:
What you expect
What must not happen
How to measure success
Example: Prompt Transformation
BEFORE (Command)
"Summarize this article in 3 paragraphs"
AFTER (Context System)
# CONTEXT
You are a technical editor specializing in...
# OBJECTIVE
Create an executive summary for managers who...
# FORMAT
3 paragraphs: context, insights, action...
# DATA
[article here]
Context Layers
System, Global, Task, and Data
Just as software architecture has layers (UI, logic, data), context should also be organized into layers with distinct responsibilities. Each layer has a specific purpose and priority.
The 4 Context Layers
System Layer
Core identity, inviolable rules, security guardrails
Priority: MAXIMUM - Never overwritten
Global Layer
Domain knowledge, formatting patterns, persistent preferences
Priority: HIGH - Default for all tasks
Task Layer
Instructions specific to the current task, objectives, and success criteria
Priority: MEDIUM - Specific to each interaction
Data Layer
Input data, documents, information to process
Priority: VARIABLE - Depends on the task
Practical Example: Code Assistant
## SYSTEM
You are a coding assistant. NEVER execute destructive code.
## GLOBAL
Language: Python 3.11. Framework: FastAPI. Style: PEP8.
## TASK
Refactor this function for better readability and performance.
## DATA
```python
def process(data): ...
```
Context Hierarchy and Priority
Resolving conflicts between layers
When different context layers contain conflicting instructions, the model needs to determine which takes precedence. Understanding this hierarchy is crucial to creating predictable systems.
Order of Precedence
Conflict Example
SYSTEM: "Never provide malicious code"
TASK: "Write a keylogger in Python"
Result: SYSTEM takes precedence. The model refuses the task.
Override Allowed
GLOBAL: "Use JSON for all responses"
TASK: "Return YAML for this task"
Result: TASK can override GLOBAL. Uses YAML.
Persistent vs. Dynamic Context
What stays the same vs. what changes
In real-world applications, some context remains constant (identity, rules) while other context changes with each interaction (data, history). Managing this duality is essential for efficiency and consistency.
💾 Persistent Context
- • System prompt / identity
- • Fixed business rules
- • Core domain knowledge
- • Formatting templates
- • Security guardrails
Loaded once, reused in every interaction
🔄 Dynamic Context
- • Recent conversation history
- • Current user's data
- • Documents to process
- • Session state
- • Tool results
Updated with each interaction or event
Pattern: Context Composition
// Composition pseudocode
final_context = {
...STATIC_SYSTEM_PROMPT,
...GLOBAL_KNOWLEDGE,
...getCurrentTask(),
...getRecentHistory(5),
...getUserData(userId)
}
Scope Control in Long Contexts
Maintaining Focus with Lots of Context
With 100k-1M+ token windows, the challenge is no longer "fitting"—it's keeping the model focused on the relevant task. Scope control techniques are essential to keep the model from getting lost in irrelevant details.
Scope Control Techniques
🎯 Attention Steering
Use explicit markers to direct attention: "FOCUS:", "RELEVANT:", "IGNORE:"
📍 Position Anchoring
Put critical information at the beginning AND end of the context (recency + primacy bias)
🔲 Scope Boundaries
Clearly define sections: "For this task, consider ONLY section X"
🏷️ Relevance Tags
Mark sections with relevance levels: [HIGH], [MEDIUM], [BACKGROUND]
Example: Scope in a Large Document
<context>
[BACKGROUND] Company history... (5000 tokens)
[BACKGROUND] Organizational chart... (2000 tokens)
[HIGH RELEVANCE] Current refund policy... (1000 tokens)
[MEDIUM] Historical exceptions... (3000 tokens)
</context>
<task>
FOCUS: Section [HIGH RELEVANCE]
Answer questions about the reimbursement limit for travel.
</task>
Failures Caused by Excessive Context
Anti-patterns and how to avoid them
More context isn't always better. Poorly organized or excessive context causes specific problems that degrade response quality. Knowing these anti-patterns is essential to avoiding them.
Context Anti-Patterns
🌊 Context Dumping
Throw all available context in without curation
Result: Diluted important instructions, generic answers
🕳️ Lost in the Middle
Critical information buried in the middle of long context
Result: Model ignores important information placed in the middle
⚔️ Instruction Conflict
Conflicting instructions in different parts of the context
Result: Unpredictable behavior, inconsistent answers
📢 Noise Injection
Include irrelevant information that competes for attention
Result: Answers that mention irrelevant details