An agent can produce a useful-looking answer that contains unsafe advice, confidential information, unsupported claims, or noncompliant content. A guardrail is a gate at an agent boundary: it assesses information against a requirement and decides whether that information may cross to a user, tool, or another component. It is a last line of defense, not a substitute for designing the rest of the agent for safety and reliability. section 4.1 section 4.2.2
The gate has two responsibilities. An assessor—usually a model or agent—evaluates a control input. The gating procedure then either forwards the protected information or blocks it, commonly returning a generic placeholder or apology. The control input is often the information being protected, but the two can differ. Internal guardrails may return reasons that help another component revise its work; user-facing guardrails generally avoid exposing rejection reasons. section 4.2
Listing 4.1 guardrail.py: Sketch of a generic Guardrail class
from ..utils import IE
class Guardrail(IE[[str], str]):
def __init__(self, assessor: IE[[str], bool]):
self.assessor = assessor
async def __call__(
self, control_input: str, information: str
) -> str:
if await self.assessor(control_input):
return information
else:
return "Response blocked by the guardrail."
The asynchronous interface separates the control input from the information to be released. Its branch makes the verdict operational: a passing assessment returns the information; a failing one returns a blocked-response message. section 4.2
Placement and timing determine what the gate can inspect and what it costs:
- An internal guardrail sits between subagents; an external guardrail sits between an agent and a tool or other external system; a response guardrail gates what reaches the user. section 4.2
- A sequential guardrail assesses information before forwarding it. A parallel guardrail can assess the input that produces protected output while that output is being generated. Parallel execution can reduce latency but waste generation work when the verdict blocks it. section 4.3.1
- Assessment adds model-invocation cost, which can grow with serving volume. Its effect depends on the assessor: safety, security, quality, and groundedness checks target different failures. section 4.2.1
Guarding an image generator twice
A parallel guardrail checks the text request before an image is released. A sequential guardrail then checks the generated image before sending it to the user. The first can reject risky requests; the second can catch unsafe output from requests that initially passed. section 4.4.1
Protecting a tool boundary
A deep research agent uses internal search and calendar tools alongside internet search. A sequential guardrail checks queries destined for internet search so that confidential information is not sent outside the agent’s information boundary. section 4.4.3
A compliance check can also return feedback instead of merely ending a workflow: a failed mortgage report goes back to report writing for revision. Guardrails can therefore share characteristics with errands and refiners. They can also be paired with resampling; in some user-facing settings, human assessment replaces automated assessment. None of these arrangements makes the gate perfect. section 2.6 section 4.2.3 section 4.2.2
