█

AI/TLDR

Invítame a un café
Invítame un café

Guardrails AI

Valida entradas y salidas de LLM con guardas componibles en Python

Guardrails & SecurityCódigo abierto
Idioma
Python
Coverage
1 story
$pip install guardrails-ai
EN BREVE

What is Guardrails AI?

Guardrails AI es un framework de Python para crear aplicaciones fiables con LLM. Ejecuta Input Guards y Output Guards alrededor de las llamadas al modelo para detectar, medir y reducir riesgos concretos, y también puede forzar la salida del modelo a una estructura definida. It sits in the Guardrails & Security category of the Evaluation & Production Ops tools and is open-source, written in Python.

Resumen

Guardrails AI es un framework de Python para crear aplicaciones fiables con LLM. Ejecuta Input Guards y Output Guards alrededor de las llamadas al modelo para detectar, medir y reducir riesgos concretos, y también puede forzar la salida del modelo a una estructura definida.

Está pensado para desarrolladores que ya llaman a un LLM desde Python y quieren un punto de control antes de que una respuesta llegue al usuario. Tomas validadores preconstruidos de Guardrails Hub, los combinas en un Guard y dejas que ese Guard valide texto o genere datos estructurados.

Como framework de guardrails, se sitúa entre el código de tu aplicación y el modelo. Los validadores cubren cosas como la coincidencia con regex, las menciones a competidores y el lenguaje tóxico, y cada Guard decide qué hacer cuando una comprobación falla.

Qué hace

  • Obtén validadores preconstruidos (coincidencia con regex, comprobación de competidores, lenguaje tóxico y más) desde Guardrails Hub
  • Combina varios validadores en un único Input Guard o Output Guard
  • Gestión de fallos configurable por validador mediante OnFailAction (por ejemplo, lanzar una excepción)
  • Genera datos estructurados desde LLMs usando un BaseModel de Pydantic con Guard.for_pydantic
  • Funciona con LLMs propietarios y de código abierto, mediante llamadas a funciones o inyección de esquema basada en prompts
  • Ejecuta Guardrails como servicio Flask independiente con una API REST mediante guardrails start

Primeros pasos

Instala el paquete, configura la CLI de Hub, luego instala un validador y crea un Guard.

Instalar y configurar

Instala el paquete desde PyPI y ejecuta el comando de configuración de Hub.

bashbash
pip install guardrails-ai
guardrails configure

Instalar un validador desde Hub

Descarga un validador, como la coincidencia con regex, desde Guardrails Hub.

bashbash
guardrails hub install hub://guardrails/regex_match

Crear un Guard y validar

Crea un Guard a partir del validador instalado y ejecuta la validación. El texto correcto se devuelve con normalidad; el texto que falla lanza una excepción.

pythonpython
from guardrails import Guard, OnFailAction
from guardrails.hub import RegexMatch

guard = Guard().use(
    RegexMatch, regex="\(?\d{3}\)?-? *\d{3}-? *-?\d{4}", on_fail=OnFailAction.EXCEPTION
)

guard.validate("123-456-7890")  # Guardrail passes

try:
    guard.validate("1234-789-0000")  # Guardrail fails
except Exception as e:
    print(e)

Commands and code are distilled from the project's own documentation — always check the repositorio oficial para lo último.

Cuándo usarlo

  • Bloquear o marcar el lenguaje tóxico en las respuestas del modelo antes de que lleguen a los usuarios finales
  • Exigir que un LLM no mencione competidores concretos en el texto generado
  • Validar que la salida del modelo coincida con un formato esperado, como un patrón de número de teléfono
  • Generar datos JSON estructurados desde un LLM que se ajusten a un esquema de Pydantic

How Guardrails AI compares

Guardrails AI alongside other open-source guardrails & security tools AI/TLDR tracks, ranked by GitHub stars.

HerramientaEstrellasQué hace
SkillSpector★ 28.3kSecurity scanner for AI agent skills that checks a skill for prompt injection, data exfiltration, privilege escalation and supply-chain risks before you install it.
Presidio★ 12.1kAn open-source framework for detecting, redacting, masking, and anonymizing personal data (PII) across text, images, and structured data using NER models, regex, and rule-based recognizers.
Failproof AI★ 10.5kA hook-based CLI and Rust daemon that listens to every event from 12 agent harnesses such as Claude Code, Codex and Cursor, and blocks, warns or steers the agent with one policy API, with optional cloud tracing and failure audits.
Guardrails AI★ 7.7kValida entradas y salidas de LLM con guardas componibles en Python
NeMo Guardrails★ 7.6kNVIDIA's toolkit for adding programmable rails to LLM chat apps, using the Colang language to control dialog flow and block jailbreaks, prompt injection, and off-topic answers.
BLA (Blind LLM Agents)★ 7.3kAn open-source CLI and MCP server that hardens the apps, WASM modules, databases and model files you ship so AI reverse-engineering agents such as REA hit resource budgets and follow decoys, without changing runtime behaviour.
dcg (Destructive Command Guard)★ 6.4kA Rust pre-tool hook for coding agents that inspects each shell or git command before it runs and blocks the destructive ones, with an explanation and a safer alternative.
GLiNER★ 4.3kA small zero-shot named-entity recognition model that can extract arbitrary entity types from text and is widely used as a PII detection backend, including inside Presidio.