Guardrails AI ensures LLM outputs meet quality and safety constraints through validators and automatic correction loops. These exercises cover the Guard object, on_fail action types (reask/fix/throw), RAIL XML specification format, and finding validators via the Guardrails Hub.
0 / 5 completed
1 / 5
What is the primary purpose of the Guardrails AI library?
Guardrails AI provides a framework for defining validation rules (validators) on LLM outputs and automatically retrying or correcting outputs that fail validation. It wraps LLM calls with a validation loop, ensuring outputs meet structural and semantic requirements before being returned to the application.
2 / 5
In Guardrails AI, what is a Guard object?
A Guard is Guardrails AI's central object that combines validators, the LLM call, and the validation loop. You call guard(llm_api, prompt=...) and Guard handles calling the LLM, running validators on the output, and retrying with correction instructions if validation fails.
3 / 5
A developer defines a Guardrails validator with on_fail='reask'. What happens when validation fails?
The reask on_fail action causes Guardrails to construct a new prompt that includes the original prompt, the failed output, and a description of what validation failed. This correction prompt is sent back to the LLM, giving it a chance to fix the specific issue. This loop continues up to num_reasks times.
4 / 5
What is the RAIL specification in Guardrails AI?
RAIL (Reliable AI Language) is Guardrails AI's XML-based specification format for declaring the expected output structure, types, and validators. A RAIL spec defines an <output> element with nested field elements that have validators attributes. It's an alternative to the Python-based Guard API for declarative configuration.
5 / 5
Which Guardrails AI validator would a developer use to ensure a generated string does not contain profanity?
The Guardrails Hub hosts community validators including ToxicLanguage for detecting toxic or profane content. Validators are installed via guardrails hub install hub://guardrails/toxic_language and then referenced in Guard definitions. The Hub model separates core functionality from specialized validators.