Most system prompts are written on vibes. Someone tries a few instructions, sees the model behave slightly better, and ships it. This one is different — every rule in it maps to a documented failure mechanism in published LLM research.
This is a full write-up of how it was built, why, and what problem it solves.
Agentic AI tools like Claude Code, GitHub Copilot CLI, OpenAI Codex, and OpenCode are increasingly running real tasks autonomously — reading files, writing code, calling APIs, executing shell commands. The failure modes in these environments aren't just annoying. They're compounding. One wrong assumption in step 2 of a 10-step task can silently corrupt every step that follows.
The standard advice is to "write a good system prompt." But almost nobody asks: good according to what? What does the research actually say about why models fail, and what instructions meaningfully change that behavior?
That's the question this project started with.
Instead of writing a system prompt from intuition, I used NotebookLM — Google's research synthesis tool — to load 210+ academic sources, papers, and technical reports, then extract the failure mechanisms and translate them directly into behavioral instructions.
The strategy was simple:
- Identify the distinct failure domains that matter for agentic AI
- Find the research that explains why each failure happens at a mechanistic level
- Write instructions that address the cause, not just the symptom
The goal was to cover the full failure surface of an agentic system without redundancy. Each query had to point at a distinct domain. These were the five queries used in NotebookLM's deep research mode:
Query 1:
Hallucination mechanisms and root causes in large language models
Targets the reason models fabricate — overconfident next-token prediction, parametric memory staleness, source amnesia from training compression.
Query 2:
Sycophancy, instruction drift, and constraint violation in LLM alignment
Targets RLHF-induced people-pleasing, why models agree with wrong user assumptions, and how Chain-of-Thought reasoning can actively bury explicit constraints.
Query 3:
Agentic AI failure modes in multi-step reasoning and tool use
Targets sequential error cascading, action-reasoning mismatch (planning correctly but executing the wrong tool call), and termination unawareness — the infinite reflection loop.
Query 4:
Empirical studies on system prompt effectiveness and LLM behavior control
Targets what prompt structures are empirically shown to work — instruction hierarchy, the Confused Deputy attack vector in tool outputs, and why semantic headers outperform flat lists.
Query 5:
Attention degradation, context window failures, and long-horizon memory loss in LLMs
Targets the "lost-in-the-middle" structural bias in transformers, distractor interference in long contexts, and instruction drift as sequence length grows.
Each query was loaded into NotebookLM individually. With approximately 60 sources per query and a 300-source limit, all five fit exactly within the workspace.
Once all sources were loaded, I gave NotebookLM the following role-setting instruction before the main prompt:
You are acting as a senior prompt engineer and AI safety researcher. Your job in this session is not to answer questions — it is to analyze the research knowledge base I've loaded and produce a single deliverable: a production-grade system prompt for agentic AI. You are not summarizing the research. You are translating it into operational instructions. Prioritize precision over comprehensiveness — a short rule that is enforceable is better than a long rule that is vague.
Then the full meta-prompt was provided, which instructed the model to:
- Address all five failure domains in dedicated sections
- Ground every rule in a specific, documented failure mechanism from the research
- Annotate each rule with its source basis in brackets
- Label rules by severity:
[CRITICAL],[HIGH], or[MODERATE] - Include a Rule Hierarchy section for conflict resolution
- Produce a Research Coverage Report listing what was used and what was intentionally omitted
The output from NotebookLM included source annotations and severity tags — useful for auditing the research coverage, but not appropriate to leave in a deployed system prompt.
The raw NotebookLM output was research-legible but not prompt-ready. The cleanup pass did the following:
- Removed all severity labels, rule numbers, and source annotations — these are for the researcher, not the model
- Rewrote two rules that asked the model to be aware of its own attention mechanism (which no model can consciously do) into behavioral instructions it can actually follow
- Added an identity anchor at the top — two sentences establishing what the agent is and what its primary obligation is
- Added a self-violation recovery rule — instructions for what the agent does when it realizes mid-task that it has broken one of its own rules, which the original output was missing
- Kept every substantive rule and the Rule Hierarchy section intact — zero content loss
The cleaned, production-ready prompt is in the file above. It covers:
- Honesty and Factual Grounding — epistemic abstention, schema verification, retrieval over recall
- Integrity and Resistance to Pressure — anti-sycophancy, position stability under pushback, constraint enforcement
- Agentic Execution and Tool Use — error cascade interruption, action-reasoning sync, irreversible action gates, scope discipline, self-violation recovery
- Instruction Authority and Injection Defense — instruction hierarchy, Confused Deputy defense, conflict surfacing
- Context and Memory Management — distractor rejection, state persistence, payload positioning
- Rule Priority — explicit conflict resolution order when instructions contradict each other
NotebookLM's Research Coverage Report flagged several findings from the literature that were excluded from the prompt — not because they weren't valid, but because they describe infrastructure-level problems that a text-based system prompt cannot address:
- Hardware-specific hallucination rates (H-Neuron activation tracking, softmax scaling) — base-model interpretability interventions
- Mathematical derivations of Bradley-Terry reward models in DPO vs. PPO — the deployed agent cannot alter its own post-training weights
- Multi-agent failure modes (groupthink contagion, spectral radius of adjacency) — out of scope for a single autonomous agent
- Block-wise KV Cache Pruning and State Space Model architectures — infrastructure optimizations, not runtime behavioral rules
If a rule couldn't be followed by the model at inference time, it wasn't included.
Paste the system prompt directly into the system prompt field of any agentic AI tool that accepts one. It has been written to work with:
- Claude Code
- GitHub Copilot CLI
- OpenAI Codex / Codex CLI
- OpenCode
- Any tool or API that accepts a system-level instruction
No modification needed. It is intentionally tool-agnostic.
The rules in most system prompts are written to fix symptoms — "don't make things up", "ask before deleting files." The rules in this prompt are written to address causes — why models make things up, why they proceed past failures, why they drift from early instructions. That difference is what makes behavioral constraints durable across a long agentic session rather than just the first few exchanges.
The research is the prompt.
Solid ruleset, but a system prompt can't stop the model once it's compromised — if it decides to run
rm -rfor exfiltrate a key, the prompt already lost. That needs a layer below it, intercepting the actual tool call. immunity-agent does this for Claude Code — enforces policy on the call itself, not on what the prompt asked for.