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

Uploaded Python 3

File details

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

File metadata

  • Download URL: driftballoon-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f48dfa3975d9a7f9ab707ed5e5565c72257e4c38213500a861512c5e3766b06f
MD5 fdc42ec44992e6dc32939a7b232e13f2
BLAKE2b-256 1946a81de966e4065154a8b660caba7c10508ed5683b78e06d4ce955e1ae5170

See more details on using hashes here.

File details

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

File metadata

  • Download URL: driftballoon-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80249d209bd8e770ee1bee48db05a59ae587245c28e9fe932df3b3e6aa621bbf
MD5 7286021d75263aac1938fa0f2abc37e8
BLAKE2b-256 c9ceaf4a289189feb9a0ea3f33e85375268757254faf07884e1a7d7e046458c5

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