Official Driftgard Python SDK — evaluate LLM interactions against your compliance policy
Project description
driftgard
Official Python SDK for Driftgard — evaluate LLM interactions against your compliance policy.
Install
pip install driftgard
Quick start
from driftgard import Driftgard
dg = Driftgard(api_key="your-api-key")
result = dg.evaluate(
project_id="your-project-id",
prompt="What stocks should I buy?",
response="Based on current trends, you should invest in...",
model_id="gpt-4o",
)
if result["evaluation"]["allowed"]:
print("Safe to return to user")
else:
print("Blocked:", result["evaluation"]["violations"])
A/B experiments
Tag evaluations with an experiment_id to compare governance metrics across models:
result = dg.evaluate(
project_id="your-project-id",
prompt="I lost money gambling. Any tips?",
response="You can recover losses by doubling your next bet.",
model_id="gpt-4o",
experiment_id="support-bot-v1", # optional
)
View experiment results on the Experiments page in the Driftgard dashboard.
## Features
- Single `evaluate()` method — send prompt/response, get verdict
- Auto-retry with exponential backoff on 5xx and network errors
- Typed exceptions: `AuthError`, `RateLimitError`, `FeatureNotAvailableError`
- Works with Python 3.8+
## Configuration
```python
dg = Driftgard(
api_key="your-api-key", # required
base_url="https://api.driftgard.com", # optional
timeout=30, # optional, seconds (default 30)
max_retries=2, # optional (default 2)
)
Error handling
from driftgard import Driftgard, AuthError, RateLimitError, FeatureNotAvailableError
try:
result = dg.evaluate(...)
except AuthError:
# Invalid or revoked API key (401)
pass
except RateLimitError:
# Too many requests (429)
pass
except FeatureNotAvailableError as e:
# API evaluate requires Compliance+ tier (403)
print(e.tier)
Requirements
- Python 3.8+
requestslibrary- API key from Driftgard (Settings → API Keys)
- Compliance or Enterprise tier for API evaluation
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 driftgard-1.2.0.tar.gz.
File metadata
- Download URL: driftgard-1.2.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e61713d2adf67467f38cc18090cf91f2feec9c71c9e699926916fdd969045b8c
|
|
| MD5 |
5722abf702a22f115855d8002ef5dbee
|
|
| BLAKE2b-256 |
b84f0261c052eb4773429869648eeed48f0cdcbae18d53048e68426aa2f1e335
|
File details
Details for the file driftgard-1.2.0-py3-none-any.whl.
File metadata
- Download URL: driftgard-1.2.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81df3d3fa9709713467d524ea446537c72bcabe96a00b9106c2348c39b353d81
|
|
| MD5 |
15a76fe4cbc1c51d23ffdd30824d8ac8
|
|
| BLAKE2b-256 |
8b8c0112ea9b5ffe1bf7e732d96477df2aa815fe567333464e546496114ae2c1
|