Guardrails Hub Types
Guardrails Hub Types provides Pydantic models and type definitions used across the Guardrails Hub ecosystem. It encapsulates data structures for hub manifests, workflows, and other configuration, ensuring consistency and validation. Currently at version 0.0.4, it is part of a rapidly evolving project, with frequent updates likely as Guardrails Hub matures.
Common errors
-
ModuleNotFoundError: No module named 'guardrails_hub_types.HubManifest'
cause Attempting to import a type directly from the top-level package instead of its specific submodule.fixThe types are organized into `models` submodules. Correct the import path to `from guardrails_hub_types.models.hub import HubManifest` (or `models.workflow`, etc.). -
pydantic.error_wrappers.ValidationError: 1 validation error for HubManifest\nname\n field required (type=value_error.missing)
cause Attempting to instantiate a Pydantic model with missing or incorrectly typed required fields.fixReview the schema for the specific type (e.g., `HubManifest`) to ensure all required fields are present and correctly formatted according to their defined types. Refer to the model's source code or generated schema for details.
Warnings
- gotcha This library is version 0.0.x and is subject to rapid change. The API may not be stable and breaking changes are highly likely in future minor versions (e.g., 0.1.0, 0.2.0) before a 1.0.0 release.
- gotcha As a types-only library, `guardrails-hub-types` provides Pydantic models for data validation and structure, but does not contain any runtime logic or execution capabilities. It is intended for schema definition and validation.
- breaking The internal structure of the `models` submodules might change, leading to `ModuleNotFoundError` if you import directly from paths like `guardrails_hub_types.hub` instead of `guardrails_hub_types.models.hub`.
Install
-
pip install guardrails-hub-types
Imports
- HubManifest
from guardrails_hub_types import HubManifest
from guardrails_hub_types.models.hub import HubManifest
- WorkflowManifest
from guardrails_hub_types.workflow import WorkflowManifest
from guardrails_hub_types.models.workflow import WorkflowManifest
Quickstart
from guardrails_hub_types.models.hub import HubManifest
from pydantic import ValidationError
# Example of creating a HubManifest instance
hub_data = {
"name": "my-hub-rail",
"version": "0.1.0",
"description": "A simple rail for demonstration.",
"authors": ["John Doe <john.doe@example.com>"],
"tags": ["demo", "llm"],
"docs_url": "https://example.com/docs",
"config": {"type": "llm_rail"},
"inputs": {"prompt": {"type": "string"}},
"outputs": {"result": {"type": "string"}}
}
try:
manifest = HubManifest(**hub_data)
print("HubManifest created successfully!")
print(f"Manifest Name: {manifest.name}")
print(f"Manifest Version: {manifest.version}")
except ValidationError as e:
print(f"Validation Error: {e}")
# Example of invalid data (missing required field 'name')
invalid_hub_data = {
"version": "0.1.0",
"description": "Missing name."
}
try:
invalid_manifest = HubManifest(**invalid_hub_data)
except ValidationError as e:
print(f"\nFailed to create invalid manifest as expected: {e}")