Context Engineering: Designing the Flow of Information to a Model
Context engineering is the work of selecting and assembling the instructions, user input, conversation history, retrieved material, memory, tool descriptions, and output constraints a model receives for a request. The aim is not to include as much as possible, but to provide what the current task needs with appropriate authority, order, and source labels. Polishing prompt wording alone cannot make a good answer likely when the supplied material is stale, unauthorized, or mixed with higher-priority instructions.
Context Engineering: Designing the Flow of Information to a Model
Context engineering is the work of selecting and assembling the instructions, user input, conversation history, retrieved material, memory, tool descriptions, and output constraints a model receives for a request. The aim is not to include as much as possible, but to provide what the current task needs with appropriate authority, order, and source labels. Polishing prompt wording alone cannot make a good answer likely when the supplied material is stale, unauthorized, or mixed with higher-priority instructions.
The term is used here as a practical idea for managing the model’s full input context, not as a universally standardized technical specification. Prompt engineering focuses on improving instructions, formats, and examples; context engineering also asks what to retrieve, which component should contain it, how to update it, and what to record. The work overlaps rather than competes.
What can be part of a model’s context?
A model request may include more than one block of prompt text. Message roles and instructions, the user’s content, prior conversation, retrieved documents, images or files, tool definitions and schemas, and response-format settings can all shape the context the model interprets. What counts toward input tokens, what is added as an internal instruction, and what affects tool permissions varies by API and model. Check the request structure in the documentation for the API you actually use.
Each component has a different purpose and trust level. Keep application-owned business rules in higher-authority instructions, separate from user material. A user request describes the task; retrieved documents are evidence; and tool schemas define permitted actions. Make trust boundaries explicit so a sentence inside an external document such as “ignore the previous rules” is not promoted into a new instruction.
| Component | Question it answers | Design check |
|---|---|---|
| Stable instructions | What should and should not the system do? | Keep lower-authority inputs and documents from overriding them. |
| Current request | What result does the user want now? | Identify purpose, language, and output form; ask when material ambiguity remains. |
| Conversation history and memory | What from earlier interactions is still relevant? | Check for stale or conflicting details, and define privacy retention and deletion. |
| Retrieved and reference material | Which facts or policies support the answer? | Check relevance, freshness, provenance, duplicates, and conflicts. |
| Tools and output contract | Which actions or formats may the model use? | Check permissions, schema, error handling, and application-side validation. |
How do you assemble context for each request?
The following is a practical design workflow, not a fixed rule implemented by every product.
**Define the work outcome.** State the question the model must answer, permitted actions, required output, and observable success and failure conditions.
**Retrieve only needed data.** Do not attach an entire conversation or database. After checking authorization, retrieve only the memories, documents, or records relevant to this request. Define outcomes such as “no information,” “needs confirmation,” or “hand off to a person” for cases where evidence is insufficient.
**Separate by role and trust.** Distinguish application-owned instructions, the user’s request, retrieval results, and executable tools. State that external material is citeable data, not an instruction, and cannot change permissions or policy.
**Set order and boundaries.** Put stable reusable instructions and tool definitions before request-specific material. Use headings or clear delimiters to separate sections, but do not assume formatting creates a security boundary. Record the actual message array and content order the model receives.
**Manage length and change frequency.** Leave room within the context limit for the output. Repeated stable prefixes may help cache reuse, but do not guarantee a cache hit. Remove or summarize irrelevant history, then check that summarization did not erase essential evidence.
**Validate and observe results.** Record identifiers that let you reconstruct retrieval sources, prompt version, model and tool settings, and chosen path. Do not copy sensitive source text into logs by default; define retention purpose and access. Check output accuracy, evidence links, format, safety, and cost separately.
Example: customer support using a policy
Consider a hypothetical support assistant answering “When will my refund arrive?” The application first checks the order status in the authenticated account and retrieves only the current, applicable excerpt of the refund policy. In the model input, it separates fixed instructions and response format from the user’s request and retrieved material, and clarifies that policy text is evidence and any commands inside it must not be followed. If the policy does not specify a processing time or the order cannot be found, the assistant must not invent a date; it should request confirmation or route the case to a person.
After the response, link the policy source ID and order-status check to the internal task record, then verify that any date in the user-facing answer is supported by the actual policy evidence. This scenario illustrates a design; it is not a report of testing a particular product or integration. The important distinction is between “copy every document into the prompt” and “retrieve only current, authorized evidence, separate its role, and validate it.”
What should you measure?
Context assembly may improve quality, but can also increase length, latency, token cost, privacy exposure, and operational complexity. Include ordinary inputs in evaluation data as well as missing or stale material, conflicting documents, prompt-injection text, ambiguous requests, and unauthorized data requests. Change one component at a time where possible so its effect is easier to interpret.
Do not measure only final-answer accuracy. Check whether the evidence actually supports the conclusion, whether source attribution survives, whether tools run only within authorized scope, whether missing information is handled correctly, and whether the output contract is met. If quality improves but latency, cost, or privacy risk exceeds operational limits, adjust the design. Keep final evaluation cases separate from those used to write or repeatedly tune the prompt.
Common mistakes
**Assuming more context is always better:** Irrelevant or duplicate documents can obscure useful evidence. Retrieve only what the task needs and confirm that compression preserves the evidence.
**Treating retrieved material as instructions:** A document may be evidence, but it cannot change application rules or permissions. Separate roles and trust levels, and evaluate with adversarial text included.
**Assuming a summary is equivalent to the source:** A summary can omit stale facts, conditions, exceptions, or attribution. Keep dates and provenance, and recheck important decisions against the source or authoritative record.
**Recording only the prompt version:** The model, tool schema, retrieval index, and injected material can also change the answer. Record identifiers for reproducibility while minimizing sensitive data.
**Assuming format instructions replace validation:** Even if the model returns JSON or a table, the application must check value meaning, allowed ranges, and whether citations are genuine.
Takeaway
Context engineering is not a technique for piling information into a prompt. It is system design for selecting, assembling, updating, and validating the information a model receives. Provide only what the request needs, with appropriate authorization and provenance; separate fixed instructions from external data; and evaluate constraints on length, change, privacy, and cost together. The best arrangement depends on the model, API, and task, so verify it with evaluations and usage records from real requests.
Sources
[OpenAI API: Prompt engineering](https://developers.openai.com/api/docs/guides/prompt-engineering) — Official guidance on message roles, prompt structure, examples, and added context. Checked 2026-11-23.
[OpenAI API: Prompt caching](https://developers.openai.com/api/docs/guides/prompt-caching) — How repeated prefixes and input composition relate to cache reuse. Checked 2026-11-23.
[Anthropic: Prompting best practices](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices) — Provider guidance on clear instructions, structure, examples, and external context. Checked 2026-11-23.