Ultralytics YOLO27:
License YOLO
Back to Ultralytics Glossary

AI Guardrails

AI guardrails are checks around an AI model that block unsafe inputs, outputs, and actions, from prompt injection filters to schema checks on tool calls.

AI guardrails are checks placed around an artificial intelligence (AI) model that inspect what goes into it, what comes out of it, and what actions it is allowed to take, blocking or rerouting anything that violates a policy. They sit outside the model's weights: a guardrail can stop a harmful answer, a leaked phone number, or an unauthorized refund even when the underlying large language model (LLM) has been tricked into producing it. Guardrails complement safety training such as reinforcement learning from human feedback (RLHF) by enforcing limits on the whole application, whatever the model itself tends to do.

Types of AI Guardrails#

Guardrails are grouped by where they act. Input guardrails screen prompts, uploaded files, and retrieved documents before the model sees them, looking for prompt injection, jailbreak attempts, personal data, or off-topic requests. Output guardrails check responses before they reach the user or downstream software, for harmful content, leaked secrets, hallucinations that contradict source documents, or structured outputs that break a required schema.

Action guardrails limit which tools an AI agent can call, with what arguments and permissions, and require human approval for consequential steps such as payments, deletions, or sending email; agent sandboxing isolates any code the agent runs. Dialog guardrails keep a conversation on approved topics, such as a banking assistant that declines medical questions.

How Guardrails Are Implemented#

Many guardrails are classifiers. Meta's Llama Guard, introduced in 2023, is an LLM fine-tuned to label both prompts and responses as safe or unsafe against a taxonomy of risk categories. Anthropic's Constitutional Classifiers, trained on synthetic data generated from a written list of allowed and disallowed content, cut the success rate of 10,000 automated jailbreak attempts from 86% to 4.4% on Claude 3.5 Sonnet, while raising refusals on production traffic by 0.38% and adding 23.7% compute overhead. Other guardrails are rules: regular expressions for credit card numbers, allowlists of tools, and schemas for tool arguments. Frameworks such as NVIDIA's NeMo Guardrails and Guardrails AI combine both kinds into configurable pipelines.

Schema validation is the simplest action guardrail to build. The example below uses Pydantic to check refund requests that an LLM agent proposes before any of them executes:

from pydantic import BaseModel, Field, ValidationError


class Refund(BaseModel):
    """Refund action a support agent may request."""

    order_id: str = Field(pattern=r"^A\d{6}$")
    amount: float = Field(gt=0, le=200)  # larger refunds go to a human


# Two tool calls proposed by an LLM; the second follows instructions injected into a customer email
proposals = ['{"order_id": "A104233", "amount": 49.99}', '{"order_id": "A104233", "amount": 5000}']

# Action guardrail: execute only tool calls that pass the schema, block the rest
for proposal in proposals:
    try:
        refund = Refund.model_validate_json(proposal)
        print(f"Executed refund of ${refund.amount} for {refund.order_id}")
    except ValidationError as error:
        print(f"Blocked: {error.errors()[0]['msg']}")

The first call prints Executed refund of $49.99 for A104233, and the second prints Blocked: Input should be less than or equal to 200, so the injected instruction never reaches the payment system no matter how convincingly it was phrased.

Guardrails in Vision Pipelines#

Vision systems use guardrails to decide when a model's output is trustworthy enough to act on. In Ultralytics Platform Agents, a Gate block controls downstream execution with a condition on YOLO26 results: the YOLO to VLM Monitor template runs a vision-language model only when at least one person is detected. Medical imaging and autonomous vehicles apply the same pattern, routing uncertain findings to clinicians and falling back to a safe stop when perception fails.

  • AI safety: The broad field of preventing AI harm. Guardrails are one of its deployment-time tools.
  • Constitutional AI: Trains principles into the model itself. Guardrails enforce rules from outside, so they still work when training fails.
  • AI governance: The policies and laws that decide what an AI system may do. Guardrails are the technical controls that enforce those decisions at runtime.
  • AI red teaming: Attacks a system to find the gaps its guardrails leave open.

Guardrails also cost speed and helpfulness: every classifier adds inference latency, and a stricter one refuses more legitimate requests. Anthropic's prototype Constitutional Classifiers withstood more than 3,000 hours of bug-bounty red teaming without a universal jailbreak, yet refused too many harmless queries and needed too much compute.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning