Langfuse integration: rules and issues from the traces you already collect
With the Langfuse integration, oversized refunds in last month's traces become an issue, and Amiril drafts the rule that blocks the next one.
With the Langfuse integration, oversized refunds in last month's traces become an issue, and Amiril drafts the rule that blocks the next one.
For the Langfuse integration, export your observations from Langfuse as JSONL and upload the file on Amiril's Data page. Each trace becomes a run of the agent its trace name points to. Amiril ranks those runs by how rare they are for that agent and groups the ones that share a problem into issues. From an issue it drafts a rule that stops the bad tool call, such as an oversized refund, before it runs.
The observations table in Langfuse has an export button, and on 3 December 2026 Langfuse's FAQ listed CSV, JSON and JSONL as its formats. Amiril reads the JSONL one, with one observation on each line.
A project with a lot of history is easier to pull through the API. The Observations API v2 returns one page at a time, and in Langfuse's API spec the last page is the one with no meta.cursor. A page can come back empty with a cursor still on it. Ask for every field group, or the inputs and outputs come back empty:
cursor=""
while :; do
next=""
[ -n "$cursor" ] && next="&cursor=$(jq -rn --arg c "$cursor" '$c|@uri')"
page=$(curl -sSf -u "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" \
"$LANGFUSE_HOST/api/public/v2/observations?fields=core,basic,io,time,model,usage,trace_context,metadata&limit=100$next") \
|| { echo "request failed at cursor $cursor" >&2; exit 1; }
echo "$page" | jq -c '.data[]' >> observations.jsonl
cursor=$(echo "$page" | jq -r '.meta.cursor // empty')
[ -z "$cursor" ] && break
done
gzip observations.jsonlThe cursor is base64, which can hold a + or a /, so jq encodes it before it goes back in the URL. curl -f turns a 401, 429 or 5xx into a failed request, so the script stops and prints the cursor it reached.
Open Data and drop the file on Drop your export here, or browse. It takes .jsonl or .jsonl.gz files. The upload lands in the environment picked at the top of the page, which the drop zone names in a line such as "Files you upload here go into Development." Uploads into a production environment ask you to confirm first.
The file then gets a row under History, which shows Scoring and then Ready. Timestamps without a timezone are read as UTC, and the row says so. If your Langfuse project wrote local times, Change timezone reads the file again in the right zone.
Once the row says Ready, every trace from the file is a run on the Traces page. The run belongs to the agent named by its Langfuse trace name. A name Amiril hasn't seen before waits on the Agents page under Unregistered until you register it or assign it to an agent you already have.
A run with one call far outside the agent's usual, such as a refund many times the size of the others, shows near the top with a rarity such as Top 1%, and hovering the label shows the bits behind it. Its page lists the rarity factor that put it there:
args.amount was 4,800 on an issue_refund call, the largest of 2,310 observations
Runs that share a problem form an issue. Amiril's grounding check can start an issue from a single run, such as one where the agent told a customer a number that no tool result or earlier message contained. A rarity issue forms from three runs whose strongest rarity factor matches. Amiril's investigator reads a sample of the issue's Langfuse traces with an AI model and writes up what they have in common under What is happening. Under Fix it shows the rule it would add to stop them. Runs that arrive live later are compared with the uploaded ones, so agent observability in Amiril starts with your Langfuse history behind each agent.
Langfuse's docs on the same day put guardrails in two places. Its security docs pair run-time libraries such as LLM Guard, NeMo Guardrails and Lakera with Langfuse tracing, which you use to inspect and evaluate those checks afterwards. Its AI Gateway, in public beta, has guardrails that inspect model requests and responses for PII, secrets, prompt injection phrases, keyword lists or your own regular expressions, and block, redact or log a match.
The gateway's guardrails work on the text going to and from the model. An Amiril rule works on a tool call. The SDK checks it in the agent's own process before the tool runs, and the rule can read the call's arguments along with earlier calls in the run or the session. This one caps the refunds a support agent can hand out in one conversation:
@id("refund-session-total") @scope("session") @sentence("This refund brings the session total to {session_total}, over 500") block ( agent == "support", tool == "issue_refund" ) unless { session_total = sum(issue_refund{}.args.amount, call.args.amount); session_total <= 500 };
issue_refund{} matches the earlier issue_refund calls, and its empty braces put no condition on them. sum adds their amounts to this one, and @scope("session") makes it read every run in the conversation's session. A second refund of 300 in the same conversation is blocked, even though each one is under 500.
When a rule could have stopped an issue's runs, the issue carries a rule suggestion with the rule drafted and a line such as "Would have blocked 4 of 5 runs", and Create rule opens it in the editor. For @per, flag and the rest of the syntax, see the rule language. Amiril's AI agent guardrails check against a copy of the rules held in the agent's memory, so a check makes no network request.
An upload brings in older history, so the runs from before last month come in with the rest, each ranked against its agent's other runs. New runs reach Amiril as they happen through a second OpenTelemetry exporter, set up beside your Langfuse integration. The one feeding Langfuse stays in place, because a tracer provider hands each span to every exporter added to it. Three standard variables configure the new one, with the key and endpoint you get under Set up a new installation on the Data page:
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="<OpenTelemetry traces endpoint>" export OTEL_EXPORTER_OTLP_TRACES_PROTOCOL="http/protobuf" export OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Bearer <your API key>"
Per-framework instrumentation is in the OpenTelemetry docs. With live traces coming in, Slack gets a daily digest and a message when an issue forms at High or above. You connect Slack under Settings, Alerts. Each message names the agent and the issue, and Slack alerts on your Langfuse traces can go to separate channels, one taking the digest and another only new issues. Test on past calls replays a rule, drafts included, over 24 hours, 7 days or 30 days of traces, uploaded ones too.
Blocking happens in the SDK. It wraps each tool and reports every rule decision to Amiril:
pip install amiril
import amiril
from amiril import plain
amiril.init()
agent = plain.Agent("support")
@agent.tool
def issue_refund(order_id: str, amount: float) -> dict:
"""Refund part or all of an order."""
return refunds.create(order_id, amount)plain is the adapter for an agent loop you wrote yourself, and amiril.init() reads AMIRIL_API_KEY from the environment. LangGraph, Google ADK and LiveKit each have their own SDK guide. A published rule starts in Shadow, where it records what it would have done and lets every call through. When the count on its page holds only calls you meant to stop, switch it to Enforce. A blocked call never reaches the tool, and the model gets a message telling it the call was not performed and not to retry it another way.
Changing the limit later is an edit and a publish, which running agents pick up within about a minute with no redeploy. If Amiril can't be reached, they keep checking with the last rules they received.
Amiril reads a copy of your Langfuse observations, taken with the export button or the API. It adds issues, rarity and the rules that block a tool call.
No. The upload is enough for runs, rarity and issues. You add the SDK only when you want a rule to block calls.
Runs from a Langfuse file show on the same pages as runs sent over OpenTelemetry, ranked and grouped into issues the same way.
The one named by the trace's name in Langfuse. A new name shows under Unregistered on the Agents page until you register it.
Upload a Langfuse export and the Langfuse integration starts on your past runs.