Guardrails Hub Types

0.0.4 · active · verified Fri Apr 17

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and instantiate a `HubManifest` using `guardrails-hub-types`. Since it uses Pydantic, data validation is automatic, and `ValidationError` is raised for malformed input, as shown with the invalid data example.

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}")

view raw JSON →