← All sessions, cheat sheets & labs
Week 4 · Field guide · Output validation

Guardrails AI

A framework that validates and repairs model output against declared rules, built from composable validators.

output validatorsopen sourcePython + JSvalidators hub

What it is

Composable validators with repair.

Guardrails AI is a framework for input and output guardrails assembled from small, composable validators: structure, PII, toxicity, competitor mentions, and many more. When a validator fails, the framework can re-ask the model or fix the output rather than simply erroring. A validators hub ships prebuilt checks you can drop in, so most common rules are a line of configuration rather than new code.

The one job

Validate and repair the output.

It sits after the model and enforces your rules on what came back: the shape is right, no PII leaked, nothing toxic, no competitor named. Where it can, it repairs the output to pass rather than dropping it, so the contract is met before the value moves on.

Reach for it when

Skip it when

A minimal look

Run validators over the output.

import { Guard } from "@guardrails-ai/core";

// declare the rules once; each validator can fix or re-ask on failure
const guard = await Guard()
  .use(NoPII, { onFail: "fix" })
  .use(NoCompetitors, { onFail: "reask" });

const { validatedOutput } = await guard.validate(modelOutput);
// validatedOutput is now safe to return to the caller
return validatedOutput;

The principle it teaches

Course principle

Never return unvalidated output. This is the output side of the Sessions 1-2 boundary, with repair added: the model may draft, but a declared contract decides what actually leaves your system.

Where it fits your labs

This spans Week 4 and Week 1. It is the output guardrail in Lab 4, and the same validator idea backs the validation work from Week 1 where a value has to pass a schema before you trust it.

Use in
Lab 4 output guardrails, and Week 1 validation where output must pass a contract.
weeks 4 + 1
Pairs with
The course's extract() (Zod) for structure, and Lakera for injection detection.