# What are AI guardrails? Types, examples and their limits

URL: https://sdclabs.com/glossary/ai-guardrails/

> AI guardrails check inputs, outputs and tool calls outside the model. The OWASP risks they answer, where they run, and a runnable Python tool-call gate.

# What are AI guardrails?

[Sergey Almyashev](https://sdclabs.com/author/almyashev/) 2026-11-19

Definition

AI guardrails are checks that sit outside the model and enforce your rules on what goes in and what comes out: input filters, output validators, and limits on which tools an agent may call, with which arguments, permissions and budgets. When a rule fails, the guardrail blocks the request, rewrites it or holds it for human approval.

## Which risks do AI guardrails address?

OWASP's 2025 list of LLM application risks is the usual map (its risk pages were last updated in April and May 2025). Four entries are where guardrails do most of the work:

| OWASP risk | What goes wrong | Guardrail that answers it |
|---|---|---|
| LLM01 Prompt injection | Input text changes the model's instructions | Input checks, separating trusted instructions from untrusted content |
| LLM05 Improper output handling | Model output reaches a browser, shell or database unchecked | Output validation and encoding before any downstream use |
| LLM06 Excessive agency | The model triggers damaging actions | Tool allowlists, minimal permissions, human approval |
| LLM10 Unbounded consumption | Requests run up cost or exhaust resources | Rate limits, token and call budgets |

OWASP is blunt about the limit of the first row: given how models work, "it is unclear if there are fool-proof methods of prevention for prompt injection" ([LLM01](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) ). That is why guardrails come in layers and why the tool layer matters most. For LLM06 Excessive agency, OWASP traces the root cause to excessive functionality, excessive permissions or excessive autonomy. Each of these is fixed in your code, not in the model.

## Where do guardrails run in an AI system?

Frameworks place checks at different points, and the points decide what a guardrail can catch.

| Stage | What is checked | Example from current docs |
|---|---|---|
| Input | The user's message before the model sees it | NeMo Guardrails input rails; OpenAI Agents SDK input guardrails |
| Retrieval | Documents pulled in for context | NeMo Guardrails retrieval rails |
| Dialog | Which conversation paths are allowed | NeMo Guardrails dialog rails, written as Colang flows |
| Tool call | Tool name, arguments, permissions, before and after the call | NeMo Guardrails execution rails; OpenAI Agents SDK tool guardrails |
| Output | The final answer before it reaches the user or another system | Output rails; output guardrails |

The [NeMo Guardrails library](https://docs.nvidia.com/nemo/guardrails/latest/index.html) names five rail types: input, retrieval, dialog, execution and output. The [OpenAI Agents SDK guardrails docs](https://openai.github.io/openai-agents-python/guardrails/) add two details that catch teams out in multi-agent setups:

- **Input guardrails run only for the first agent in the chain, and output guardrails only for the agent that produces the final output.** If you need a check around each call in a workflow with handoffs or delegated specialists, use tool guardrails, which run on every guarded function-tool invocation.
- **Input guardrails run in parallel with the agent by default.** That saves latency, but if the tripwire fires, the agent may already have used tokens and executed tools. Blocking mode (run_in_parallel=False) finishes the check before the agent starts.

## How are guardrails different from evals and model alignment?

|   | Guardrails | Evals | Model alignment |
|---|---|---|---|
| When it acts | On every live request | Before release and on samples | During model training |
| Who controls it | Your team, in your code | Your team, in your test suite | The model provider |
| What it produces | Allow, block, rewrite or hold | A score against a threshold | Default behavior of the model |
| What it misses | Attacks no rule anticipated | Cases not in the dataset | Your app's own rules |

Guardrails stop a bad request in the moment. AI evals tell you, before release, whether the guardrails and the model still behave as intended. You need both.

## Example: a tool-call gate in Python

OWASP's [agentic risk list for 2026](https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026/) , published in December 2025, recommends a policy enforcement layer it calls an "intent gate": treat model and planner outputs as untrusted, and validate intent and arguments, enforce schemas and apply rate limits before any tool runs. Here is a minimal version, with an output check added. It uses only the Python standard library, and the output shown is from running this file as printed.

import re # Policy for each tool the agent may call. Anything not listed is denied. POLICY = { "search_orders": {"args": {"customer_id": str}, "max_calls": 20, "approval": False}, "issue_refund": {"args": {"order_id": str, "amount": float}, "max_calls": 1, "approval": True}, } CARD = re.compile(r"\b(?:\d[ -]?){13,16}\b") # card-like numbers must never leave the system def check_tool_call(name, args, calls_so_far, approved=False): rule = POLICY.get(name) if rule is None: return "deny: tool not allowed" if set(args) != set(rule["args"]): return "deny: unexpected arguments" if any(not isinstance(args[k], t) for k, t in rule["args"].items()): return "deny: wrong argument type" if calls_so_far.get(name, 0) >= rule["max_calls"]: return "deny: call budget spent" if rule["approval"] and not approved: return "hold: needs human approval" return "allow" def check_output(text): return "block: card number in output" if CARD.search(text) else "allow" used = {} print(check_tool_call("search_orders", {"customer_id": "c-42"}, used)) print(check_tool_call("delete_customer", {"customer_id": "c-42"}, used)) print(check_tool_call("issue_refund", {"order_id": "1182", "amount": 49.0}, used)) print(check_tool_call("issue_refund", {"order_id": "1182", "amount": 49.0}, used, approved=True)) print(check_output("Your card 4111 1111 1111 1111 was charged."))
Output, line by line: allow, deny: tool not allowed, hold: needs human approval, allow, block: card number in output. The model never sees this code and cannot talk its way past it, which is the point of keeping guardrails outside the model. In production, the caller also increments calls_so_far after each allowed call so the budget applies.

## What should you check before trusting your guardrails?

1. **Every tool has a written policy** : allowed arguments, permissions on the downstream system, a call budget and whether a person must approve.
1. **Guardrails cover every agent, not only the first one.** Check where your framework actually runs each check.
1. **Every block and hold is logged** with the input that triggered it. Those logs show false positives and new attack patterns; see agent observability.
1. **The eval suite includes attack cases** , so a prompt or model change that weakens a guardrail fails CI.

SDCLabs adds guardrails for inputs, outputs, rate and cost as part of its [AI agents](https://sdclabs.com/services/ai-agents/) work, and our [responsible AI](https://sdclabs.com/services/responsible-ai/) service tests them for prompt injection and data leakage before each release. For the product side of the question, read [Can you trust an AI agent inside your product?](https://sdclabs.com/blog/ai-agents-in-products/)

## Sources

1. [LLM01:2025 Prompt Injection](https://genai.owasp.org/llmrisk/llm01-prompt-injection/) , OWASP Gen AI Security Project, 2025-04-17
1. [LLM05:2025 Improper Output Handling](https://genai.owasp.org/llmrisk/llm052025-improper-output-handling/) , OWASP Gen AI Security Project, 2025-05-05
1. [LLM06:2025 Excessive Agency](https://genai.owasp.org/llmrisk/llm062025-excessive-agency/) , OWASP Gen AI Security Project, 2025-05-05
1. [LLM10:2025 Unbounded Consumption](https://genai.owasp.org/llmrisk/llm102025-unbounded-consumption/) , OWASP Gen AI Security Project, 2025-04-28
1. [OWASP Top 10 for Agentic Applications for 2026](https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026/) , OWASP Gen AI Security Project, 2025-12-09
1. [NeMo Guardrails library overview](https://docs.nvidia.com/nemo/guardrails/latest/index.html) , NVIDIA, 2026-09-16
1. [Guardrails](https://openai.github.io/openai-agents-python/guardrails/) , OpenAI Agents SDK documentation, 2026-11

## Frequently asked questions

### What is a guardrail in AI?

A rule enforced in code around a model, not inside it. It inspects a prompt, a model answer or a planned tool call and allows, blocks, rewrites or escalates it.

### What are some examples of AI guardrails?

Blocking prompts that try to override instructions, refusing off-topic requests, masking personal data in answers, validating that output matches a JSON schema, limiting an agent to read-only tools, and requiring a person to approve refunds or deletions.

### Do you need guardrails if the model is already safety-trained?

Yes. Safety training sets the default behavior the provider chose; it knows nothing about your refund limits, your data access rules or which of your tools are high risk. Those rules have to live in your own guardrails.

### Can guardrails stop prompt injection completely?

No. OWASP states it is unclear whether fool-proof prevention exists, so teams combine input checks with least-privilege tools, human approval for high-impact actions and output validation, which limit the damage when an injection gets through.

Services

- [Responsible AI](https://sdclabs.com/services/responsible-ai/)
- [AI agents](https://sdclabs.com/services/ai-agents/)

Read next

- [Can you trust an AI agent inside your product?](https://sdclabs.com/blog/ai-agents-in-products/)
- [How to build AI agents that still work after the demo](https://sdclabs.com/blog/how-to-build-ai-agents/)

Related terms

- [MCP server](https://sdclabs.com/glossary/mcp-server/)

[Sergey Almyashev](https://sdclabs.com/author/almyashev/) Chief Operating Officer14+ years in QA, automated, exploratory and performance testing, and continuous integration and delivery within Scrum, helping teams in product and outsourcing companies organize teams, processes and tools.[LinkedIn](https://www.linkedin.com/in/sergeyalmyashev/)

## Building with AI agents? Talk to an engineer.

[Start a project](https://sdclabs.com/contact/) [Book a call with the CEO](https://calendly.com/sdclabs/60min)
