Skip to main content

DriftRail SDK - AI Safety & Observability Platform for LLM monitoring, guardrails, and compliance

Project description

DriftRail Python SDK

PyPI version Python 3.8+ License: MIT

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 synchronous ingest() 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

driftrail-2.0.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

driftrail-2.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

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

Hashes for driftrail-2.0.0.tar.gz
Algorithm Hash digest
SHA256 f55f40e7ae702d94fdf6f820384a80bb482dc4efa649f3c16a8b3aa99f7f5d8b
MD5 81b424365fd496adc8f267b1af9d4b9c
BLAKE2b-256 8412e473aa05efdc05529e48adebbf26fa8e33fca93d8df15a7ea194072fa581

See more details on using hashes here.

Provenance

The following attestation bundles were made for driftrail-2.0.0.tar.gz:

Publisher: publish.yml on cutmob/DriftRail-Python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for driftrail-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3b23fbc9ffce65aa61e1f15118fb5847d1716eaab56ba32975f8750854055d5
MD5 9aa71a0472dd48ecd7c49309551ef68f
BLAKE2b-256 dc05b147d08242da90c07f275e6e10921e05b21d17ff34f2fe067ad8a5310afa

See more details on using hashes here.

Provenance

The following attestation bundles were made for driftrail-2.0.0-py3-none-any.whl:

Publisher: publish.yml on cutmob/DriftRail-Python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page