Implementation:Guardrails ai Guardrails Hub Install
| Knowledge Sources | |
|---|---|
| Domains | Package_Management, Validation |
| Last Updated | 2026-02-14 00:00 GMT |
Overview
Concrete function for installing validator packages from the Guardrails Hub provided by the guardrails package.
Description
The install function handles the full lifecycle of downloading and registering a validator package from the Guardrails Hub. It parses the Hub URI, fetches the package manifest, delegates to pip for dependency installation, optionally installs local ML models, and imports/registers the validator module so it becomes available through guardrails.hub.
Usage
Use this function programmatically to install validators at runtime, or invoke it indirectly via the CLI command guardrails hub install hub://guardrails/regex_match.
Code Reference
Source Location
- Repository: guardrails
- File: guardrails/hub/install.py
- Lines: L37-186
Signature
def install(
package_uri: str,
install_local_models=None,
quiet: bool = True,
upgrade: bool = False,
install_local_models_confirm: Callable = default_local_models_confirm,
) -> ValidatorModuleType:
"""Install a validator package from a hub URI.
Args:
package_uri (str): The URI of the package to install.
install_local_models (bool): Whether to install local models or not.
quiet (bool): Whether to suppress output or not.
install_local_models_confirm (Callable): A function to confirm the
installation of local models.
Returns:
ModuleType: The installed validator module.
"""
Import
from guardrails.hub.install import install
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| package_uri | str | Yes | Hub URI e.g. "hub://guardrails/regex_match" with optional version spec |
| install_local_models | Optional[bool] | No | Whether to download ML models locally |
| quiet | bool | No | Suppress output (default True) |
| upgrade | bool | No | Upgrade to latest version (default False) |
| install_local_models_confirm | Callable | No | Confirmation callback for model downloads |
Outputs
| Name | Type | Description |
|---|---|---|
| module | ValidatorModuleType | Installed module with __validator_exports__ attribute containing export names |
Usage Examples
Basic Installation
from guardrails.hub.install import install
# Install a validator and get the module
module = install("hub://guardrails/regex_match")
RegexMatch = module.RegexMatch
# Install with version constraint
module = install("hub://guardrails/regex_match>=1.4")
CLI Installation
# Install from command line
guardrails hub install hub://guardrails/regex_match
# After installation, import in Python
from guardrails.hub import RegexMatch