DriftRail SDK - AI Safety & Observability Platform for LLM monitoring, guardrails, and compliance
Project description
DriftRail Python SDK
AI Safety & Observability Platform — Monitor, classify, and audit every LLM interaction.
Installation
pip install driftrail
# For async support
pip install driftrail[async]
Quick Start
from driftrail import DriftRail
client = DriftRail(
api_key="dr_live_...",
app_id="my-app"
)
# Log an LLM interaction
response = client.ingest(
model="claude-sonnet-4",
provider="anthropic",
input={"prompt": "What is the capital of France?"},
output={"text": "The capital of France is Paris."}
)
print(f"Event ID: {response.event_id}")
Inline Guardrails
Block dangerous outputs BEFORE they reach users:
from driftrail import DriftRail
client = DriftRail(api_key="...", app_id="my-app")
# Get response from your LLM
llm_response = your_llm_call(user_prompt)
# Guard it before returning to user
result = client.guard(
output=llm_response,
input=user_prompt,
mode="strict" # or "permissive"
)
if result.allowed:
return result.output # May be redacted if PII was found
else:
print(f"Blocked: {[t.reason for t in result.triggered]}")
return "Sorry, I can't help with that."
Guard Modes
strict(default): Blocks on medium+ risk (PII, moderate toxicity, prompt injection)permissive: Only blocks on high risk (severe toxicity, high-risk injection)
Fail-Open vs Fail-Closed
# Fail-open (default): If DriftRail is unavailable, content is allowed through
client = DriftRail(api_key="...", app_id="...", guard_mode="fail_open")
# Fail-closed: If DriftRail is unavailable, raises exception
client = DriftRail(api_key="...", app_id="...", guard_mode="fail_closed")
try:
result = client.guard(output=llm_response)
except GuardBlockedError as e:
print(f"Blocked: {e.result.triggered}")
Async Usage
import asyncio
from driftrail import DriftRailAsync
async def main():
async with DriftRailAsync(api_key="...", app_id="my-app") as client:
response = await client.ingest(
model="claude-3",
provider="anthropic",
input={"prompt": "Hello"},
output={"text": "Hi there!"}
)
asyncio.run(main())
Fire-and-Forget (Non-blocking)
# Won't block your main thread
client.ingest_async(
model="gpt-4o",
provider="openai",
input={"prompt": "..."},
output={"text": "..."}
)
⚠️ Serverless Warning: Do not use
ingest_async()in AWS Lambda, Google Cloud Functions, or other serverless environments. Use the synchronousingest()method instead.
With Metadata
import time
start = time.time()
# ... your LLM call ...
latency = int((time.time() - start) * 1000)
client.ingest(
model="gpt-4o",
provider="openai",
input={"prompt": "..."},
output={"text": "..."},
metadata={
"latency_ms": latency,
"tokens_in": 50,
"tokens_out": 150,
"temperature": 0.7
}
)
With RAG Sources
client.ingest(
model="claude-3.5-haiku",
provider="anthropic",
input={
"prompt": "What does our refund policy say?",
"retrieved_sources": [
{"id": "doc-123", "content": "Refunds are available within 30 days..."},
{"id": "doc-456", "content": "Contact support for refund requests..."}
]
},
output={"text": "According to our policy, refunds are available within 30 days..."}
)
Enterprise Features
from driftrail import DriftRailEnterprise
client = DriftRailEnterprise(api_key="...", app_id="my-app")
# Incident management
stats = client.get_incident_stats()
# Compliance status
compliance = client.get_compliance_status()
# Model leaderboard
leaderboard = client.get_model_leaderboard(metric="avg_risk_score")
# Brand safety checks
violations = client.check_brand_safety("Some AI output text")
Documentation
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 driftrail-2.0.0.tar.gz.
File metadata
- Download URL: driftrail-2.0.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f55f40e7ae702d94fdf6f820384a80bb482dc4efa649f3c16a8b3aa99f7f5d8b
|
|
| MD5 |
81b424365fd496adc8f267b1af9d4b9c
|
|
| BLAKE2b-256 |
8412e473aa05efdc05529e48adebbf26fa8e33fca93d8df15a7ea194072fa581
|
Provenance
The following attestation bundles were made for driftrail-2.0.0.tar.gz:
Publisher:
publish.yml on cutmob/DriftRail-Python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
driftrail-2.0.0.tar.gz -
Subject digest:
f55f40e7ae702d94fdf6f820384a80bb482dc4efa649f3c16a8b3aa99f7f5d8b - Sigstore transparency entry: 919061763
- Sigstore integration time:
-
Permalink:
cutmob/DriftRail-Python@539d90a4c6c362200617758aa260777556bc6231 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/cutmob
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@539d90a4c6c362200617758aa260777556bc6231 -
Trigger Event:
push
-
Statement type:
File details
Details for the file driftrail-2.0.0-py3-none-any.whl.
File metadata
- Download URL: driftrail-2.0.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3b23fbc9ffce65aa61e1f15118fb5847d1716eaab56ba32975f8750854055d5
|
|
| MD5 |
9aa71a0472dd48ecd7c49309551ef68f
|
|
| BLAKE2b-256 |
dc05b147d08242da90c07f275e6e10921e05b21d17ff34f2fe067ad8a5310afa
|
Provenance
The following attestation bundles were made for driftrail-2.0.0-py3-none-any.whl:
Publisher:
publish.yml on cutmob/DriftRail-Python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
driftrail-2.0.0-py3-none-any.whl -
Subject digest:
b3b23fbc9ffce65aa61e1f15118fb5847d1716eaab56ba32975f8750854055d5 - Sigstore transparency entry: 919061768
- Sigstore integration time:
-
Permalink:
cutmob/DriftRail-Python@539d90a4c6c362200617758aa260777556bc6231 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/cutmob
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@539d90a4c6c362200617758aa260777556bc6231 -
Trigger Event:
push
-
Statement type: