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
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-length
Example
from 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.

python
from guardrails import Guard

guard = Guard()
result = guard(
    model="groq/openai/gpt-oss-120b",
    messages=[{"role": "user", "content": "Say hello"}],
)
print(result.validated_output)
ProviderKeyVariablemodel=
GroqFree, console.groq.com/keysGROQ_API_KEY"groq/openai/gpt-oss-120b"
GeminiFree, aistudio.google.com/apikeyGEMINI_API_KEY"gemini/gemini-2.5-flash"
OpenRouterFree models end in :free, openrouter.ai/keysOPENROUTER_API_KEY"openrouter/google/gemma-4-31b-it:free"
OpenAIPaid, platform.openai.com/api-keysOPENAI_API_KEY"gpt-4o-mini"
export GROQ_API_KEY=gsk_...
Try it yourself
  • Run pip list and find the packages whose names start with guardrails.

Little by little, you're building something great.