HeadlinesBriefing HeadlinesBriefing.com

Add Guardrails to Local LLM Agent

Towards Data Science •
×

An agent can decide which tools to call and how to use their results. This flexibility is useful, but it also creates a need for boundaries during execution. Guardrails provide stronger control than instructions alone, offering 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 show how to add a runtime guardrail using the Open AI Agents SDK. We use Gemma 4 E4B running locally through Ollama to show that these guardrails also apply to agents powered by locally hosted models.

The Open AI Agents SDK allows us to place guardrails at different points along the agentic problem-solving process: Input guardrails check the request before the agent starts; tool-input guardrails check a tool call before the tool receives its arguments; tool-output guardrails check a tool’s result before it returns to the agent; output guardrails check the agent’s final response before it is shown to the user.

For the case study, we build a small customer-support agent where a customer needs to contact an online store because a refund has not arrived yet. The case file contains information that can be shared with the customer, such as the refund amount, current status, and expected processing time, but also includes internal details that should stay private, such as the internal refund token, fraud-risk score, and the assessment that the account was flagged for possible repeat-refund abuse.

We first define a naive local agent without such a guardrail, then implement a tool-output guardrail to prevent sensitive details from leaking to the customer.

Source: Towards Data Science · Summarized by HeadlinesBriefing