LLM/agent observability for behavior deviations, guardrails, and telemetry
Project description
detra
LLM/agent observability for behavior deviations, guardrails, and telemetry.
detra traces LLM and agent steps, compares outputs against configured behavior expectations, flags deviations, and ships metrics/events to your telemetry backend. Deterministic checks run first; LLM judges are optional and should be sampled or used with compact evidence.
Install
pip install detra # core only (6 deps)
pip install "detra[litellm]" # + any-model judge
pip install "detra[otel]" # + OpenTelemetry backend
pip install "detra[datadog]" # + Datadog backend
pip install "detra[all]" # everything
Quick Start
import detra
vg = detra.init("detra.yaml")
@vg.trace("refund_policy_agent")
async def answer_refund_question(message: str):
result = await agent.run(message)
return result
# Tracing + deviation checks happen automatically
result = await answer_refund_question("Can I get a refund after 90 days?")
Define Behaviors in YAML
app_name: my-llm-app
judge_config:
provider: none # or: litellm, gemini
model: gpt-4o-mini
sampling:
rate: 0.1
nodes:
refund_policy_agent:
expected_behaviors:
- "Must answer with either eligible, ineligible, or needs_review"
- "Must mention the policy window when denying a refund"
- "Must route to needs_review for missing order dates"
unexpected_behaviors:
- "Approves refunds outside the policy window"
- "Invents policy exceptions"
- "Asks for payment details"
adherence_threshold: 0.90
security_checks:
- pii_detection
- prompt_injection
Pluggable Architecture
Backends -- where telemetry goes:
| Backend | Install | Use case |
|---|---|---|
| Console | included | Local dev, CI |
| OpenTelemetry | detra[otel] |
Prometheus, Jaeger, OTLP |
| Datadog | detra[datadog] |
Datadog LLM Observability |
| Custom | included | Implement the protocol |
Judges -- optional reviewers for sampled or ambiguous behavior checks:
| Judge | Install | Models |
|---|---|---|
| LiteLLM | detra[litellm] |
GPT-4o, Claude, Gemini, Llama, 100+ |
| Gemini | detra[gemini] |
Google Gemini models |
| None | included | Rules-only mode |
Evaluation Pipeline
- Rule checks (fast): empty output, JSON validity, length
- Security scans: PII, prompt injection, sensitive content
- Behavior/deviation checks: expected/unexpected behaviors from YAML spec
- Optional sampled judge: for ambiguous cases or compact evidence
- Flag + alert: when score < threshold or security issues found
Decorator Types
@vg.trace("node") # generic
@vg.workflow("pipeline") # workflow
@vg.llm("model_call") # LLM call
@vg.task("processing") # task
@vg.agent("step") # agent
Works on sync and async functions. Safe inside running event loops (FastAPI, etc.).
Links
License
MIT
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 detra-0.2.0.tar.gz.
File metadata
- Download URL: detra-0.2.0.tar.gz
- Upload date:
- Size: 172.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91511ebb1cbca6fbfad5ea5aae8aa26ff929c5cbc6a48829e634d86f45317198
|
|
| MD5 |
7da8616b5155da612d2d2e68d2b730c7
|
|
| BLAKE2b-256 |
c5f5d71c0b4faf71b67c31c663a63c52d123bc696177776bf856689a22e367e1
|
Provenance
The following attestation bundles were made for detra-0.2.0.tar.gz:
Publisher:
publish-pypi.yml on adc77/detra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
detra-0.2.0.tar.gz -
Subject digest:
91511ebb1cbca6fbfad5ea5aae8aa26ff929c5cbc6a48829e634d86f45317198 - Sigstore transparency entry: 1419421105
- Sigstore integration time:
-
Permalink:
adc77/detra@f49053d03ac145fb6c1f9f4ddf226857710d85c3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adc77
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f49053d03ac145fb6c1f9f4ddf226857710d85c3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file detra-0.2.0-py3-none-any.whl.
File metadata
- Download URL: detra-0.2.0-py3-none-any.whl
- Upload date:
- Size: 112.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d18bff9f5eae7a6e00167eff22bb338b03dee243cb690cb1761d6ae86413bdd
|
|
| MD5 |
c893758b312d499a1a5cc2763dcd5983
|
|
| BLAKE2b-256 |
a4bf32ecd68327f89dd08a40421211f41010e8c66bcfe4a7e0994081b9ea1d50
|
Provenance
The following attestation bundles were made for detra-0.2.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on adc77/detra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
detra-0.2.0-py3-none-any.whl -
Subject digest:
9d18bff9f5eae7a6e00167eff22bb338b03dee243cb690cb1761d6ae86413bdd - Sigstore transparency entry: 1419421270
- Sigstore integration time:
-
Permalink:
adc77/detra@f49053d03ac145fb6c1f9f4ddf226857710d85c3 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/adc77
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@f49053d03ac145fb6c1f9f4ddf226857710d85c3 -
Trigger Event:
push
-
Statement type: