liveBook · Manning

Guardrail sandwich

As explained in Designing AI Agents

An execution pattern that places a state-changing action between trusted pre-check and post-check controls, with a controlled executor in between.

A guardrail sandwich places a state-changing action between trusted controls that the action cannot rewrite. A pre-check decides whether it may start, a controlled executor limits how it runs, and a post-check uses protected evidence to decide whether the effect satisfies the checked contract fields. Use it for costly, sensitive, or difficult-to-reverse effects. section 6.5

The execution path has three responsibilities:

  • Pre-check: evaluate the proposed action against protected preconditions before execution begins. section 6.5
  • Controlled execution: expose the guarded path through a facade and snapshot the request and runner arguments. section 6.5
  • Post-check: query a protected evidence adapter and accept the checked contract fields only when the task-specific evidence supports them. section 6.5 section 6.9

The hierarchy is one of trust, not time: higher-trust controls constrain the lower-trust action and judge its result. Keep policy and verifiers outside the agent's writable state. Enforce the controls at a runtime chokepoint, and classify effects using registered contracts rather than tool names alone. section 6.5 section 6.5.5

Containment is not verification. A container can limit where a command runs while still allowing it to write the wrong file. Similarly, output redaction controls information release but does not establish that a payment was correct. Check the business effect separately. section 6.5.5

A failed or blocked post-check does not roll back an action that has already run. Restrict access to the raw result, withhold unaccepted output, and create a durable compensation or investigation obligation. The task remains incomplete until that obligation has an accepted outcome. section 6.5.5

Guarding publication

For a schema change spanning a definition, generated client, and consuming service, guard publication of a pull request or package. The pre-check confirms the expected base revision and destination; the post-check resolves the published object and reruns the required integration probe. A persistent plan can track dependencies, while tool dispatch narrows the capabilities available at each step. section 6.6

Choose the smallest structure that addresses the failure. A fixed handler may be sufficient if it enforces the same admission and verification requirements; add human approval when policy requires it, rather than treating a pre-check as a substitute. Monitor rejection, unknown outcomes, postcondition failures, unverified release, compensation debt, bypass attempts, latency, and accepted effects. section 10.7.1 section 6.5

How Designing AI Agents covers it

How deep it goes
Explains control placement, failure modes, recovery obligations, and operational metrics without specifying a complete implementation.
Examples
Uses cross-repository schema publication to illustrate revision checks, published-object readback, and an integration probe.
What you can do after
Operate/configure guarded execution paths, postcondition checks, compensation obligations, and reliability metrics for state-changing actions.
How it connects
Connects execution guardrails with tool dispatch, plan-and-execute, prompt chaining, and approval gates.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing AI Agents. The section links point to the parts of the book it draws on.