Abstract
Every engineering organization has rules that should hold for every change: parameterize queries, check authorization on every handler, never log secrets, keep tests deterministic. Agents are usually told these rules once, in a system prompt or a file they happen to read, and then expected to keep them in mind while their context fills with logs, diffs and retries.
The evidence says that expectation is fragile. Models use information unevenly across their input, they follow fewer instructions reliably as instructions pile up, and the code they write is often insecure when nothing pushes back. We argue that best practices belong in a constant prior: a small, curated layer that sits at the top of every compiled context, byte for byte the same, regardless of the task below it.
Where rules live in an agent’s context
In a typical coding agent, rules arrive through three channels. Some are in the system prompt. Some are in project files (contributing guides, style guides, agent instruction files) that the agent reads when it decides to. Some are given by a person halfway through the session, after something went wrong.
All three degrade as the session runs:
- System-prompt rules keep their absolute position at the start, but the point where the model writes moves further away with every turn. After an hour, hundreds of thousands of tokens of tool output separate the rule from the line of code it should govern.
- Rules read from files land wherever the read happened, usually in the middle of the transcript.
- Corrections from people are buried by the next round of tool calls, and can be lost entirely when the transcript is summarized to fit the window.
The pinned layer
Left: Chad compiles a fresh stack for every task; the best-practices layer never moves. Right: one transcript that appends every turn, so the rules drift away from where the model is writing. Illustrative animation.
The bar shows how close the rules sit to the point of generation (full = adjacent). In the transcript the rules keep their absolute position but end up hundreds of thousands of tokens away, and rules learned mid-session (amber) land in the middle. Illustrative, not measured.
None of this is visible from the outside. The agent keeps producing plausible code. What changes is the probability that each rule is applied to the code it is producing right now.
Position is not neutral
Liu et al. measured how well models use a relevant document depending on where it sits among twenty retrieved documents. Accuracy follows a U-shape: highest when the evidence is at the start, lower at the end, lowest in the middle. For GPT-3.5-Turbo, mid-context accuracy fell below the closed-book baseline, meaning the model did worse with the right document in the middle than with no documents at all [1].
Accuracy by position of the relevant document
Multi-document QA, 20 documents, GPT-3.5-Turbo. Reported by Liu et al. (Table 6).
Source: Lost in the Middle [1]. Accuracy 75.8% at position 1, 57.2% at 5, 53.8% at 10, 55.4% at 15, 63.2% at 20. The closed-book baseline (no documents) is 56.1%. One model and one task; the shape, not the exact values, is the point.
Model providers now encode this in their guidance. OpenAI’s prompting guide for GPT-4.1 recommends placing instructions both before and after long context, and, if only one position is possible, before it [2]. Anthropic’s documentation recommends putting long documents near the top of the prompt and the query at the end, reporting that queries at the end improved response quality by up to 30% in its tests [3].
Read together, these point to a simple layout: stable rules at the very top, the specific task at the very end, and as little as possible in between. That is the layout a compiled context can guarantee and an accumulating transcript cannot.
Rule recall vs. position and context length
Move a rule through the context and grow the context around it. Illustrative model, not a benchmark.
Curve shape: primacy and recency advantages with a weaker middle, and a lower floor as the context grows, as reported qualitatively in the literature cited in this paper. The values are invented for the illustration. Plays through the presets automatically; click a preset or drag a slider to explore.
More rules, less compliance
Placement is half the problem. The other half is volume.
IFEval
Zhou et al. build a benchmark of about 500 prompts with 25 types of verifiable instructions (“write more than 400 words”, “use no commas”), so that compliance can be checked by a program rather than a judge. It made instruction following measurable, one prompt at a time. [4]
SysBench
Qin et al. test whether models follow system messages across 500 hand-built system prompts. They single out three failure modes: constraint violation, instruction misjudgement and instability across turns. [6]
How Many Instructions Can LLMs Follow at Once?
Jaroslawicz et al. scale the number of simultaneous instructions from 10 to 500 across 20 models. The best model reaches 68.9% at 500. They also report a primacy bias: instructions earlier in the list are followed more reliably. [5]
OctoBench
Ding et al. evaluate scaffold-specified rules in repository-grounded agentic coding, with 7,098 checklist items over 217 tasks. They report a systematic gap between solving the task and complying with the rules of the scaffold. [7]
The IFScale results are the most useful for design, because they show the shape of the decline. Some frontier models hold near-perfect accuracy up to roughly 150 instructions and then fall off; others decline steadily; smaller models collapse early to low floors [5].
Instruction-following accuracy vs. number of simultaneous instructions
IFScale, as reported by Jaroslawicz et al. (averaged over five runs). Hover for values.
Source: [5], Table 1. Keyword-inclusion instructions in a report-writing task; models as named by the authors (mid-2025 versions). Rules in a real codebase are less uniform, so treat this as the shape of the curve, not a prediction.
Two consequences follow. First, a best-practices layer has a budget. Dumping a 40-page engineering handbook into every prompt moves the agent to the right of this chart. Second, order inside the layer matters: if earlier instructions are followed more reliably, the rules whose violation is most costly go first.
Security is where forgetting costs most
Most forgotten rules cost style or rework. Security rules are different: a missed one ships a vulnerability, and nothing in the task’s own tests will catch it.
Pearce et al. prompted GitHub Copilot with 89 scenarios built around high-risk weakness classes and generated 1,689 programs; approximately 40% were vulnerable [8]. Perry et al. ran a user study with 47 participants: those with an AI assistant wrote significantly less secure code than the control group, and were more likely to believe their code was secure [9].
SQL task: share of solutions vulnerable to SQL injection
Perry et al., CCS 2023. Participants with an AI assistant vs. a control group without one.
Source: [9]. 33 participants in the AI group, 14 in the control group; difference reported as significant (p = 0.041). Small sample, 2022-era model.
Newer models have not made the problem disappear. Veracode’s 2025 report tested more than 100 models on 80 curated tasks and found security flaws in 45% of cases. Models failed to defend against cross-site scripting in 86% of relevant cases and against log injection in 88%, and the report finds that security performance stayed flat even as models got better at producing working code [10]. This is a vendor report on a designed task set, not a sample of production code, but its direction matches the academic studies.
Security knowledge itself is not missing. It is codified, public and short. The OWASP Top 10:2025 lists the ten most critical web application risk categories, from Broken Access Control (A01) and Software Supply Chain Failures (A03) to Injection (A05) [11]. The OWASP Top 10 for LLM Applications 2025 does the same for systems built on models, starting with Prompt Injection and including Excessive Agency and System Prompt Leakage [12]. The gap is not knowledge. It is the reliable presence of that knowledge at the moment a line of code is written.
Perry et al. also found that participants who trusted the assistant less and engaged more with their prompts produced fewer vulnerabilities [9]. A constant prior is that engagement, made systematic: the security rules are restated to the model on every loop, not left to the vigilance of whoever wrote the prompt.
Principles as a prior
The idea of conditioning a model on a short, explicit list of principles has precedent. Constitutional AI trains a model to critique and revise its own outputs against a written set of principles, and uses AI feedback based on them instead of human labels of harmful outputs [13]. The lesson we take from it is narrow: a short, stable, human-readable list of rules is a workable way to shape model behavior. Constitutional AI applies its principles at training time; a best-practices layer applies an organization’s principles at inference time, where they can be changed in a review instead of a training run.
Anthropic’s guidance on context engineering frames the same constraint from the other side: context is a finite resource with diminishing returns, and the goal is the smallest set of high-signal tokens that produces the desired behavior [14]. Best practices are the highest-signal tokens an organization has, because they apply to every task. They should be the last thing cut, not the first thing buried.
Consistency matters as much as presence. When the same layer appears in every loop:
- Behavior is comparable across loops. A Builder fixing a bug and a Builder adding a feature are conditioned on the same rules, so differences in their output come from the task, not from which rules happened to be in view.
- Changes are deliberate. Updating a rule is a versioned change to one layer, visible in review, not an edit scattered across prompts and files.
- The prefix is stable. Provider-side prompt caches reuse only an exact prefix. A layer that is identical at the top of every context is the part of the prompt that can be cached across loops.
How Chad applies it
Chad does not grow the context. Each agent loop starts empty, and a context compiler builds about 6k tokens from durable memory, in a fixed order:
- Global domain best practices, on top of everything and always present: the organization’s standards, security rules and playbooks for the domain the task touches.
- The validated intent and its acceptance criteria.
- Related changes, found by a columnar query on ClickHouse, where git history is stored as rows of line additions and deletions linked to the intent behind each change.
- Validated actions, stored as input → output pairs.
- The atomic task and its target files, at the end, next to where the model writes.
The first layer is the constant prior. It is curated, not dumped: a short list ordered by cost of violation, with security rules first. It is the same for the Planner, the Builder, the Verifier and the Debugger woken by a Sentry error, so every role works under the same rules. And because the Verifier sees the same layer as the Builder, checking compliance with it is part of validation, whether the validator is a person or an AI verifier. Only validated actions enter memory, so a change that violated a rule does not become an example for the next loop.
The layout uses both ends of the context the way the research suggests: stable rules at the top, the specific task at the bottom, and a short, high-signal middle. The rules are never more than a few thousand tokens from the point of generation, and they never compete with hundreds of thousands of tokens of tool output.
Limits & next steps
The studies above use different models, tasks and setups; their numbers are each paper’s own and not directly comparable. IFScale measures keyword inclusion, not engineering rules, and position effects vary by model and may be weaker in newer generations. Our argument does not rest on any single figure: it rests on the consistent direction of the evidence, and on the fact that a compiled context makes rule placement a design decision instead of an accident of session length.
A constant prior also has costs. A layer that is too long eats the budget it is meant to protect; a layer that is too generic gets ignored. Curating it per domain is real work, and a rule in the prompt is not a guarantee: deterministic checks (linters, static analysis, dependency policies) remain the enforcement layer, and the prior reduces how often they fire.
We have not published measurements of Chad’s rule compliance. We are preparing an evaluation that compares rule adherence with the best-practices layer pinned at the top, placed mid-context, repeated at both ends, and absent, on real repositories. Results will be published here.
References
- Liu, N. F. et al. Lost in the Middle: How Language Models Use Long Contexts. TACL, 2024.
- OpenAI. GPT-4.1 Prompting Guide. OpenAI Cookbook, 2025.
- Anthropic. Prompting best practices: long context prompting. Claude documentation.
- Zhou, J. et al. Instruction-Following Evaluation for Large Language Models. arXiv:2311.07911, 2023.
- Jaroslawicz, D., Whiting, B., Shah, P., Maamari, K. How Many Instructions Can LLMs Follow at Once?. arXiv:2507.11538, July 2025.
- Qin, Y. et al. SysBench: Can Large Language Models Follow System Messages?. arXiv:2408.10943, 2024.
- Ding, D. et al. OctoBench: Benchmarking Scaffold-Aware Instruction Following in Repository-Grounded Agentic Coding. arXiv:2601.10343, January 2026.
- Pearce, H., Ahmad, B., Tan, B., Dolan-Gavitt, B., Karri, R. Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributions. IEEE Symposium on Security and Privacy, 2022.
- Perry, N., Srivastava, M., Kumar, D., Boneh, D. Do Users Write More Insecure Code with AI Assistants?. ACM CCS, 2023.
- Veracode. 2025 GenAI Code Security Report. Industry report, July 2025 (updated October 2025).
- OWASP Foundation. OWASP Top 10:2025. 2025.
- OWASP GenAI Security Project. OWASP Top 10 for LLM Applications 2025. 2025.
- Bai, Y. et al. Constitutional AI: Harmlessness from AI Feedback. arXiv:2212.08073, 2022.
- Anthropic. Effective context engineering for AI agents. 2025.