
The Answer Is Optional: An Abstention Contract for AI
A practical guide to deciding when AI should answer, seek evidence, defer, or refuse using calibrated signals, risk–coverage curves, and fallback capacity.
Read MoreZharfAI Team

Prompt engineering asks how to express an instruction. Context engineering asks a larger production question: what information, authority, state, and capabilities should the model receive at this moment—and what must remain outside?
The distinction matters because a modern AI application rarely sends one prompt. It assembles system policy, user intent, conversation state, retrieved documents, memory, tool definitions, tool results, examples, output schemas, and safety metadata. If these pieces are stale, contradictory, overbroad, or indistinguishable from untrusted text, a more capable model may simply fail with greater confidence.
Anthropic’s 2025 guide to effective context engineering describes context as a finite resource whose tokens should be selected for utility. Research gives a stronger warning: the Lost in the Middle study found that long-context models can perform worse when relevant information sits in the middle of a long input. A large window is capacity, not a guarantee that every token receives equal use.
This guide turns context engineering into a concrete architecture: a typed context manifest, a trust-aware assembly pipeline, token and latency budgets, security boundaries, and evaluations that isolate context failures from model failures.
Do not construct production prompts by concatenating strings. Represent each context item as a typed record before rendering it for the model.
| Context type | Examples | Required metadata |
|---|---|---|
| Policy | Safety rules, business constraints, response contract | Owner, version, precedence, effective date |
| Task | User goal, success condition, open questions | Request ID, actor, scope, expiry |
| State | Completed steps, selected objects, pending approvals | Source event, timestamp, integrity |
| Evidence | Database row, document passage, measurement | Source ID, supporting span, permissions, freshness |
| Memory | Confirmed preference, project decision | Subject, scope, confidence, retention |
| Tool | Search, database query, payment, email | Schema, side effects, permissions, timeout |
| Example | Demonstration of desired behavior | Applicability, source, version |
| Output contract | JSON schema, citation format, validation rules | Schema version, validator |
A useful item envelope might contain:
id, type, content, source, owner, trust_level, authority,
created_at, effective_at, expires_at, sensitivity,
allowed_uses, transformation_history, token_estimate
The model does not need to see every field verbatim. The context builder does. These fields make it possible to filter, order, explain, invalidate, and audit inputs rather than treating the final prompt as an opaque blob.
An item can be trustworthy as data but lack authority to change the task. A webpage may accurately describe a product while having no authority to override the user’s instruction. A prior model summary may be useful state but should not outrank a current primary record. A user may be authoritative about their goal while still providing a mistaken factual claim.
Model these dimensions separately:
Then define precedence in code. For example, application policy can constrain behavior; the current user request defines the goal inside those constraints; retrieved pages provide data, not instructions; tool output updates state but cannot silently broaden scope.
This is the key defense against “flat context,” where every natural-language token appears equally directive.
A robust context builder behaves more like a compiler than a scrapbook.
Resolve active identity, tenant, locale, task type, time reference, expected output, and risk tier. Preserve the original user instruction alongside any structured interpretation so the system can detect semantic drift.
Select policy by product, jurisdiction, organization, role, task, and effective date. Do not send every policy document. Compile only applicable rules and preserve policy IDs for later explanation.
Load only the state required to continue the current workflow. Distinguish confirmed external state—such as a record returned by an API—from a model’s previous plan. Revalidate state when it may have changed since the last turn.
Filter by permissions and source authority before semantic ranking. Return exact supporting passages, stable identifiers, dates, and access labels. If sources conflict, include the conflict or escalate; do not let a similarity score choose the truth silently.
Read RAG and enterprise knowledge quality for the retrieval layer and evidence-first automation for claim-to-source traceability.
Apply identity, project, sensitivity, status, and temporal rules before relevance. A recalled preference is not a policy. A stale project decision should be invalidated, not summarized more elegantly. The control-first AI memory guide explains this lifecycle.
Expose only capabilities required for the task and current actor. Tool descriptions should state side effects, required approval, idempotency expectations, and failure behavior—not only a friendly name and parameter list.
Assign budgets by type and risk. Preserve non-negotiable policy, immediate task, critical evidence, identifiers, and unresolved conflicts. Compress verbose history and low-value examples first.
Render clear structural boundaries, then run machine checks: required sections present, no item above the actor’s permissions, token limit respected, schema valid, source IDs resolvable, and tool set consistent with policy.
Summarizing a noisy pile produces a smaller noisy pile. Use four operations in order:
Compression is lossy. Store both the compressed representation and its source references. For consequential facts, require the model or verifier to consult the original supporting span before action.
The “lost in the middle” result should not be turned into a universal trick such as repeating instructions at both ends. The durable response is evaluation: shuffle evidence position, add realistic distractors, and measure whether the system still identifies the right source. If moving one paragraph changes a decision, the context pipeline is brittle.
Every additional item has at least four costs:
Maintain an item-level estimate before rendering. A practical budget might reserve fixed capacity for policy and task state, dynamically allocate evidence based on risk, and leave room for tool results that arrive during execution.
Do not optimize only for the smallest prompt. The objective is the smallest context that achieves the required quality and safety. A regulatory comparison may require multiple authoritative sources; a simple formatting request may need no retrieval or personal memory at all.
Prompt caching can reduce repeated prefill cost for stable prefixes, but caching is a storage decision. Provider documentation may impose different retention or eligibility rules. OpenAI’s current API data-controls documentation, for example, states that extended prompt caching has storage implications and is not compatible with its Zero Data Retention option. Treat such details as provider-specific and verify them before deployment.
Tool integration adds both capabilities and new context sources. The official Model Context Protocol architecture distinguishes tools, resources, and prompts:
That separation is useful, but a protocol does not decide which server to trust, which result is authoritative, or whether an action matches user intent. Those remain application responsibilities.
The July 28, 2026 MCP release candidate introduced a stateless core, extensions, tasks, apps, and authorization hardening. Fast-moving protocol changes make version pinning and capability negotiation part of context engineering. Record server identity, protocol version, declared capabilities, tool-schema version, authorization scope, and response provenance in each run.
Never treat a tool description or response as policy merely because it arrived through an integration. A compromised server, document, email, webpage, or database field can return text that looks like an instruction.
The OWASP 2025 prompt-injection guidance notes that indirect injections can arrive through external websites and files, and that RAG or fine-tuning does not fully solve the problem. The essential controls are architectural:
The OWASP prompt-injection prevention cheat sheet describes a useful pattern: the component with privileged tools should not directly consume uncontrolled content. Even then, a model-based guard is one layer, not proof of safety.
For implementation detail, see browser-agent security and tool permission design.
If model, retrieval, memory, policy, and tools all change together, a failed answer is hard to diagnose. Freeze the model and evaluate context variants; then freeze the context fixture and compare models.
Build a test matrix covering:
| Test | Expected behavior |
|---|---|
| Missing evidence | Abstain, ask, or use an approved fallback |
| Conflicting primary sources | Surface the conflict and apply declared precedence |
| Stale memory | Ignore or mark superseded |
| Unauthorized relevant document | Exclude it without leaking its existence or content |
| Injection in a webpage | Treat as data; do not alter tools or task |
| Important passage moved to middle | Preserve answer quality |
| Duplicate documents | Avoid overweighting repeated evidence |
| Tool schema changed | Fail validation or negotiate explicitly |
| Long conversation | Preserve current goal and unresolved state |
| Locale switch | Keep meaning, permissions, citations, and output direction |
| No-personalization task | Use no personal memory |
| Provider outage | Degrade without losing state or duplicating side effects |
Measure:
A “good prompt” that works only with one document order is not production-ready context engineering.
No. RAG is one source-selection mechanism. Context engineering also covers policy, user intent, workflow state, memory, tool affordances, output contracts, permissions, ordering, compression, and evaluation.
No. Preserve the current goal, decisions, unresolved questions, and necessary evidence. Expire or summarize low-value turns, and never assume old model output is authoritative merely because it is recent.
No. A stronger model cannot retrieve a document it was not given, repair a wrong permission boundary, know that a policy is superseded, or safely distinguish untrusted instructions without an application architecture that represents those facts.
Place them in a structurally distinct, high-authority policy layer and enforce critical rules outside the model. Do not rely on ordering alone for permissions, financial limits, data access, or destructive-action controls.
This article was substantially reviewed on July 30, 2026 using:
The model is only the execution engine. The context builder decides what world the model is allowed to see—and therefore deserves the same rigor as any other production decision system.

A practical guide to deciding when AI should answer, seek evidence, defer, or refuse using calibrated signals, risk–coverage curves, and fallback capacity.
Read More
A field guide to admitting, quarantining, or rejecting MCP servers, plugins, and agent tools using provenance, capability tests, and enforceable runtime limits.
Read More
A field guide to baselines, delayed outcomes, change attribution, and deciding when deployed AI should be watched, constrained, rolled back, or rebuilt.
Read MoreIf this note maps to a real system in your organization, start with the services page or a shipped case study.