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

Uploaded Python 3

File details

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

File metadata

  • Download URL: driftballoon-0.1.0.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for driftballoon-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd4d2a2dc31c72488db5c57f9305d8229e2b4f689c0c31fd561220c62239d939
MD5 85963eeae3d11392c9eeea205ee87126
BLAKE2b-256 598b189fb7d8ec6b7028508dc402acd3bb212024b7bc42baf454f60eb8fe18d4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for driftballoon-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08523311947ffcc2aeb5f5a86abe18710aa479f146fbe9830f4c2a408cac2856
MD5 1c0d7b9a86f233ec5b53ff21b21ddbb4
BLAKE2b-256 1b0fdce0c2d8772b76dc20acff0c55823e408378992acebbb984b8797a3baa8e

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