1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
28 small wins to finish your pathNext lesson →
Installation and setup
Guardrails AI and its validators install from PyPI. A Guard that calls a model by name goes through LiteLLM, so a free Groq or Gemini key works.
guardrails-ai and a validator package
Install the library and one validator. Until version 0.11 validators came from a private registry, installed with guardrails hub install and a token you had to sign up for. In 0.11 they became ordinary PyPI packages named guardrails-ai-<name>, installed with pip and imported from the guardrails_ai namespace. Lesson 7 covers the change in full.
pip install "guardrails-ai==0.11.0" guardrails-ai-valid-lengthfrom importlib.metadata import version
print(version("guardrails-ai"))Calling a model by nameOptional
Every lesson up to 23 uses PretendModel, the stand-in from lesson 14, so this section can wait until lesson 24. There, the Guard passes model= to LiteLLM, which reads the provider's key from the environment.
from guardrails import Guard
guard = Guard()
result = guard(
model="groq/openai/gpt-oss-120b",
messages=[{"role": "user", "content": "Say hello"}],
)
print(result.validated_output)| Provider | Key | Variable | model= |
|---|---|---|---|
| Groq | Free, console.groq.com/keys | GROQ_API_KEY | "groq/openai/gpt-oss-120b" |
| Gemini | Free, aistudio.google.com/apikey | GEMINI_API_KEY | "gemini/gemini-2.5-flash" |
| OpenRouter | Free models end in :free, openrouter.ai/keys | OPENROUTER_API_KEY | "openrouter/google/gemma-4-31b-it:free" |
| OpenAI | Paid, platform.openai.com/api-keys | OPENAI_API_KEY | "gpt-4o-mini" |
export GROQ_API_KEY=gsk_...Try it yourself
- Run
pip listand find the packages whose names start withguardrails.
Little by little, you're building something great.