Implementation:Guardrails ai Guardrails Create Command Hub
| Knowledge Sources | |
|---|---|
| Domains | Package_Distribution, CLI |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete CLI command for scaffolding Guard configurations from Hub validators provided by the guardrails package.
Description
The guardrails create command (create_command function) installs specified validators from the Hub and generates a config.py file with proper imports, Guard instantiation, and .use() calls. It supports templates for pre-built configurations and a dry-run mode for previewing output. This is an External Tool Doc as it documents a CLI command rather than a programmatic API.
Usage
Run guardrails create --validators "hub://guardrails/regex_match,hub://guardrails/toxic_language" --guard-name MyGuard to generate a config file.
Code Reference
Source Location
- Repository: guardrails
- File: guardrails/cli/create.py
- Lines: L18-104
Signature
@gr_cli.command(name="create")
@trace(name="guardrails-cli/create")
def create_command(
validators: Optional[str] = typer.Option(
default="", help="A comma-separated list of validator hub URIs.",
),
guard_name: Optional[str] = typer.Option(
default=None, help="The name of the guard to define in the file.",
),
local_models: Optional[bool] = typer.Option(
None, "--install-local-models/--no-install-local-models",
),
filepath: str = typer.Option(
default="config.py", help="Output configuration file path.",
),
template: Optional[str] = typer.Option(
default=None, help="Hub template URI for pre-built configurations.",
),
dry_run: bool = typer.Option(
default=False, is_flag=True, help="Preview without writing.",
),
):
Import
# CLI command - invoked via shell:
# guardrails create --validators "hub://guardrails/regex_match"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| validators | Optional[str] | No | Comma-separated Hub URIs |
| guard_name | Optional[str] | No | Name for the generated Guard |
| filepath | str | No | Output path (default "config.py") |
| template | Optional[str] | No | Hub template URI for pre-built configs |
| dry_run | bool | No | Preview without writing (default False) |
Outputs
| Name | Type | Description |
|---|---|---|
| config.py | File | Python file with validator imports, Guard instantiation, and .use() calls |
Usage Examples
Basic Scaffolding
# Generate a config with two validators
guardrails create \
--validators "hub://guardrails/regex_match,hub://guardrails/toxic_language" \
--guard-name ContentGuard
# Preview without writing
guardrails create \
--validators "hub://guardrails/regex_match" \
--dry-run
Using Templates
# Use a pre-built chatbot template
guardrails create --template hub:template://guardrails/chatbot