Install guardrails-ai and initialize a Guard with Guard.from_pydantic(output_class=MySchema) where MySchema is a Pydantic model defining the expected output structure
Add validators like DetectPII, RestrictToTopic, or custom validators by decorating fields with @validator or registering them via guard.use(ValidatorClass)
Wrap LLM calls with guard(llm_api=openai.chat.completions.create, prompt=...) — the Guard will parse, validate, and optionally re-prompt on failure
Configure on_fail behavior per validator: 'reask' triggers a correction prompt, 'fix' applies an automatic transformation, 'exception' raises a ValidationError
Log validation outcomes to Guardrails Hub or a custom endpoint using guard.configure(tracer=...) for monitoring validation failure rates
Known gotchas
Re-ask loops can cascade — set max_reasks on the Guard to prevent infinite retry loops when the model consistently fails to produce valid output
Validators that call external APIs (e.g., PII detection services) add latency to every LLM call; profile validation overhead and consider async validators for high-throughput pipelines
Pydantic v1 and v2 are both supported but require different import paths; mixing them in the same project causes subtle schema parsing failures
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp