How work4ai/guardrails works
Project type and purpose
• Project type: A Python framework/library with a CLI and optional Flask-based server component.
• Purpose:
– Provide “Guardrails” (validation layers) around LLM calls to detect and mitigate risks (via input/output validators).
– Enable generation of structured data from LLMs (via Pydantic schemas or function-calling).
– Offer a standalone server mode (Flask) for remote guardrail validation via REST.
– Include a plugin-style “Hub” for pre-built validators and support custom validators.
File structure
– Top-level:
• guardrails/ ← core library package
• server_ci/ ← Docker + config for the Flask server
• docs/ + docusaurus/ ← documentation site
• tests/ ← unit and integration tests
• CLI entrypoints: Makefile, package.json (JS wrappers), pyproject.toml
– Within guardrails/:
• cli/ ← Typer/Click-based commands (configure, hub install, start server, validate)
• api_client.py ← abstraction over LLM API calls
• run/ ← sync, async, streaming runners that orchestrate LLM + validation
• prompt/ ← prompt builders & templates
• schema/ ← rail schema parser, Pydantic schema generator
• validator_service/ ← sync/async validator orchestration
• hub/ & hub_telemetry/← integration with remote Hub service for validator packages
• integrations/ ← adapters for LangChain, LlamaIndex, Databricks, FAISS vectordb
• telemetry/ & call_tracing/ ← OpenTelemetry & custom tracing handlers
• document_store.py ← persistence for prompt & validation history
• vectordb/ ← local vector store (FAISS) for retrieval-based validators
• types/, classes/, utils/ ← core data types, history & log classes, helper utilities
Insights from README
– Describes two workflows:
a) Running local Guards in Python (Guard().use(...).validate(...))
b) Running a standalone Guardrails Server (Flask + REST) for remote calls
– Mentions two modes of structured-data output: function calling vs prompt optimization
– Illustrates Hub CLI usage: install validators, create Guards