Guides, sensors and enforcement

  • Advanced
  • 35 min
  • Lesson 4 of 7 in Harness engineering
  • Last verified

Open slides(27 slides)

Before you start

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.

Diagram: A guide steers before the action, a hook can stop the action as it happens, and a sensor reports afterwards so the agent or the team can...

feedback for the next attempt

Guide
written rule, before

Agent acts

Hook
blocks the call as it happens

Sensor
reports after: lint, tests, nightly report

Diagram summary: A guide steers before the action, a hook can stop the action as it happens, and a sensor reports afterwards so the agent or the team can correct. Each fails alone, so a good harness has all three, built cheapest first.

Guides and sensors

Guides (feedforward)Sensors (feedback)
Whenbefore the agent actsafter the agent acts
Purposeraise the odds of a good first attemptlet the agent notice and fix its own mistake
Examplesinstruction files, skills, reference documents, templateslinters, type checkers, tests, structural checks, an AI review, an LLM judge
Fails alone becausenothing checks that the rule was followedthe 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:

Diagram: Checks run from cheapest and fastest right after an edit, through commit-time and CI checks, to continuous scans and runtime signals, with...

new work

Agent edit

After the edit: format, lint, type check (seconds)

Before commit or push: fast tests, structural checks, a review agent

CI: full tests, slower checks, deeper review

Continuous drift scans: dead code, dependencies

Runtime signals: errors, latency, sampled quality checks

Diagram summary: Checks run from cheapest and fastest right after an edit, through commit-time and CI checks, to continuous scans and runtime signals, with problems feeding back into new work.

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.

Diagram: Hooks fire at points in the lifecycle, and what each can do differs.

Prompt submitted

Hook can block the prompt

Model proposes a tool call

Before the tool call:
hook can BLOCK it

Tool runs

After the tool call:
hook cannot undo it, can feed a message back

Agent tries to stop:
hook can PREVENT the stop

Diagram summary: Hooks fire at points in the lifecycle, and what each can do differs. Before a tool call a hook can block it. After the call it cannot undo it but can send feedback. When the agent tries to stop, a hook can refuse the stop, which is how you reject “done” while tests fail.

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:

TierExamplePolicy
Read-onlyread files, searchallow
Reversible writeedit files in the workspace, make a branchallow inside the sandbox
Costly or externalnetwork calls, installs, spending money, sending emailallow-list or approve each use
Destructive or irreversibledelete data, deploy, force-push, payexplicit 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.

Diagram: A sandbox needs both boundaries.

without filesystem isolation: can escape and reach the network

without network isolation: files can be sent out

Agent

Filesystem isolation:
only specific directories

Network isolation:
only approved servers

Free to work inside the boundaries,
far fewer approval prompts

Risk

Risk

Diagram summary: A sandbox needs both boundaries. Filesystem isolation keeps the agent in specific directories and network isolation limits it to approved servers. With only one, a compromised agent can still send files out or escape to the network. Inside both, the agent can work freely with fewer prompts.

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.

Diagram: The agent that wrote the work should not be its only grader.

Builder agent writes the change

Deterministic checks:
tests, linters, types

Separate evaluator for judgment

Protected success criteria:
tests and pass list the builder cannot edit

Accept

Diagram summary: The agent that wrote the work should not be its only grader. Deterministic checks run first, a separate evaluator handles judgment, and the success criteria sit where the builder cannot rewrite them.

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.

Resources & Further Reading

Checked sources to go deeper. The essential ones come first in each group.

Further reading

Hands-on

  • NeMo Guardrails (opens in a new tab)

    NVIDIA2026Repository

    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.

0 of 10 answered

Keyboard: arrow keys move between options. Space or Enter selects the focused option.

ObjectiveClassify 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.

  1. Question 1 of 10A linter runs after every edit and prints the rule that was broken and how to fix it. How is it best classified?

    Choose one answer.

  2. Question 2 of 10Which of these are computational controls? Select all that apply.

    Choose all that apply.

ObjectivePlace checks at the cheapest effective point in the lifecycle and write sensor output the agent can act on.

  1. Question 3 of 10Which check belongs right after every edit, before anything else runs?

    Choose one answer.

  2. Question 4 of 10A lint check prints 300 lines of passing results into the agent's context on every edit. What is the problem, and what is the fix?

    Choose one answer.

ObjectiveExplain why a hook is a guarantee and a prompt rule is a suggestion, and say which hook points can block an action.

  1. Question 5 of 10Which hook point can refuse a file deletion before it happens?

    Choose one answer.

  2. Question 6 of 10The tests are failing, yet the agent says it has finished. Which control can refuse to let it stop?

    Choose one answer.

ObjectiveCombine permission tiers, a sandbox with filesystem and network limits, and the lethal-trifecta rule into defence in depth.

  1. Question 7 of 10A sandbox limits the agent to the workspace folder but allows any outbound network connection. What is the gap?

    Choose one answer.

  2. Question 8 of 10Which agent design contains the lethal trifecta?

    Choose one answer.

ObjectiveExplain why the agent that builds the work should not be the only thing that checks it, and where behaviour checks stay weak.

  1. Question 9 of 10The agent edits its own failing tests until they pass. What is the strongest protection?

    Choose one answer.

  2. Question 10 of 10Why is a green, AI-generated test suite with decent coverage not enough to trust behaviour?

    Choose one answer.