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
Release files for quillai-network-guardrails 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| quillai_network_guardrails-0.1.0.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| quillai_network_guardrails-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / quillai_network_guardrails-0.1.0.tar.gz
| Download URL | quillai_network_guardrails-0.1.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee79cdb251bf04ea7fdc80ce8b813269c9fe17c6d093e23b84b6e60e13d47789
|
|
BLAKE2b-256 checksum How to use checksums |
35075d4bb3a5a76634774480f786c86d6ae2bbc22e228388547ee79384968825
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|
Release files / quillai_network_guardrails-0.1.0-py3-none-any.whl
| Download URL | quillai_network_guardrails-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2fcd4bacc54c09a116b06eb1ca3c1b7aac67c4525bec03eb945b707e4f23b100
|
|
BLAKE2b-256 checksum How to use checksums |
6b0f3b0f1febba232eb9ca3e1b5a04b4f9cbe024e61b8e4608480866f5f50903
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.7
|