Skip to main content

The QA SDK for AI - Python client for the Canary QA Platform

Project description

canary-sdk

Canary MIT License PyPI

The QA Platform for AI. Monitor your AI application's output quality in real-time. Know before your users do.

Quick Start

pip install canary-sdk
import canary_sdk

canary_sdk.init(api_key="cny_live_sk_...")

# Wrap any AI call — 3 lines total
result = canary_sdk.capture(
    ai_input="What is the ICD-10 code for Type 2 Diabetes?",
    ai_output="E11.9",
    model="gpt-4o",
    feature="diagnosis_check",
)

Get your API key at canaryqa.ai.

How It Works

graph LR
    A[Your AI App] -->|canary_sdk.capture| B[Canary SDK]
    B -->|async batch<br/>fire-and-forget| C[Canary API]
    C -->|Inngest event| D[Evaluators<br/>accuracy · hallucination · performance]
    D --> E[Quality Scores]
    E --> F[Dashboard & Alerts]

The SDK adds zero latency to your AI calls. Traces are buffered and flushed in a background thread (batch of 25 or every 5 seconds). If the SDK encounters any error, your application continues running uninterrupted.

Integration Patterns

Pattern 1: Direct Capture

Wrap any function call manually — works with any LLM provider:

import canary_sdk

canary_sdk.init(api_key="cny_live_sk_...")

# Call your LLM as usual
response = my_llm_call(prompt)

# Then capture the trace
canary_sdk.capture(
    ai_input=prompt,
    ai_output=response,
    model="gpt-4o",
    feature="diagnosis_check",
)

Pattern 2: Decorator

Automatically capture inputs and outputs of a function — zero boilerplate:

from canary_sdk import Canary

canary = Canary(api_key="cny_live_sk_...")

@canary.trace(feature="diagnosis_check")
def check_diagnosis(patient_note: str) -> str:
    return llm.generate(patient_note)

# Traces are captured automatically — just call your function normally
result = check_diagnosis("Patient presents with polyuria and polydipsia...")

Pattern 3: LiteLLM Callback

Instrument all LiteLLM calls automatically — one registration captures everything:

import litellm
import canary_sdk

canary_sdk.init(api_key="cny_live_sk_...")
litellm.callbacks = [canary_sdk.callback()]

# Tag each call with a feature name via metadata
response = await litellm.acompletion(
    model="gpt-4o",
    messages=[{"role": "user", "content": prompt}],
    metadata={"feature_tag": "diagnosis_check"},
)
# Trace is automatically captured — no extra code needed

PHI Redaction

PHI redaction via Microsoft Presidio is enabled by default. Patient names, dates, SSNs, and other identifiers are redacted before data leaves your application.

# PHI redaction ON by default — safe for healthcare AI
canary_sdk.init(api_key="cny_live_sk_...")

# Opt out for non-healthcare applications
canary_sdk.init(api_key="cny_live_sk_...", redact_phi=False)

Healthcare terms are preserved: drug names, disease names, ICD-10 codes, and clinical terminology are not redacted.

Feature Tags

Feature tags let you track quality separately for each AI capability in your dashboard:

# Good — specific feature tags give you per-feature quality trends
metadata={"feature_tag": "diagnosis_check"}
metadata={"feature_tag": "icd10_lookup"}
metadata={"feature_tag": "risk_adjustment"}
metadata={"feature_tag": "prior_auth_review"}

# Also valid — no tag (traces aggregated under org level)
# (omit metadata kwarg)

Configuration

Parameter Default Description
api_key required Your Canary API key (cny_live_ or cny_test_)
redact_phi True Enable Microsoft Presidio PHI redaction
batch_size 25 Traces per batch flush
flush_interval 5.0 Seconds between automatic flushes
api_url https://api.canaryqa.ai Canary API base URL

Dashboard

View quality scores, failure drill-downs, and configure threshold alerts at app.canaryqa.ai.

The dashboard shows:

  • Quality score per feature — composite of accuracy, hallucination, and performance scores
  • Failure drill-down — 3-panel diff view: input, AI output with errors highlighted, expected output
  • Trend charts — quality over time, per model and per feature
  • Alert configuration — set thresholds, Slack/email destinations

License

MIT — see LICENSE.

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

canary_sdk-1.0.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

canary_sdk-1.0.0-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file canary_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: canary_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for canary_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8093d25e9900ccaf19b11549b7d20cb51013dcc3a909fd82628e90cc8a0e887c
MD5 346d8f0eab334e12f378d62872967900
BLAKE2b-256 f34ed5537304180814bc78aa858f9500c2fee8a60244541b41203ec4782d0b31

See more details on using hashes here.

File details

Details for the file canary_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: canary_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for canary_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a89095bfa78c075f887f07d1ee922bff8ee69bb5e26210570fdea0f1e595cc0e
MD5 0105ff7e0e9d3cdcc1a93222a80f304f
BLAKE2b-256 903403e884c563fecd3a21249c542eaff2d096d3818ef891f18402ebf4098f5a

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