Skip to content

Context Engineering: How What Goes into the Prompt Affects the Response

Cover: context engineering The quality of an LLM's response is determined not only by the model but also by what is loaded into it. Context assembly is a separate engineering discipline: context engineering.

The Model Sees the World Through Context

An LLM has no memory between calls. Everything the model 'knows' at the moment of the response is the context: system prompt, dialogue history, found documents, tool descriptions. From this follows a simple conclusion: if garbage gets into the context, the response will be garbage, no matter how powerful the model. The reverse is also true: a well-assembled context can even pull up an average model.

What Makes Up the Context

flowchart LR
    A[System Prompt] --> F[Context]
    B[Dialogue History] --> F
    C[Found Documents] --> F
    D[Tool Schemas] --> F
    F --> G[Model]

1. System Prompt

The system prompt sets the rules of behavior. The main rule here is brevity and specificity: the longer the instruction, the worse the model follows it. Important instructions go first.

2. Dialogue History

In a multi-turn dialogue, the entire history goes into the context. Over time, it grows and pushes out the beginning. If there were important rules at the beginning, the model 'forgets' them.

3. Found Documents

In RAG, documents are the main source of facts. Here, two effects work: - more does not mean better: extra fragments dilute the model's attention; - lost in the middle: the middle of the context is remembered worse, so key fragments should be placed closer to the edges.

4. Tool Schemas

When tool calling occurs, descriptions of tools enter the context. They should also be kept compact: extra tools confuse the model's choice.

Practical Techniques

Cut Everything Unnecessary

Every token in the context costs money and the model's attention. Before sending, check: - is this fragment necessary for the response; - can it be formulated more briefly; - does it duplicate another fragment.

Place Important Information at the Beginning and End

The model uses the beginning and end of the context best. System rules go first, and the user's last request goes last. Found documents with the most important information should be placed closer to the edges.

Use Instruction Hierarchy

Separate levels: system rules, user request, data. This is the principle of instruction hierarchy, which protects against prompt injection.

Monitor Token Budget

For mass calls, token efficiency works: every saved token is money and speed. Count how many tokens are spent on the system prompt and documents, and optimize.

Example: Before and After

Before — an inflated prompt with unnecessary explanations:

You are an assistant. Please help me. I want you to answer the question below, try to be helpful and polite. If you don't know the answer, just say you don't know...
After — a compact instruction:
Answer briefly. If you don't know the answer, just say so.
Both versions do the same thing, but the second one saves dozens of tokens per call.

Conclusion

Context engineering is not 'prompt magic,' but ordinary work with information: what to include, what to exclude, and in what order to present it. The model is the executor, and the quality of the input determines the quality of the output.

See Also