Example
Guardrails AI — implementation sample

A real, runnable mini-project. Download it and run with Docker.

June 28, 2026

Guardrails AI — implementation sample

A tiny Guardrails AI sample: it asks an LLM for JSON, then validates that output against a Pydantic schema — coercing types and enforcing age >= 0 — before you trust it.

Configure

cd samples/guardrails-ai_1
cp .env.sample .env
# edit .env: set OPENAI_API_KEY (used for the LLM call)

Run with Docker

cd samples/guardrails-ai_1
docker build -t aas-guardrails .
docker run --rm --env-file .env aas-guardrails

Run with Docker (in a devcontainer with DooD)

The foreground docker run may print nothing under Docker-outside-of-Docker — run detached and follow the logs:

docker logs -f "$(docker run -d --env-file .env aas-guardrails)"

Run locally

cd samples/guardrails-ai_1
pip install -r requirements.txt
python app.py

Example run

The model returns the JSON (with Rex, dog, 3), and the Guard parses and validates it against the schema. One run with gpt-4o-mini:

validation passed: True
validated output: {'name': 'Rex', 'species': 'dog', 'age': 3}

Files

.env.sample
# Copy to `.env` and add your OpenAI API key (used for the guarded LLM call).
#   cp .env.sample .env
OPENAI_API_KEY=

MODEL=gpt-4o-mini