Schedule icon
Webhook icon
Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Create icon
Fail icon
Log icon

Langfuse Daily LLM Trace Quality and Cost Sentinel

Audit Langfuse LLM observability traces for cost, error rate, and p95 latency. Alert Slack and open GitHub issues when quality thresholds are breached.

Categories
AIData

Diagram unavailable

We could not build the topology for this blueprint. The flow itself is valid, use the YAML on the left to run it.

Production LLM applications emit thousands of traces per day through Langfuse, covering RAG pipelines, chat agents, classification tasks, and summarisation workflows. Without automated quality gates, three failure modes go undetected until they surface as customer complaints: runaway prompt loops that inflate token costs beyond the daily budget; cascading provider errors or timeouts that spike error rates; and slow model responses that degrade the user experience.

This blueprint provides a daily observability sentinel that pulls yesterday's traces from the Langfuse REST API, computes total USD spend, error rate, and p95 latency, compares each metric against configurable thresholds, and routes alerts to Slack with a full breakdown table. When the daily cost ceiling is breached the execution is explicitly failed so the incident is red in Kestra's UI. A webhook trigger lets deployment pipelines run the same check immediately after a prompt-template release.

How it works

  1. daily_quality_check (io.kestra.plugin.core.trigger.Schedule, cron 0 8 * * *, shipped disabled: true) runs every morning before standup. on_demand_check (io.kestra.plugin.core.trigger.Webhook) lets CI/CD pipelines run an immediate check after a prompt-template deployment.
  2. fetch_traces (io.kestra.plugin.scripts.python.Script in python:3.12-slim) calls GET /api/public/traces with a fromTimestamp/toTimestamp window derived from lookback_hours, paginates up to 1000 traces, aggregates total cost, token counts, latency percentiles, and error counts, writes traces_summary.json, and emits all metrics via Kestra's outputs protocol. A bundled offline fixture triggers automatically when the API is unreachable so the flow is safely testable without live credentials.
  3. evaluate_thresholds (io.kestra.plugin.scripts.python.Script) compares the aggregated metrics against max_daily_cost_usd, max_error_rate_pct, and max_p95_latency_ms, and emits a verdict of BREACH or HEALTHY along with per-threshold boolean flags.
  4. route_on_verdict (io.kestra.plugin.core.flow.If) branches on the verdict:
    • HEALTHY: log_healthy records a clean pass with all four key metrics.
    • BREACH: alert_slack posts a rich block-kit card to Slack listing every breached threshold. When open_github_issue is true, io.kestra.plugin.github.issues.Create files a labeled sprint-tracking issue with a full metrics table. When cost is specifically breached, io.kestra.plugin.core.execution.Fail marks the execution red in the Kestra UI.
  5. The errors block catches API authentication failures or container errors and notifies Slack so the absence of a daily report is never mistaken for a healthy system.

What you get

  • Automated daily LLM cost governance that fails the execution explicitly when spend exceeds the ceiling.
  • Error rate monitoring that catches cascading provider failures or broken prompt templates before users are impacted.
  • p95 latency tracking that surfaces slow models or overloaded inference endpoints.
  • Rich Slack block-kit alert cards with a complete metrics breakdown for the lookback window.
  • Optional GitHub issue creation so quality breaches land in the engineering sprint backlog automatically.
  • Offline fixture fallback making the flow safely testable in CI without live Langfuse credentials.

Who it's for

  • AI Engineers and MLOps teams operating production RAG pipelines, chat agents, or classification services tracked in Langfuse.
  • Engineering managers and FinOps teams who own LLM spend budgets and need automated daily cost reconciliation.
  • Platform Engineers implementing quality gates around prompt-template deployment pipelines.

Why orchestrate this with Kestra

A manual daily review of Langfuse dashboards scales poorly across teams and models. Kestra wraps the quality check in a declarative YAML flow with encrypted secret management for API keys, a dual trigger (schedule + webhook) so the same gate runs on a daily cadence and on every prompt deployment, structured outputs that downstream flows can branch on, and an explicit Fail task that makes cost breaches operationally visible without relying on someone noticing a Slack message.

Prerequisites

  • A Langfuse project with API keys (Public Key and Secret Key), available at cloud.langfuse.com or on a self-hosted instance.
  • A Slack Incoming Webhook URL for alert delivery.
  • A GitHub Personal Access Token with Issues write permission if open_github_issue is enabled.

Secrets

  • LANGFUSE_SENTINEL_WEBHOOK_KEY: Secret key guarding the on-demand webhook trigger URL.
  • LANGFUSE_PUBLIC_KEY: Langfuse project Public Key for REST API authentication.
  • LANGFUSE_SECRET_KEY: Langfuse project Secret Key for REST API authentication.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for quality breach and failure alerts.
  • GITHUB_TOKEN: GitHub Personal Access Token (scope repo or Issues write) used when open_github_issue is true.
  • GITHUB_REPOSITORY: Target repository in owner/repo format where issues are created.

Quick start

  1. Add LANGFUSE_SENTINEL_WEBHOOK_KEY, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, and SLACK_WEBHOOK_URL to your Kestra namespace secrets.
  2. Import this blueprint and click Execute with default inputs to run against the bundled offline fixture and verify Slack rendering.
  3. Set langfuse_host to your live instance URL and lookback_hours: 1 to run a quick live smoke test.
  4. Tune max_daily_cost_usd, max_error_rate_pct, and max_p95_latency_ms to match your production SLOs.
  5. Enable daily_quality_check by setting disabled: false to activate the automated morning schedule.

How to extend

  • Break down cost by model or user by grouping traces on the model or userId fields returned by the Langfuse API and emitting per-model spend as additional outputs.
  • Add a PagerDuty task in the breach branch to escalate persistent cost overruns to on-call engineers.
  • Push total_cost_usd, error_rate_pct, and p95_latency_ms to a Prometheus Pushgateway to chart LLM quality trends over time.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.