Guides, sensors and enforcement
- Advanced
- 35 min
- Lesson 4 of 7 in Harness engineering
- Last verified
Select text in the lesson first to keep it with your note. With the keyboard, move focus here and press the button: the note goes with the section you are reading.
In this module
On this page
Before you start
- Completed:What is an agent harness?
- Completed:Guardrails, safety and prompt injectionSafety and guardrails
- Completed:Limiting blast radius and treating output as untrustedSafety and guardrails
You will be able to
- Classify a control as a guide (before the action) or a sensor (after it), and as computational or inferential, and say why an agent needs both.
- Place checks at the cheapest effective point in the lifecycle and write sensor output the agent can act on.
- Explain why a hook is a guarantee and a prompt rule is a suggestion, and say which hook points can block an action.
- Combine permission tiers, a sandbox with filesystem and network limits, and the lethal-trifecta rule into defence in depth.
- Explain why the agent that builds the work should not be the only thing that checks it, and where behaviour checks stay weak.
The instructions say: refunds above ₹5,000 need approval. Vihaan issues one for ₹8,000 anyway.
The nightly report shows it the next morning. The payments system could have refused it at the time, and the instructions could have been clearer.
Three things watch the same line: the instruction, the report and the block. Which one is enough on its own?
Concept
Once an agent can act, you need a way to steer it and a way to stop it. Böckeler’s April 2026 article on martinfowler.com gives a clean vocabulary. A guideGuide (harness)A control that steers an agent before it acts, such as an instruction file, a skill or a template. It raises the odds of a good first attempt but does not check anything.Open the glossary entry is a control that anticipates the agent’s behaviour and steers it before it acts, so a good first attempt is likelier. A sensorSensor (harness)A control that observes after the agent acts, such as a linter, a test or a review, so the agent can correct itself. It works best when its output says what to fix.Open the glossary entry observes after it acts, so the agent can correct itself. Separately, a control is computational when it is a deterministic, fast check on ordinary compute (tests, linters, type checkers, structural analysis), and inferential when it is a semantic check by a model (an AI code review, an LLM judge), which is slower, costlier and less predictable.
This lesson is about designing that enforcement layer for the harness. The security ideas it relies on are taught elsewhere and only revisited here: prompt injection in guardrails and prompt injection, and blast radius and the lethal trifecta in limiting the blast radius.
Why It Matters
A rule written in a prompt is a request. The agent follows it most of the time and then, one day, does not. A harness that matters in production has to make the important rules hold whether or not the model cooperates, and it has to do that cheaply enough to run on every change. Getting the mix of controls right is what separates an agent you can leave running from one you must watch.
Mental Model
Back in the story: the written rule is a guide, steering Vihaan before he acts. The nightly report is a sensor, reporting after the refund has gone out. The block in the payments system, which refuses the call before it completes, is a hook: it fires at a defined point and can stop the action. The rule alone fails because nothing checks it. The report alone comes too late for this refund, although it helps the next one. The block alone stops this one refund but gives no guidance. A good setup has all three, and the cheapest one that would have caught the mistake is the one to build first.
Guides and sensors
| Guides (feedforward) | Sensors (feedback) | |
|---|---|---|
| When | before the agent acts | after the agent acts |
| Purpose | raise the odds of a good first attempt | let the agent notice and fix its own mistake |
| Examples | instruction files, skills, reference documents, templates | linters, type checkers, tests, structural checks, an AI review, an LLM judge |
| Fails alone because | nothing checks that the rule was followed | the agent repeats the same mistakes without guidance |
The examples in the table are ours, not a list from the article. You need both. Sensors work best when what they print is written for a model to act on: a lint error that states the rule that was broken and how to fix it is far more useful than a bare “failed”.
The computational and inferential split gives a rule of thumb. Run computational sensors on every change, because they are cheap, fast and reliable. Spend inferential checks where meaning matters and no deterministic test exists, and treat their verdicts as less certain.
Check early, check cheaply
Böckeler’s advice is to keep quality left: run checks as early as possible, with fast ones before integration and expensive ones after. Some drift is monitored continuously, outside any single change, such as dead code or dependency scans. A reasonable ordering:
One more design rule keeps sensors from consuming the budget they protect: success is silent and failure is verbose. A passing check adds nothing to the context. A failing one adds a short, specific message the agent can use.
Hooks: instructions that always run
A hookHookCode the harness runs at a defined point, such as before or after a tool call or when the agent tries to stop. A rule enforced by a hook holds whatever the model decides.Open the glossary entry is code the harness runs at defined points in the agent’s lifecycle. Claude Code’s documentation shows what that looks like in practice: handlers run at events such as before a tool call, after one, when the agent tries to stop, and when a prompt is submitted. What matters for design is what each point can do:
- Before a tool call can block it. A hook there can refuse a deletion, a write outside the workspace, or an edit to a protected path.
- After a tool call cannot undo it, because the tool already ran. It can feed a message back to the agent, which suits a lint or type check after an edit.
- When the agent tries to stop can prevent the stop and keep it working, which is how you refuse “done” while the tests are failing. Claude Code caps this at eight consecutive continuations, after which it ends the turn, so a stop hook is not an unlimited block.
- When a prompt is submitted can block that prompt, and the documentation lists a few other events that can block as well. Read the current table before you rely on a specific point.
The documentation also describes the contract: a hook signals a block with a specific exit code or a structured decision, and a hook that blocks wins even if it prints something that suggests allowing. These are product details that change, so read the current page, but the pattern holds across tools: a rule in a prompt is a suggestion; a hook is a guarantee.
Architecture as a constraint
Instructions about structure (“keep the layers separate”) are a guide. A structural test that fails when a lower layer imports a higher one is a computational sensor. InfoQ’s summary of OpenAI’s February 2026 report (a secondary account) describes dependencies flowing in one direction through fixed layers, with structural tests checking compliance and linters and CI checking that the design documents are consistent and cross-linked. The transferable idea is to enforce invariants (the boundaries that must hold) and leave the implementation free, and to put the fix in the error message so the agent can repair itself. When a document is not enough, promote the rule into code.
Permissions, sandboxes and the lethal trifecta
Permissions decide what the agent may do without asking. A common way to tier them, offered as a design aid:
| Tier | Example | Policy |
|---|---|---|
| Read-only | read files, search | allow |
| Reversible write | edit files in the workspace, make a branch | allow inside the sandbox |
| Costly or external | network calls, installs, spending money, sending email | allow-list or approve each use |
| Destructive or irreversible | delete data, deploy, force-push, pay | explicit human approval |
Approvals have a cost of their own. Anthropic’s October 2025 post on sandboxing describes approval fatigue: constantly clicking approve slows work and can mean people stop scrutinising what they approve. Its answer is to set boundaries so that the agent can work freely inside them, and it reports an 84 percent reduction in permission prompts in internal use. Two boundaries matter together. Filesystem isolation limits the agent to specific directories; network isolation limits it to approved servers. The post says you need both: without network isolation a compromised agent could send out sensitive files, and without filesystem isolation it could escape the sandbox and reach the network. Where credentials are needed, the post’s web version keeps them outside the sandbox and uses a proxy that checks the request and attaches the real token. Other layers worth having: no secrets inside, limits on CPU, memory and time, and a separate working copy or container per task so parallel agents cannot collide. Fail closed when identity or scope is missing; Microsoft’s file-access documentation describes exactly that behaviour.
The security rule to keep in mind is the lethal trifectaLethal trifectaThe combination of private data, exposure to untrusted content and an outbound channel in one agent. Together they allow data theft, so do not combine all three.Open the glossary entry (Simon Willison, 16 June 2025): private data, exposure to untrusted content, and a way to communicate externally. An agent with all three can be tricked into sending the data out. His advice is to avoid the combination entirely, and he quotes the Design Patterns for Securing LLM Agents against Prompt Injections paper for the rule that an agent that has ingested untrusted input must be constrained so the input cannot trigger consequential actions. He also warns against relying on prompt instructions or guardrail products as the control. In a harness that means removing one leg by design, separating agents by trust level, giving each tool its own least-privilege credential, and requiring approval where data crosses a boundary. See limiting the blast radius for the underlying reasoning.
Verification you can trust
Two habits make verification worth having. Do not let the builder be the only grader. An agent that wrote the work and also approves it has an obvious conflict; prefer deterministic tests, and where you need judgment, use a separate check. Make the success criteria hard for the agent to change: protect test files with permissions or a hook, and keep the list of what must pass where the agent cannot rewrite it, rather than relying on a prompt that says not to.
Be honest about the limits. Böckeler calls the behaviour side, whether the software does the right thing, the hardest and the least solved. Her three categories are maintainability checks (duplication, complexity, coverage, style; the easiest), architecture-fitness checks (performance and logging standards, boundaries) and behaviour checks (the hardest). Common practice for behaviour relies on a functional specification, AI-generated tests and manual testing, and she says that puts a lot of faith in AI-generated tests, which is not good enough yet. A green suite with decent coverage is therefore not full confidence. Add coverage and mutation checks where you can, and keep manual testing for critical paths.
She also notes that some codebases are easier to harness than others: strong typing gives you a type checker as a sensor, and clear module boundaries support structural rules. Legacy systems are hardest exactly where the harness is most needed. And she lists open questions that are worth saying out loud in an interview: how to keep guides and sensors from contradicting each other as the set grows, whether a sensor that never fires means quality or blindness, and how to measure how much a harness covers.
Real-World Application
A coding agent that must never touch infra/ and must pass lint before it commits. A guide: the instruction file says so and links the rules. A before-tool hook blocks any write under infra/ and prints which path is protected and who to ask. An after-edit hook runs the formatter, linter and type check, silent on success and short on failure. A stop hook refuses to finish while the targeted tests are red. Pushing needs approval. CI runs the full suite as an independent grader that the agent cannot edit. Each control answers a different failure, and none depends on the model remembering a rule.
Interview Perspective
Expect: “A coding agent keeps violating your module boundaries and occasionally edits tests to go green. Design the enforcement layer.” “Guides versus sensors; computational versus inferential: give examples.” “Your agent reads public GitHub issues, has repository access and can call an external API. What is the risk and how do you redesign it?”
A strong answer pairs guides with sensors, chooses computational checks first, places them early, makes tests and success criteria hard to change, uses a hook where a rule must hold, names the lethal trifecta, and says where verification is still weak. Common mistakes: relying on prompt text for hard rules; verbose passing output filling the context; an LLM judge where a unit test would do; letting the author of the code also approve it; auto-approving destructive tools; a sandbox with open network access and mounted cloud credentials. A misconception to watch for: “a stricter system prompt is a guardrail.”
Provenance: Common industry pattern. These are typical of agent-engineering interviews; none is verified for a named company.
Practice Questions
- Basic: Explain guides and sensors, and computational and inferential controls, with two examples of each pairing.
- Intermediate: Design the hooks for a code agent that must never touch
infra/and must pass lint before it commits. - Advanced: Your agent reads issues from the public, has repository access, and can open pull requests and call an external API. Identify the risk and redesign it.
- Product-Company: Propose the guides, sensors and timing of each for a template used to start a new Python service.
Activity
Take one rule your team currently writes in a prompt or a document. Decide whether it should be a guide, a sensor or a hook, and which tier of cost (edit time, commit time, CI) it belongs at. Then write the exact message a failing sensor would print so that an agent could fix the problem without asking.
Homework
Design the enforcement layer for an agent that runs read-only SQL against production replicas. Cover the permission tiers, what the sandbox limits, which checks run before the query is sent, what a failing check prints, how the agent’s work is verified by something other than the agent, and which leg of the lethal trifecta you remove.
Quick Revision
- Guide steers before; sensor observes after. Use both. Computational first; inferential where meaning matters.
- Check early and cheaply; success silent, failure verbose and written for the agent.
- A prompt rule is a suggestion; a hook is a guarantee. Before-tool hooks can block; after-tool hooks cannot undo; a stop hook can refuse “done” (up to a continuation cap).
- Tier permissions; avoid approval fatigue with a sandbox that limits both files and network; keep credentials out; fail closed.
- Lethal trifecta: private data, untrusted content, external communication. Remove one leg.
- Do not let the builder be the only grader; make success criteria hard to change; behaviour checks are the weak spot.
Check yourself
- Walk-through: A coding agent keeps breaking your module boundaries and sometimes edits tests to pass. Design the enforcement layer.
- Variation: Do the same for an agent that runs SQL on production replicas.
- Common misconception: “A stricter system prompt is a guardrail.” A prompt is a guide; a guardrail that must hold needs a check or a hook.
Related
Resources & Further Reading
Checked sources to go deeper. The essential ones come first in each group.
Further reading
LLM06:2025 Excessive Agency (opens in a new tab)Essential
Names excessive functionality, permissions and autonomy as root causes, which are the things the permission tiers and sandbox in this lesson limit.
Agents Rule of Two: A Practical Approach to AI Agent Security (opens in a new tab)
A second framing of the same risk as the lethal trifecta, with a practical rule for how many of the three traits one agent session should hold.
OWASP Top 10 for Agentic Applications for 2026 (opens in a new tab)
A current catalogue of agent-specific risks, useful for checking whether your hooks and sandbox cover the main ones.
Demystifying evals for AI agents (opens in a new tab)
Covers how to grade agent runs, which connects to keeping the grader separate from the builder.
Hands-on
NeMo Guardrails (opens in a new tab)
An open-source library with input, dialog, retrieval, execution and output rails; try it to see what a framework offers beside hooks and tests.
More for this module: Harness engineering resources
Practice
Test what you just read. Quizzes and cards are grouped by module: Harness engineering.
Check yourself10 questions on what this lesson set out to teach
Checking answers needs JavaScript. You can still read every question and option below.
Keyboard: arrow keys move between options. Space or Enter selects the focused option.