An agent can decide which tools to call and how to use their results.
This flexibility is certainly useful, but it also creates a need for boundaries during execution.
Probably the first thing you will think of is adding instructions to describe the behavior you want. But instructions are only a soft form of enforcement; there is no guarantee that the agent will always observe them.
Guardrails , on the other hand, provide stronger control. Concretely, they provide a runtime checkpoint where we can validate an agent’s input or output, accept/reject/modify it before the run continues.
In this post, we'll show how we can add a runtime guardrail using the OpenAI Agents SDK.
We'll use Gemma 4 E4B running locally through Ollama to show that these guardrails also apply to agents powered by locally hosted models, not necessarily only the OpenAI models.
···
1. Where Guardrails Fit
A typical agent run moves through several stages.…