AI guardrails are the checks and limits around an AI system that control what goes in, what comes out and what actions it may take. They sit outside the model, in your application code, retrieval layer, tool layer and monitoring. A well-built system uses several, because no single filter reliably stops every failure.

This guide covers the types of guardrails, how to implement them in order, how agents change the picture, and how to test that they work. It is written for engineers and technical leaders moving a large language model (LLM) application or agent towards production.

Why do AI applications need guardrails?

An LLM produces likely text. It does not know your policies, which data a user may see, or which actions are reversible. Instructions in the system prompt help, but they are requests, not controls: a user, a web page or a document the model reads can push against them.

The OWASP Top 10 for LLM Applications (2025) is a useful map of what goes wrong. The table below matches its risks to the guardrail that addresses each one. The mapping is ours.

OWASP 2025 riskGuardrail to put in place
LLM01 Prompt injectionTreat all external content as data; check permissions at the tool call
LLM02 Sensitive information disclosurePermission-filtered retrieval; redaction before and after the model
LLM03 Supply chainPin and review models, packages and plugins
LLM04 Data and model poisoningControl who can add to training data and knowledge bases
LLM05 Improper output handlingValidate and escape output before any system uses it
LLM06 Excessive agencyLeast privilege, approvals and limits on actions
LLM07 System prompt leakageKeep secrets and authorisation logic out of the prompt
LLM08 Vector and embedding weaknessesTenant isolation and access control in the index
LLM09 MisinformationGrounding, citations and the option to decline
LLM10 Unbounded consumptionRate, token, time and cost limits

For governance, NIST's Generative AI Profile (AI 600-1) extends its AI Risk Management Framework to generative systems.

What are the main types of AI guardrails?

Input guardrails

These run before the model. Validate length and file types, check that the request is in scope, detect personal data you should not process, and flag likely injection attempts. Detection reduces noise, but do not treat a classifier as a security boundary.

Retrieval guardrails

In a RAG application, apply the user's permissions before documents reach the model. If a user cannot open a file in your document system, its text should never enter their context window. Keep sources attached so answers can cite them.

Output guardrails

These run after the model. Enforce a schema, check that claims are supported by the retrieved text, redact sensitive values, and escape anything that will be rendered as HTML or passed to a shell or database. Give the system a clear path to say it does not know.

Action guardrails

These matter most for agents. Every tool call should pass through code that checks who is asking, whether this action is allowed on this resource, and whether it needs approval. The model proposes; your code decides.

Operational guardrails

Set limits on tokens, time, steps, retries and spend per task. Log prompts, retrieved passages, tool calls and decisions with care for personal data. Add alerts and a switch that stops the system quickly.

How do you implement AI guardrails step by step?

  1. Write down the harm. List what the system must never do, such as reveal another customer's data or issue a refund without approval.
  2. Rank by impact and reversibility. Reading a public page is low risk. Sending money, deleting records or emailing a customer is not.
  3. Choose the cheapest reliable control for each. Prefer deterministic code (permissions, schemas, allow-lists) over another model call where you can.
  4. Put human approval on irreversible actions. Show the person exactly what will happen, not a summary of it.
  5. Fail safely. Decide what happens when a check errors or times out. For high-risk actions, block.
  6. Build an evaluation set. Include normal requests, edge cases and attacks.
  7. Monitor and review. Feed real incidents and false blocks back into the set.

A minimal example

This Python sketch shows the idea of deciding at the tool call rather than in the prompt. It is illustrative and needs your own authorisation and storage.

APPROVAL_REQUIRED = {"issue_refund", "delete_record", "send_email"}

def run_tool(user, name, args, approved=False):
    if name not in user.allowed_tools:
        return {"status": "denied", "reason": "tool not permitted"}
    if not can_access(user, name, args):
        return {"status": "denied", "reason": "resource not permitted"}
    if name in APPROVAL_REQUIRED and not approved:
        return {"status": "pending", "preview": describe(name, args)}
    result = TOOLS[name](**validate(name, args))
    audit_log(user.id, name, args, result)
    return {"status": "ok", "result": result}

Even if an injected instruction convinces the model to call issue_refund, the call stops until a person approves it.

How are guardrails different for AI agents?

A chatbot can say something wrong. An agent can do something wrong. OWASP calls the underlying problem excessive agency: too much functionality, too many permissions or too much autonomy.

For agents, add these:

  • Least privilege per task. Give the agent the tools this job needs, not every tool you have.
  • Separate reading from acting. Content from emails, web pages and tickets can inform the agent, but it must not grant new permissions.
  • Step and budget limits. Stop loops that repeat the same action or burn tokens without progress.
  • Checks on tool servers. If you use the Model Context Protocol (MCP), review what each server exposes. Our paper MCP Guardian describes a security layer for MCP-based systems, and the MCP server directory shows which hosted servers answer and how many tools they list.
  • Compact, inspectable state. Good context engineering makes it easier to see why an agent acted.

How do you test guardrails?

Test guardrails like any other part of the system, with numbers you track over time.

MeasureWhat it tells you
Attack success rateHow often a bad request gets through
False block rateHow often a legitimate request is stopped
Unsupported claim rateHow often answers go beyond the sources
Unauthorised action rateHow often an action runs without permission; target zero
Added latency and costWhat the checks cost the user

Include indirect prompt injection, where the attack is hidden in a document or page the system reads. Re-run the set when you change the model, prompt, tools or retrieval.

What are the limits of AI guardrails?

  • No filter is complete. Assume some injections succeed and limit what they can do.
  • More checks add latency. Run inexpensive ones first and reserve model-based checks for higher risk.
  • Over-blocking drives people away. Users who are refused too often go around the system.
  • Guardrails do not replace governance. Someone must own the policy, the incidents and the decision to stop.

Where AI Anytime can help

We design guardrails, evaluations and approval flows as part of Agentic AI Solutions, and run architecture and security reviews through AI consulting. Enterprise AI Suite applies the same principle: agents update business records only with your approval.

Frequently asked questions

What are AI guardrails?

AI guardrails are controls around an AI system that check inputs, limit what data it can see, validate outputs, restrict actions and monitor behaviour in production.

What is an example of an AI guardrail?

Requiring a person to approve a refund before an agent can issue it. The rule is enforced in code at the tool call, so a manipulated prompt cannot bypass it.

Can guardrails stop prompt injection completely?

No known control stops every prompt injection. Reduce exposure by treating external content as untrusted, and limit the damage with permissions, approvals and monitoring.

Are guardrails the same as a system prompt?

No. A system prompt asks the model to behave a certain way. Guardrails are enforced outside the model, so they still apply when the model is wrong or manipulated.

Where should a team start with AI guardrails?

Start with the actions and data that could cause the most harm. Add permission checks, approval for irreversible actions, output validation and logging before adding model-based filters.