Guardrails AI: Python validators and RAG setup
Learn to build Guardrails AI validators in Python, mask a blocked word, enforce a 30-word limit, and add input and output checks to a RAG app.
Player not loading? Watch on YouTube
This Python tutorial introduces Guardrails AI through custom validators and a support-focused RAG application. The speaker describes guardrails as checks before a request reaches an LLM and after it returns an answer. Input checks target off-topic questions and prompt injection; output checks examine the generated response before the user receives it.
The walkthrough starts with a package import in a virtual environment, then explains validator registration, pass and fail results, and failure actions. A basic validator checks lowercased text for the word "stupid". A later example supplies a repair value that replaces the word with asterisks. The speaker tests the validation status and corrected output, then combines that check with a short-answer validator intended to limit text to 30 words.
The RAG example adds allowed support topics and checks for selected jailbreak phrases. An output validator uses context supplied through metadata to look for words absent from the retrieved text. These examples demonstrate specific text checks; they do not establish comprehensive protection against prompt injection or unsupported answers.
The speaker also contrasts rule enforcement with observability and points to the Hub for reusable validators. The RAG example uses a hosted model API alongside the Python validation code.