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.2.1.tar.gz (14.4 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.2.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for driftballoon-0.2.1.tar.gz
Algorithm Hash digest
SHA256 ad490cb8c6a04e18d2e342d7fd6779e16e8b0685d588ed2ce457a4b7d04a7d14
MD5 1f085e7d2e9941efe23995fc25c3b195
BLAKE2b-256 0c2cce4b0d60ace49d05f0ab336b97e8adfd465810a3d833d18db6ec1a963f9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: driftballoon-0.2.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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 069fe61dfb31f9a4599c26bb19cd3c52abe291b9d09ed15758181e824b757684
MD5 d0504cf0f3588f6fb3fe28dca3eb975f
BLAKE2b-256 4e929bca677aefab3e2481492828b1b48d2693cdffeee229f63d4e2a3baaefc3

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