Skip to main content

End-to-end LLM observability for vertical AI applications with Datadog

Project description

detra

End-to-end LLM Observability for Vertical AI Applications with Datadog Integration

detra is a comprehensive Python framework for monitoring, evaluating, and securing LLM applications. It provides automatic tracing, Gemini-powered evaluation, security scanning, alerting, and full integration with Datadog's LLM Observability platform.

Features

  • Automatic Tracing: Decorator-based tracing that captures inputs, outputs, and metadata
  • LLM Evaluation: Gemini-powered evaluation to check adherence to expected behaviors
  • Security Scanning: Detection of PII, prompt injection, and sensitive content
  • Alerting: Integration with Slack, PagerDuty, and custom webhooks
  • Datadog Integration: Full integration with Datadog LLM Observability, metrics, events, monitors, and dashboards
  • Incident Management: Automatic incident creation for critical issues

Installation

pip install detra

# With optional dependencies
pip install detra[server]      # FastAPI/uvicorn support
pip install detra[dev]        # Development tools
pip install detra[optimization]  # DSPy optimization
pip install detra[all]        # All optional dependencies

Quick Start

1. Install and Configure

# Install
pip install detra

# Set environment variables
export DD_API_KEY=your_datadog_api_key
export DD_APP_KEY=your_datadog_app_key
export GOOGLE_API_KEY=your_google_api_key

2. Create Configuration

Create detra.yaml:

app_name: my-llm-app
datadog:
  api_key: ${DD_API_KEY}
  app_key: ${DD_APP_KEY}
  site: datadoghq.com
  service: my-service

gemini:
  api_key: ${GOOGLE_API_KEY}
  model: gemini-2.5-flash

nodes:
  extract_entities:
    expected_behaviors:
      - "Must return valid JSON"
      - "Must extract party names accurately"
    unexpected_behaviors:
      - "Hallucinated party names"
      - "Fabricated dates"
    adherence_threshold: 0.85

3. Use in Your Code

import detra

# Initialize
vg = detra.init("detra.yaml")

# Decorate your LLM functions
@vg.trace("extract_entities")
async def extract_entities(document: str):
    # Your LLM call here
    result = await llm.complete(prompt)
    return result

# Use the function - tracing and evaluation happen automatically
result = await extract_entities("Contract text...")

4. Setup Monitoring

# Create monitors and dashboard
setup_results = await vg.setup_all(slack_channel="#llm-alerts")
print(f"Dashboard URL: {setup_results['dashboard']['url']}")

Usage Examples

Basic Tracing

import detra

vg = detra.init("detra.yaml")

@vg.trace("summarize")
async def summarize(text: str):
    return await llm.summarize(text)

Different Trace Types

@vg.workflow("document_processing")  # Workflow trace
@vg.llm("llm_call")                  # LLM call trace
@vg.task("data_extraction")         # Task trace
@vg.agent("agent_name")              # Agent trace

Manual Evaluation

result = await vg.evaluate(
    node_name="extract_entities",
    input_data="Document text",
    output_data={"entities": [...]},
)
print(f"Score: {result.score}, Flagged: {result.flagged}")

Security Scanning

nodes:
  my_node:
    security_checks:
      - pii_detection
      - prompt_injection
      - sensitive_content

Alerting

integrations:
  slack:
    enabled: true
    webhook_url: ${SLACK_WEBHOOK_URL}
    notify_on:
      - flag_raised
      - incident_created
      - security_issue

Evaluation Pipeline

  1. Rule-Based Checks: Fast validation (JSON format, empty output, etc.)
  2. Security Scans: PII detection, prompt injection scanning
  3. LLM Evaluation: Gemini-based semantic evaluation of behaviors
  4. Flagging: Automatic flagging when thresholds are breached
  5. Alerting: Notifications sent based on severity

Requirements

  • Datadog account with API key and Application key
  • Google API key for Gemini evaluation (optional but recommended)

Documentation

License

MIT 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

detra-0.1.0.tar.gz (186.0 kB view details)

Uploaded Source

Built Distribution

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

detra-0.1.0-py3-none-any.whl (106.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for detra-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c429f1820637b22318543d5e2e75e55ea4f145d806761090b02c94fa38bafceb
MD5 581ec399a35730fda99489578671bf33
BLAKE2b-256 6c22fcc8ae97bc102986feab9938d74d489bc13e64617bfa23425e748a83ff87

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for detra-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d1720fb301d80f510ff915b064f22da8ba9663cf01d47bb55b180c39d66338bb
MD5 e9880d759c7a7e3ad6b36e31fe3dcda6
BLAKE2b-256 a7abb2040d8bd7f719f15830713efc2746828518317299aee1b932367dc4a8f7

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