Guardrails for AI Agents with AgentHooks

AI agents are moving beyond answering questions. They can look up customer records, issue refunds, update accounts and take other actions on a user’s behalf. That makes one question hard to avoid: how do you stay in control of what an agent sees, does and says?

A prompt can tell an agent not to reveal private information or call a risky tool. But a prompt is an instruction to a model, not a reliable control in your application. Models can misunderstand, be manipulated or simply make the wrong choice. For important decisions, your application needs checkpoints that evaluate what is happening and decide what may happen next.

That is the role of Microsoft.Agents.AI.AgentHooks, a package that connects Microsoft Agent Framework agents to the Agent Hooks specification. It gives your application a consistent way to inspect an agent run and apply your own policies as the run unfolds.

What are Agent Hooks?

Agent Hooks define specific points where an agent pauses and gives your application a chance to review the next step. At each point, your code receives context about what is happening and returns a decision, called a verdict. The agent then follows that decision.

There are eight interception points across a run:

  • agent_startup begins the run.
  • input checks the user’s message before the model sees it.
  • pre_model_call and post_model_call surround each call to the model.
  • pre_tool_call and post_tool_call surround each tool call.
  • output checks the final answer before it reaches the user.
  • agent_shutdown closes the run.

The model and tool checkpoints can repeat as the agent works through a request. For example, the model may call a tool, review its result, and then call another tool before producing a final response. Each step gives your application another opportunity to apply the right policy.

agenthooks-interception-points

Why use checkpoints?

A prompt can influence an agent, but it cannot guarantee that an action is safe. Interceptors let your application apply clear rules at the boundaries where data or actions matter: before a model receives sensitive input, before a tool changes a record, after a tool returns private data, and before an answer is shown to a user.

This approach offers several practical benefits:

  • Consistent coverage. User input, model calls, tool calls and final output all have defined review points.
  • Fail-closed behavior. In enforcement mode, if an interceptor fails, times out or returns an invalid decision, the action is denied. Streaming output is held until it passes its check.
  • Flexible decisions. An interceptor can allow, warn, deny, ask for human approval or transform data.
  • Clear separation. Business tools can focus on their job, while policy rules live in focused, testable interceptors.
  • An audit trail. Each checkpoint can record where it occurred, what decision was made, and which rule made it.
  • A safer rollout. Evaluate-only mode records what a policy would have blocked without enforcing it, letting you assess rules before they affect users.

Interceptors: the checkpoints you control

An interceptor is a small policy component that reviews an agent event and returns a verdict. Agent Hooks calls it at the relevant interception points and provides an AgentContext containing information about that moment in the run.

The context tells the interceptor where it is, for example, before a tool call, and what is about to happen. At a tool checkpoint, it can include the tool’s name and its arguments. At other points, the target may be the incoming user message, the model’s response, a tool result or the final answer.

That context lets you write rules that match the event. A tool policy, for instance, could reject any attempt to delete a customer and require approval before issuing a refund above a set amount. The policy checks the tool name and its arguments before the tool runs. If the refund is small, it allows the call; if it exceeds the limit, it asks for human approval; if the action is prohibited, it denies the call.

The tool itself does not need to know about the guardrail. This keeps policy decisions in one place and makes them easier to review and update.

Verdicts: what happens next

Every interceptor returns a verdict. The verdict determines whether the agent continues, pauses for approval, stops, or proceeds with adjusted data.

VerdictWhat it means
AllowLet the step proceed.
WarnLet it proceed, while recording a warning for visibility or review.
DenyBlock the step. The effect depends on the checkpoint: the run can stop, or a blocked tool call can return an error to the model so the conversation can continue safely.
EscalatePause for a human decision. An approval resolver receives the request, and the step proceeds only if it is approved.
Transform (Decision.Transform)Change the data before it continues through the agent.

Transform is especially useful because it can protect information without stopping the entire interaction. At the input checkpoint, an interceptor can replace a Social Security number with a marker such as [SSN REDACTED] before the model receives the message. At a post-tool checkpoint, it can mask a card number in a tool result. At the output checkpoint, it can remove a secret from the answer before the user sees it.

A transformation targets a specific value in the event data, such as the content of the current target. The interceptor returns the replacement, and Agent Hooks applies it before the run continues. The model can still respond to the request, but it does not need to see or repeat the protected value.

What happens when a tool is blocked?

Suppose a user asks an assistant to delete a customer record. At pre_tool_call, the interceptor sees that the agent is about to invoke the deletion tool. It returns a deny verdict, so the tool never runs. The model receives information that the action was blocked and can explain the restriction or offer another option. The run can then continue to a safe final answer.

For a request that requires approval, the interceptor returns an escalation verdict instead. The approval resolver routes the decision to a human. If approved, the tool call proceeds; if denied, the action remains blocked. This makes human review part of the flow, rather than relying on the model to decide for itself when it should ask.

A useful audit trail

Each interception point can produce a record with the checkpoint, verdict, interceptor and reason. That record helps explain what happened during a run and makes policies easier to monitor.

For example, an audit trail could show that a request passed input and model checks, but a destructive tool call was denied by the tool policy. The assistant then continued and returned a safe explanation. The tool was not executed, and the record identifies the rule responsible for stopping it.

Evaluate-only mode is useful while introducing a new policy. In this mode, the system records the verdict the interceptor would have returned, but does not block the action. Teams can review those records, adjust rules that are too broad, and then switch to enforcement when the results look right.

Putting the layers together

Agent Hooks fits alongside other safety controls. For example, Microsoft Foundry’s content safety features can help protect model interactions, while application-level interceptors can govern your own tools, data, approvals and final responses. Each layer has a different view of the request, so using them together can provide more complete coverage.

Good to know

  • Agent Hooks provides places to apply controls; it is not a sandbox. Interceptors run inside your trusted application, so they should be implemented and operated with the same care as other security-sensitive code.
  • Tools hosted and executed by a model provider do not pass through your application’s pre_tool_call checkpoint. Their activity may be visible after the model call, but it is important to understand this boundary when deciding which actions to expose.

If you are putting agents in front of real users and real data, prompts alone are not enough to govern every action. Interceptors give your application a chance to inspect each important step, and verdicts make the next action explicit: allow it, flag it, stop it, ask a person or safely transform the data.

Start in evaluate-only mode, review what your policies catch, and refine them before enforcing them. That gives you a practical path from experimentation to agent behavior you can observe and control.

To see a full implementation as a sample for Agent Hooks, please visit the repo here

Let us know in the comments if this was useful to you.

Leave a Comment

Your email address will not be published. Required fields are marked *

Are you human? Please solve:Captcha


more insights

Scroll to Top