The QA SDK for AI - Python client for the Canary QA Platform
Project description
canary-sdk
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8093d25e9900ccaf19b11549b7d20cb51013dcc3a909fd82628e90cc8a0e887c
|
|
| MD5 |
346d8f0eab334e12f378d62872967900
|
|
| BLAKE2b-256 |
f34ed5537304180814bc78aa858f9500c2fee8a60244541b41203ec4782d0b31
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a89095bfa78c075f887f07d1ee922bff8ee69bb5e26210570fdea0f1e595cc0e
|
|
| MD5 |
0105ff7e0e9d3cdcc1a93222a80f304f
|
|
| BLAKE2b-256 |
903403e884c563fecd3a21249c542eaff2d096d3818ef891f18402ebf4098f5a
|