TOOL WIKI · SECURITY & IDENTITY

Guardrails AI

Applies validators and checks to data entering or leaving an LLM application.

Download example files Code + setup + checks in a ZIP
Jump to a section 10 sections

EXAMPLE USE CASE

Reject a malformed generated order object

An agent application needs independently enforced input, identity, data or action checks before exposing a protected capability.

Input
A JSON response and an OrderResult Pydantic contract.
Expected output
Validated fields or a failed validation outcome.
  • Success check: The known JSON validates without a model call.
  • Try a failure: Change status to invented and require rejection.

Example scope: Actual local schema validation with reasks disabled; it does not prove the values are factually correct.

Official reference · Guardrails AI

WHAT IT ISValidation framework
WHERE IT FITSSecurity & identity
SEE HOW THE SYSTEM FITS TOGETHERSELECT A COMPONENT
inputprocessresultcheckoutputRequest or workloadVerified application inputGuardrails AIValidation frameworkApplicationenforcementInterpret and enforceAllowed operationScoped service callAuthoritative outcomeSuccess or explicit errorAudit + reviewEvidence of the decision
  1. Identify the actor, operation, resource, and relevant evidence.

  2. Enforcing a defined set of output or input requirements. A validation result must be connected to an explicit application decision.

  3. Consume the identity, policy result, credential, or detection from this component. Fail according to an explicit application policy.

  4. The business service still checks permission for the actual target resource.

  5. Record the result without leaking unnecessary credentials or sensitive content.

  6. Retain actor, policy version, operation identifier, and result with deliberate redaction.

    Result or stopping point
Guardrails AI

Enforcing a defined set of output or input requirements. A validation result must be connected to an explicit application decision.

Follow the arrows, then select a component to inspect its responsibility. On mobile, downward arrows connect the next step; bent arrows identify branches and return paths. Select a destination to jump to that component.

When to consider it

  • Enforcing a defined set of output or input requirements.

A design decision to make

  • A validation result must be connected to an explicit application decision.

Prerequisites and setup

  • Use an isolated test environment and synthetic data. Keep provider keys and real secrets out of test fixtures.
Shell
python3 -m venv .venv
source .venv/bin/activate
pip install guardrails-ai pydantic

Try a small integration

validate.py

Python · validate.py
from typing import Literal
from pydantic import BaseModel
from guardrails import Guard

class OrderResult(BaseModel):
    order_id: str
    status: Literal["packed", "shipped", "not_found"]

guard = Guard.for_pydantic(output_class=OrderResult)
result = guard.parse(llm_output='{"order_id":"A104","status":"packed"}', num_reasks=0)
print("Passed:", result.validation_passed)
print(result.validated_output)

Run and check the result

Shell
python validate.py
  • The known JSON validates without a model call.
  • Change status to invented: validation must fail or raise an error; the application must reject that output.

Common failures

  • Do not continue a protected operation when the policy response is missing, invalid or unavailable.
  • A successful test on one fixture is not a complete security evaluation; include bypass attempts and legitimate requests.

Production decisions

  • Enforce decisions in application/service code before an operation. A detector score or valid schema is not user authorization.
  • Test allowed, denied, malformed, timeout and unavailable outcomes; record redacted decision reasons and default to a safe failure state.
  • Apply separate resource authorization and factual checks after output validation. Configure validator/reask behavior and usage ceilings explicitly.

Keep exploring

A human approval boundary for agent actionsA governed tool layer with MCP

Explore the same layer

NeMo GuardrailsLlama GuardPresidioLakera

Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.