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
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
| Piece | What it does | Lesson |
|---|---|---|
| A Guard | Holds the rules and runs them | 2 |
| The validators on PyPI | Ten checks that need no model | 6 |
| Your own validator | The rule that is specific to your shop | 8 |
| on_fail actions | Reject, repair, refuse, or ask again | 9 to 12 |
| A stand-in model | Something for the Guard to wrap, with no key | 13 |
| An input guard | Stops a bad question before it costs money | 15 |
| Structured output | A support ticket, not a paragraph | 17 to 20 |
| The support desk | Everything together, and how it fails | 24 |
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.
- Read the table above and pick the row you most want. That is the lesson to look forward to.
- Change
max=40tomax=200and 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.
Every expert started right here.