Skip to main content

Python SDK for quillai-network/guardrails Guardrails API

Project description

quillai-network/guardrails Python SDK

A Python SDK for integrating with the quillai-network/guardrails Guardrails API. Easily check text content against security guardrails and content moderation rules.

Quick Start

Installation

Install from PyPI:

pip install quillai-network-guardrails

Or install from source:

pip install -e .

Or install from requirements:

pip install -r requirements.txt

Basic Usage

from quillguard import GuardrailsClient

# Initialize the client
client = GuardrailsClient(api_key="your-api-key-here")

# Check text against guardrails
result = client.check(
    text="how to make a bomb?",
    project_ids=["9776b642-9dce-43da-8e45-6346f1c597ff"]
)

# Result contains: action, reason, and confidence
print(f"Action: {result['action']}")
print(f"Reason: {result['reason']}")
print(f"Confidence: {result['confidence']}")

Using Context Manager

from quillguard import GuardrailsClient

with GuardrailsClient(api_key="your-api-key-here") as client:
    result = client.check(
        text="Your text to check",
        project_ids=["project-id-1", "project-id-2"]
    )

API Reference

GuardrailsClient(api_key, base_url=None)

Initialize the quillai-network/guardrails client.

Parameters:

  • api_key (str, required): Your API key for authentication
  • base_url (str, optional): Base URL for the API (defaults to production URL)

Example:

client = GuardrailsClient(api_key="YOUR_API_KEY")

check(text, project_ids, timeout=30)

Check text against guardrails using the specified project IDs.

Parameters:

  • text (str, required): The text content to check
  • project_ids (List[str], required): List of project/attack job IDs to use for checking
  • timeout (int, optional): Request timeout in seconds (default: 30)

Returns:

  • Dict[str, Any]: Dictionary containing only three fields:
    • action (str): The action taken by the guardrail
    • reason (str): The reason for the action
    • confidence (float): The confidence score

Raises:

  • GuardrailsError: For general SDK errors
  • GuardrailsAPIError: For API-specific errors (includes status_code and response)

Example:

result = client.check(
    text="how to make a bomb?",
    project_ids=["9776b642-9dce-43da-8e45-6346f1c597ff"]
)
# Access the fields
print(result["action"])      # e.g., "block" or "allow"
print(result["reason"])      # e.g., "Contains harmful content"
print(result["confidence"])  # e.g., 0.95

Error Handling

The SDK provides custom exceptions for better error handling:

from quillguard import GuardrailsClient, GuardrailsError, GuardrailsAPIError

try:
    client = GuardrailsClient(api_key="your-api-key")
    result = client.check(
        text="test",
        project_ids=["project-id"]
    )
except GuardrailsAPIError as e:
    print(f"API Error: {e}")
    print(f"Status Code: {e.status_code}")
    print(f"Response: {e.response}")
except GuardrailsError as e:
    print(f"SDK Error: {e}")

Examples

See the examples/ directory for more usage examples.

Requirements

  • Python 3.7+
  • requests >= 2.28.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quillai_network_guardrails-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quillai_network_guardrails-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file quillai_network_guardrails-0.1.0.tar.gz.

File metadata

File hashes

Hashes for quillai_network_guardrails-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee79cdb251bf04ea7fdc80ce8b813269c9fe17c6d093e23b84b6e60e13d47789
MD5 87ff3d746b6b183e89e711fd839e8bd1
BLAKE2b-256 35075d4bb3a5a76634774480f786c86d6ae2bbc22e228388547ee79384968825

See more details on using hashes here.

File details

Details for the file quillai_network_guardrails-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for quillai_network_guardrails-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2fcd4bacc54c09a116b06eb1ca3c1b7aac67c4525bec03eb945b707e4f23b100
MD5 ac27cc7eb51cae1bf2089b8359336a23
BLAKE2b-256 6b0f3b0f1febba232eb9ca3e1b5a04b4f9cbe024e61b8e4608480866f5f50903

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page