Metadata-Version: 2.4
Name: quillai-network-guardrails
Version: 0.1.0
Summary: Python SDK for quillai-network/guardrails Guardrails API
Author-email: quillai-network/guardrails <support@quillguard.ai>
License: MIT
Project-URL: Homepage, https://github.com/quillai/quillguard-python
Project-URL: Documentation, https://github.com/quillai/quillguard-python#readme
Project-URL: Repository, https://github.com/quillai/quillguard-python
Project-URL: Issues, https://github.com/quillai/quillguard-python/issues
Keywords: guardrails,security,content-moderation,api,sdk
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: flake8>=5.0.0; extra == "dev"

# 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:

```bash
pip install quillai-network-guardrails
```

Or install from source:

```bash
pip install -e .
```

Or install from requirements:

```bash
pip install -r requirements.txt
```

### Basic Usage

```python
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

```python
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:**
```python
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:**
```python
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:

```python
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

