Guardrails AIguardrails-ai 0.11.0 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
27 small wins to finish your pathNext lesson

What you are going to build

Guardrails AI is a Python library that puts a check between a language model and whatever reads its answer. The check can reject the answer, repair it, or send it back to the model to try again. This course builds a guarded support desk for an online shop, and every lesson runs on your machine with no API key and no model download.

A model that is usually right is still a problem. The shop's support desk must never promise a refund, must fit a message gateway that cuts off at forty characters, and must never mention a competitor. Guardrails is the place those three rules live, and the place the failures get recorded.

A checked answer, working

Example
from guardrails import Guard
from guardrails_ai.valid_length import ValidLength
from pretend_guardrails import PretendModel

desk = Guard().use(ValidLength(min=1, max=40, on_fail="noop"))
answer = desk(PretendModel(), messages=[{"role": "user", "content": "Where is order 8821?"}])

print(answer.validation_passed, "|", answer.validated_output)
for summary in answer.validation_summaries:
    print(summary.validator_name, "-", summary.failure_reason)

A model was asked a question, it answered, a rule looked at the answer and the rule said no. Nobody wrote a web request and nobody called an API.

PretendModel is about thirty lines of Python that you write in lesson 13. Guardrails talks to a model through a callable, and a callable is cheap to fake, which is what makes the whole course free to run.

No key, and no downloads either

Other Guardrails courses exist and every one of them needs something. The official short course needs an OpenAI key by its fourth video. The most cited written tutorial downloads a toxicity model of several hundred megabytes. This course needs pip install guardrails-ai and nothing else, because ten of the validators on PyPI are plain Python and the model is a function.

Lesson 23 shows the one line that swaps in a real model, and says plainly what changes when you do.

What you will have built

PieceWhat it doesLesson
A GuardHolds the rules and runs them2
The validators on PyPITen checks that need no model6
Your own validatorThe rule that is specific to your shop8
on_fail actionsReject, repair, refuse, or ask again9 to 12
A stand-in modelSomething for the Guard to wrap, with no key13
An input guardStops a bad question before it costs money15
Structured outputA support ticket, not a paragraph17 to 20
The support deskEverything together, and how it fails24
Where the course goes
The piecesReading itWith a modelReal workGuardrails AI

What you need

  • Python 3.10 or newer.
  • pip install guardrails-ai, plus a few validator packages that lesson 6 lists.
  • No account, no key, no card, no Docker, no model downloads.
Try it yourself
  • Read the table above and pick the row you most want. That is the lesson to look forward to.
  • Change max=40 to max=200 and run it again. The verdict flips and the loop prints nothing.
  • Change the question to "Can I get a refund on order 8821?" and read the answer the stand-in gives.
Back toAll frameworks

Every expert started right here.