Skip to main content

Python SDK for DriftBalloon - LLM output drift detection and observability

Project description

DriftBalloon Python SDK

PyPI version Python License: MIT

LLM output drift detection and observability. One line of logging — DriftBalloon stays completely out of your critical path.

Install

pip install driftballoon

Quickstart

from driftballoon import DriftBalloon

db = DriftBalloon(api_key="db_sk_your_key")

# After each LLM call, log the response (fire-and-forget)
response = openai.chat.completions.create(model="gpt-4o", messages=[...])
db.log(
    name="support-agent",
    response=response.choices[0].message.content,
    model="gpt-4o",
).submit()

# Check which prompt version is active ("a" or "b")
active = db.get_active_prompt("support-agent")

Features

  • Fire-and-forget logginglog().submit() is non-blocking; your app never waits on DriftBalloon
  • Semantic drift detection — detects when LLM responses shift meaning or topic
  • Length drift detection — catches abnormally short or long responses
  • Prompt status tracking — check which prompt version is active via get_active_prompt()
  • Multi-model support — track gpt-4o, claude-3-5-sonnet, or any model string
  • Local config cache — prompt configs are cached and synced every 30s
  • Offline resilience — your app keeps working if DriftBalloon is unreachable
  • Retry with backoff — failed log submissions are retried automatically

Environment Variables

export DRIFTBALLOON_API_KEY=db_sk_your_key
import os
from driftballoon import DriftBalloon

db = DriftBalloon(api_key=os.environ["DRIFTBALLOON_API_KEY"])

For self-hosted deployments, set the base URL:

db = DriftBalloon(api_key="db_sk_xxx", base_url="https://driftballoon.your-company.com")

API Reference

DriftBalloon(api_key, base_url=None, sync_interval=30.0, auto_start=True)

Initialize the client. Can be used as a context manager.

log(name, response, prompt=None, model=None) -> LogTask

Log an LLM response. Call .submit() (async, fire-and-forget) or .invoke() (synchronous).

get_active_prompt(name) -> "a" | "b" | None

Get the active prompt version from cached config.

get_config(name) -> PromptConfig | None

Get the full prompt configuration.

get_baseline_status(name) -> (status, count)

Check if the baseline is ready ("learning" or "ready") and how many samples have been collected.

Documentation

Full docs at docs.driftballoon.com.

Local Development

# Setup
make install

# Unit tests (no backend required)
make test

# Integration tests (requires running API)
make test-integration

# Quickstart smoke test
DRIFTBALLOON_API_KEY=db_sk_xxx python examples/quickstart.py

# Cross-venv testing from repo root
make sdk-test-local KEY=db_sk_xxx

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

driftballoon-0.1.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

driftballoon-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file driftballoon-0.1.1.tar.gz.

File metadata

  • Download URL: driftballoon-0.1.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for driftballoon-0.1.1.tar.gz
Algorithm Hash digest
SHA256 742442a8dcf42801238d797b9c5db753f67f8d869d6b8f9197d7d2aac0f32dbf
MD5 28382abeead49b04aa429f4635102ddd
BLAKE2b-256 90cee23adbe62fe36ff363091b78cbd71fdb85c09b5f6b0208fd68b93c3ee526

See more details on using hashes here.

File details

Details for the file driftballoon-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: driftballoon-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for driftballoon-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5bbe20c5e6dd583bd2fe242d775e5f1dd84c2832fe6310f4b540d707449473db
MD5 52b3a8e615747816a888fe1c8cf05103
BLAKE2b-256 f9469644ce156a2308a3d01cde430a010609334251845e80b792564fe79d87fc

See more details on using hashes here.

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