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 authenticationbase_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 checkproject_ids(List[str], required): List of project/attack job IDs to use for checkingtimeout(int, optional): Request timeout in seconds (default: 30)
Returns:
Dict[str, Any]: Dictionary containing only three fields:action(str): The action taken by the guardrailreason(str): The reason for the actionconfidence(float): The confidence score
Raises:
GuardrailsError: For general SDK errorsGuardrailsAPIError: 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quillai_network_guardrails-0.1.0.tar.gz.
File metadata
- Download URL: quillai_network_guardrails-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee79cdb251bf04ea7fdc80ce8b813269c9fe17c6d093e23b84b6e60e13d47789
|
|
| MD5 |
87ff3d746b6b183e89e711fd839e8bd1
|
|
| BLAKE2b-256 |
35075d4bb3a5a76634774480f786c86d6ae2bbc22e228388547ee79384968825
|
File details
Details for the file quillai_network_guardrails-0.1.0-py3-none-any.whl.
File metadata
- Download URL: quillai_network_guardrails-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2fcd4bacc54c09a116b06eb1ca3c1b7aac67c4525bec03eb945b707e4f23b100
|
|
| MD5 |
ac27cc7eb51cae1bf2089b8359336a23
|
|
| BLAKE2b-256 |
6b0f3b0f1febba232eb9ca3e1b5a04b4f9cbe024e61b8e4608480866f5f50903
|