<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Otel on lo0 — Tech Blog</title><link>https://blog.lo0.es/en/tags/otel/</link><description>Recent content in Otel on lo0 — Tech Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Mon, 01 Jun 2026 05:00:00 +0200</lastBuildDate><atom:link href="https://blog.lo0.es/en/tags/otel/index.xml" rel="self" type="application/rss+xml"/><item><title>LLM Guard: the sworn translator with a notebook of equivalences — anatomy, scanners and its integration with Langfuse, vLLM and LiteLLM</title><link>https://blog.lo0.es/en/posts/llm-guard-anatomy-scanners-langfuse-vllm-litellm/</link><pubDate>Mon, 01 Jun 2026 05:00:00 +0200</pubDate><guid>https://blog.lo0.es/en/posts/llm-guard-anatomy-scanners-langfuse-vllm-litellm/</guid><description>&lt;blockquote>
&lt;p>This post is a &lt;strong>deep dive into a single piece&lt;/strong> inside the layer covered in the &lt;a href="https://blog.lo0.es/en/posts/llm-guardrails-safety-four-lines-of-defence/">post on guardrails and LLM safety&lt;/a>. That one maps the four lines of defence (input, retrieval, tool, output) and the 2026 OSS catalogue from a bird&amp;rsquo;s-eye view; this one gets down to ground level on &lt;strong>LLM Guard&lt;/strong>, because its Anonymize/Deanonymize pattern, its composable scanner model and its four deployment modes deserve their own treatment. The analogies built up there (HACCP kitchen, four CCPs) still hold: this post zooms in on the tool that occupies the PII belt and the individual scanners within that architecture.&lt;/p>
&lt;/blockquote>
&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>LLM Guard is the OSS tool (MIT, Protect AI) that materialises the LLM guardrail layer with a model radically different from that of NeMo Guardrails and Guardrails AI: instead of a declarative DSL (Colang) or a validator framework with external LLM-as-judge calls, it offers a &lt;strong>catalogue of specialised compact detectors&lt;/strong>, 15 input scanners and 21 output scanners, composable as a Python pipeline, with one distinctive mechanism: the &lt;strong>Anonymize → LLM → Deanonymize with Vault&lt;/strong> pattern. The Vault is a centralised store of the mapping between real entities (&lt;code>John Doe&lt;/code>, &lt;code>12345678X&lt;/code>) and placeholders (&lt;code>[REDACTED_PERSON_1]&lt;/code>, &lt;code>[REDACTED_DNI_1]&lt;/code>); on input, entities are redacted and the mapping is saved; the LLM never sees real personal data; on output, the Deanonymize scanner restores the originals before returning the answer to the user. This post takes apart: the internal anatomy (Vault + scanners + orchestrator with &lt;code>fail_fast&lt;/code> and TTL cache), the four deployment patterns with their mathematics (in-process library, FastAPI API, OTel sidecar over vLLM, AI Gateway plugin — LiteLLM, Envoy AI Gateway, Kong AI Gateway), the integration diagrams with Langfuse (via LLM Guard&amp;rsquo;s OTel HTTP exporter + &lt;code>langfuse.score()&lt;/code> from the AI Gateway), the mathematics with the project&amp;rsquo;s benchmarks (Anonymize at 177 ms CPU → 128 ms ONNX-CPU → 125 ms GPU FP16 → 38 ms GPU+ONNX, scaling ×4.6 when you combine ONNX + GPU), the ONNX pattern as the default acceleration without a dedicated GPU, the comparison with NeMo Guardrails (declarative Colang DSL oriented to conversational flow) and Guardrails AI (JSON contract-style validators with external judges), the application to on-premise hardware (which scanners hold up on CPU, which need a shared GPU) and the seven operational pitfalls specific to the tool.&lt;/p>
&lt;h2 id="the-analogy-the-sworn-translator-with-a-notebook-of-equivalences">The analogy: the sworn translator with a notebook of equivalences&lt;/h2>
&lt;div class="diagram" style="max-width:820px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 820 380" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="LLM Guard as a sworn translator with a notebook of equivalences">
&lt;style>
.t-user{fill:#7aafff;stroke:#444;stroke-width:1.4;rx:8}
.t-trad{fill:#ffd76b;stroke:#444;stroke-width:1.4;rx:8}
.t-model{fill:#ff8a4c;stroke:#444;stroke-width:1.4;rx:8}
.t-vault{fill:#c8b8ff;stroke:#444;stroke-width:1.4;rx:8}
.tl{font:600 13px sans-serif;fill:#222}
.ts{font:400 11px sans-serif;fill:#555}
.tn{font:italic 11px sans-serif;fill:#555}
.tar{stroke:#666;stroke-width:1.6;fill:none;marker-end:url(#mt1)}
.tcb{stroke:#7a5;stroke-width:1.4;fill:none;stroke-dasharray:5 3;marker-end:url(#mt2)}
&lt;/style>
&lt;defs>
&lt;marker id="mt1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#666"/>&lt;/marker>
&lt;marker id="mt2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#7a5"/>&lt;/marker>
&lt;/defs>
&lt;rect x="20" y="40" width="120" height="60" class="t-user"/>
&lt;text x="80" y="64" text-anchor="middle" class="tl">Customer&lt;/text>
&lt;text x="80" y="82" text-anchor="middle" class="ts">"My ID is 12345678X,&lt;/text>
&lt;text x="80" y="96" text-anchor="middle" class="ts">is VAT due?"&lt;/text>
&lt;rect x="180" y="40" width="160" height="60" class="t-trad"/>
&lt;text x="260" y="64" text-anchor="middle" class="tl">Translator (Anonymize)&lt;/text>
&lt;text x="260" y="82" text-anchor="middle" class="ts">redacts sensitive entities&lt;/text>
&lt;text x="260" y="96" text-anchor="middle" class="ts">+ writes them in the notebook&lt;/text>
&lt;rect x="380" y="40" width="160" height="60" class="t-model"/>
&lt;text x="460" y="64" text-anchor="middle" class="tl">LLM&lt;/text>
&lt;text x="460" y="82" text-anchor="middle" class="ts">receives sanitised text:&lt;/text>
&lt;text x="460" y="96" text-anchor="middle" class="ts">"My ID is [DNI_1], is VAT due?"&lt;/text>
&lt;rect x="580" y="40" width="160" height="60" class="t-trad"/>
&lt;text x="660" y="64" text-anchor="middle" class="tl">Translator (Deanonymize)&lt;/text>
&lt;text x="660" y="82" text-anchor="middle" class="ts">restores the originals&lt;/text>
&lt;text x="660" y="96" text-anchor="middle" class="ts">from the notebook&lt;/text>
&lt;rect x="680" y="40" width="120" height="60" class="t-user" transform="translate(-20 130)"/>
&lt;text x="720" y="194" text-anchor="middle" class="tl" transform="translate(-20 0)">Customer receives&lt;/text>
&lt;text x="720" y="212" text-anchor="middle" class="ts" transform="translate(-20 0)">an answer with&lt;/text>
&lt;text x="720" y="226" text-anchor="middle" class="ts" transform="translate(-20 0)">"12345678X" restored&lt;/text>
&lt;path class="tar" d="M140,70 L180,70"/>
&lt;path class="tar" d="M340,70 L380,70"/>
&lt;path class="tar" d="M540,70 L580,70"/>
&lt;path class="tar" d="M660,100 Q660,150 700,170"/>
&lt;rect x="280" y="220" width="220" height="80" class="t-vault"/>
&lt;text x="390" y="244" text-anchor="middle" class="tl">Vault (shared notebook)&lt;/text>
&lt;text x="390" y="262" text-anchor="middle" class="ts">[PERSON_1] = "Marta García"&lt;/text>
&lt;text x="390" y="276" text-anchor="middle" class="ts">[DNI_1] = "12345678X"&lt;/text>
&lt;text x="390" y="290" text-anchor="middle" class="ts">[IBAN_1] = "ES91 2100 0418..."&lt;/text>
&lt;path class="tcb" d="M260,100 L320,218"/>
&lt;path class="tcb" d="M460,218 L660,100"/>
&lt;text x="200" y="160" class="tn">stores mapping&lt;/text>
&lt;text x="500" y="160" class="tn">looks up to restore&lt;/text>
&lt;text x="410" y="340" text-anchor="middle" class="tn">The LLM never sees the original PII. The notebook (Vault) is the only point that knows the equivalence.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>A serious sworn translator working with sensitive documents, an employment contract, a medical record, a tax return, does not send the raw text to the machine translation service in the cloud. They keep a &lt;strong>notebook of equivalences&lt;/strong> open on the desk. When the original document arrives, they open the notebook and start writing down: &amp;ldquo;Marta García&amp;rdquo; → &lt;code>[PERSON-1]&lt;/code>, &amp;ldquo;12345678X&amp;rdquo; → &lt;code>[DNI-1]&lt;/code>, &amp;ldquo;ES91 2100 0418&amp;hellip;&amp;rdquo; → &lt;code>[IBAN-1]&lt;/code>. They substitute each occurrence in the text with its label and pass the &lt;strong>anonymised&lt;/strong> text to the translation service. The service returns a translation that still contains the labels. The translator opens the notebook again, restores each label with its original value, and hands the client the final translation with the PII intact. As far as the translation service is concerned, those personal data &lt;strong>never existed&lt;/strong>: it only saw placeholders.&lt;/p>
&lt;p>This is the exact operation that defines LLM Guard&amp;rsquo;s character against the rest of the ecosystem. NeMo Guardrails solves safety with a &lt;strong>declarative graph&lt;/strong> of rules in Colang; Guardrails AI with &lt;strong>validators&lt;/strong> that invoke an LLM-as-judge to verify contracts; LLM Guard with a &lt;strong>catalogue of specialised compact detectors&lt;/strong> + the Vault pattern. All three are valid in different scenarios. The choice is not a matter of taste: it is structural, according to how the system is built and where the bottleneck is.&lt;/p>
&lt;p>The translator also checks, of course, that the text contains no other problems besides PII: insults, instructions to reprogram itself, links to hostile pages, code that should not be there. That is what the rest of the scanner catalogue is for. But the house signature, what sets it apart, is that notebook.&lt;/p>
&lt;h2 id="internal-anatomy-of-llm-guard">Internal anatomy of LLM Guard&lt;/h2>
&lt;div class="diagram" style="max-width:820px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 820 460" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Internal anatomy of LLM Guard">
&lt;style>
.a-orch{fill:#7aafff;stroke:#444;stroke-width:1.4;rx:8}
.a-in{fill:#a8e6a3;stroke:#444;stroke-width:1.4;rx:6}
.a-out{fill:#ffd76b;stroke:#444;stroke-width:1.4;rx:6}
.a-vault{fill:#c8b8ff;stroke:#444;stroke-width:1.4;rx:6}
.a-obs{fill:#f8a8d8;stroke:#444;stroke-width:1.4;rx:6}
.al{font:600 12px sans-serif;fill:#222}
.as{font:400 10px sans-serif;fill:#444}
.an{font:italic 10px sans-serif;fill:#555}
.aar{stroke:#666;stroke-width:1.4;fill:none;marker-end:url(#ma1)}
&lt;/style>
&lt;defs>&lt;marker id="ma1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#666"/>&lt;/marker>&lt;/defs>
&lt;rect x="20" y="20" width="780" height="40" class="a-orch"/>
&lt;text x="410" y="42" text-anchor="middle" class="al">Orchestrator: scan_prompt() / scan_output() · fail_fast · TTL cache · timeout · OTel spans&lt;/text>
&lt;text x="410" y="56" text-anchor="middle" class="as">Iterates scanners in order, aggregates is_valid and risk_score, emits traces and Prometheus metrics&lt;/text>
&lt;text x="50" y="90" class="al">Input scanners (15)&lt;/text>
&lt;rect x="30" y="100" width="120" height="22" class="a-in"/>&lt;text x="90" y="115" text-anchor="middle" class="as">Anonymize ⓥ&lt;/text>
&lt;rect x="30" y="125" width="120" height="22" class="a-in"/>&lt;text x="90" y="140" text-anchor="middle" class="as">PromptInjection&lt;/text>
&lt;rect x="30" y="150" width="120" height="22" class="a-in"/>&lt;text x="90" y="165" text-anchor="middle" class="as">Toxicity&lt;/text>
&lt;rect x="30" y="175" width="120" height="22" class="a-in"/>&lt;text x="90" y="190" text-anchor="middle" class="as">Secrets&lt;/text>
&lt;rect x="30" y="200" width="120" height="22" class="a-in"/>&lt;text x="90" y="215" text-anchor="middle" class="as">TokenLimit&lt;/text>
&lt;rect x="30" y="225" width="120" height="22" class="a-in"/>&lt;text x="90" y="240" text-anchor="middle" class="as">BanTopics&lt;/text>
&lt;rect x="30" y="250" width="120" height="22" class="a-in"/>&lt;text x="90" y="265" text-anchor="middle" class="as">BanCompetitors&lt;/text>
&lt;rect x="30" y="275" width="120" height="22" class="a-in"/>&lt;text x="90" y="290" text-anchor="middle" class="as">BanCode / Code&lt;/text>
&lt;rect x="30" y="300" width="120" height="22" class="a-in"/>&lt;text x="90" y="315" text-anchor="middle" class="as">Sentiment&lt;/text>
&lt;rect x="30" y="325" width="120" height="22" class="a-in"/>&lt;text x="90" y="340" text-anchor="middle" class="as">Gibberish&lt;/text>
&lt;rect x="30" y="350" width="120" height="22" class="a-in"/>&lt;text x="90" y="365" text-anchor="middle" class="as">Language&lt;/text>
&lt;rect x="30" y="375" width="120" height="22" class="a-in"/>&lt;text x="90" y="390" text-anchor="middle" class="as">InvisibleText&lt;/text>
&lt;rect x="30" y="400" width="120" height="22" class="a-in"/>&lt;text x="90" y="415" text-anchor="middle" class="as">Regex · BanSubstrings&lt;/text>
&lt;rect x="180" y="120" width="160" height="170" class="a-vault"/>
&lt;text x="260" y="142" text-anchor="middle" class="al">Vault&lt;/text>
&lt;text x="260" y="160" text-anchor="middle" class="as">In-memory dictionary&lt;/text>
&lt;text x="260" y="174" text-anchor="middle" class="as">per session / request&lt;/text>
&lt;text x="260" y="200" text-anchor="middle" class="as">[PERSON_1]→"Marta García"&lt;/text>
&lt;text x="260" y="214" text-anchor="middle" class="as">[DNI_1]→"12345678X"&lt;/text>
&lt;text x="260" y="228" text-anchor="middle" class="as">[IBAN_1]→"ES91..."&lt;/text>
&lt;text x="260" y="252" text-anchor="middle" class="as">.placeholder() / .get()&lt;/text>
&lt;text x="260" y="266" text-anchor="middle" class="as">optional: persistence&lt;/text>
&lt;text x="260" y="280" text-anchor="middle" class="as">Redis / sticky client&lt;/text>
&lt;path class="aar" d="M150,110 L186,140"/>
&lt;text x="360" y="90" class="al">Output scanners (21)&lt;/text>
&lt;rect x="350" y="100" width="120" height="22" class="a-out"/>&lt;text x="410" y="115" text-anchor="middle" class="as">Deanonymize ⓥ&lt;/text>
&lt;rect x="350" y="125" width="120" height="22" class="a-out"/>&lt;text x="410" y="140" text-anchor="middle" class="as">Sensitive (PII out)&lt;/text>
&lt;rect x="350" y="150" width="120" height="22" class="a-out"/>&lt;text x="410" y="165" text-anchor="middle" class="as">Toxicity · Bias&lt;/text>
&lt;rect x="350" y="175" width="120" height="22" class="a-out"/>&lt;text x="410" y="190" text-anchor="middle" class="as">NoRefusal&lt;/text>
&lt;rect x="350" y="200" width="120" height="22" class="a-out"/>&lt;text x="410" y="215" text-anchor="middle" class="as">Relevance&lt;/text>
&lt;rect x="350" y="225" width="120" height="22" class="a-out"/>&lt;text x="410" y="240" text-anchor="middle" class="as">FactualConsistency&lt;/text>
&lt;rect x="350" y="250" width="120" height="22" class="a-out"/>&lt;text x="410" y="265" text-anchor="middle" class="as">JSON validator&lt;/text>
&lt;rect x="350" y="275" width="120" height="22" class="a-out"/>&lt;text x="410" y="290" text-anchor="middle" class="as">MaliciousURLs&lt;/text>
&lt;rect x="350" y="300" width="120" height="22" class="a-out"/>&lt;text x="410" y="315" text-anchor="middle" class="as">URLReachability&lt;/text>
&lt;rect x="350" y="325" width="120" height="22" class="a-out"/>&lt;text x="410" y="340" text-anchor="middle" class="as">LanguageSame&lt;/text>
&lt;rect x="350" y="350" width="120" height="22" class="a-out"/>&lt;text x="410" y="365" text-anchor="middle" class="as">ReadingTime&lt;/text>
&lt;rect x="350" y="375" width="120" height="22" class="a-out"/>&lt;text x="410" y="390" text-anchor="middle" class="as">BanCompetitors&lt;/text>
&lt;rect x="350" y="400" width="120" height="22" class="a-out"/>&lt;text x="410" y="415" text-anchor="middle" class="as">Regex · BanSubstrings&lt;/text>
&lt;path class="aar" d="M340,140 L350,140"/>
&lt;text x="540" y="90" class="al">Backend models&lt;/text>
&lt;rect x="510" y="100" width="160" height="60" class="a-obs"/>
&lt;text x="590" y="120" text-anchor="middle" class="al">ONNX runtime&lt;/text>
&lt;text x="590" y="136" text-anchor="middle" class="as">quantised models&lt;/text>
&lt;text x="590" y="152" text-anchor="middle" class="as">CPU + GPU compatible&lt;/text>
&lt;rect x="510" y="170" width="160" height="60" class="a-obs"/>
&lt;text x="590" y="190" text-anchor="middle" class="al">Transformers (HF)&lt;/text>
&lt;text x="590" y="206" text-anchor="middle" class="as">BERT NER, distilbert&lt;/text>
&lt;text x="590" y="222" text-anchor="middle" class="as">deberta, bge, etc.&lt;/text>
&lt;rect x="510" y="240" width="160" height="60" class="a-obs"/>
&lt;text x="590" y="260" text-anchor="middle" class="al">Presidio Analyzer&lt;/text>
&lt;text x="590" y="276" text-anchor="middle" class="as">spaCy / flair / regex&lt;/text>
&lt;text x="590" y="292" text-anchor="middle" class="as">~50 base entities&lt;/text>
&lt;rect x="510" y="310" width="160" height="60" class="a-obs"/>
&lt;text x="590" y="330" text-anchor="middle" class="al">Pure validators&lt;/text>
&lt;text x="590" y="346" text-anchor="middle" class="as">regex, JSON schema,&lt;/text>
&lt;text x="590" y="362" text-anchor="middle" class="as">stdlib URL parsing&lt;/text>
&lt;text x="700" y="90" class="al">Telemetry&lt;/text>
&lt;rect x="690" y="100" width="115" height="60" class="a-obs"/>
&lt;text x="747" y="120" text-anchor="middle" class="al">OTel exporter&lt;/text>
&lt;text x="747" y="136" text-anchor="middle" class="as">traces (HTTP)&lt;/text>
&lt;text x="747" y="152" text-anchor="middle" class="as">metrics (HTTP)&lt;/text>
&lt;rect x="690" y="170" width="115" height="60" class="a-obs"/>
&lt;text x="747" y="190" text-anchor="middle" class="al">Prometheus&lt;/text>
&lt;text x="747" y="206" text-anchor="middle" class="as">/metrics endpoint&lt;/text>
&lt;text x="747" y="222" text-anchor="middle" class="as">counters + histograms&lt;/text>
&lt;rect x="690" y="240" width="115" height="60" class="a-obs"/>
&lt;text x="747" y="260" text-anchor="middle" class="al">structured logs&lt;/text>
&lt;text x="747" y="276" text-anchor="middle" class="as">stdout JSON,&lt;/text>
&lt;text x="747" y="292" text-anchor="middle" class="as">Loki/ELK parseable&lt;/text>
&lt;rect x="690" y="310" width="115" height="60" class="a-obs"/>
&lt;text x="747" y="330" text-anchor="middle" class="al">FastAPI&lt;/text>
&lt;text x="747" y="346" text-anchor="middle" class="as">/analyze/prompt&lt;/text>
&lt;text x="747" y="362" text-anchor="middle" class="as">/analyze/output&lt;/text>
&lt;text x="410" y="445" text-anchor="middle" class="an">The Vault is the unique piece: Anonymize (input) and Deanonymize (output) share it in the same request or session. Without it, PII would leak to the LLM.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>The three structural pieces are:&lt;/p>
&lt;p>&lt;strong>1. The orchestrator&lt;/strong> (&lt;code>scan_prompt&lt;/code>, &lt;code>scan_output&lt;/code>). It receives an ordered list of scanners and runs them sequentially over the text. It returns the triple &lt;code>(sanitized_text, results_valid, results_score)&lt;/code> where:&lt;/p>
&lt;ul>
&lt;li>&lt;code>sanitized_text&lt;/code> is the text transformed by the scanners that mutate it (Anonymize, BanSubstrings with redaction).&lt;/li>
&lt;li>&lt;code>results_valid&lt;/code> is a &lt;code>{scanner_name: bool}&lt;/code> dict indicating which scanners passed.&lt;/li>
&lt;li>&lt;code>results_score&lt;/code> is a &lt;code>{scanner_name: float}&lt;/code> dict with the reported risk score (0 clean, 1 maximum violation).&lt;/li>
&lt;/ul>
&lt;p>It supports &lt;code>fail_fast=True&lt;/code> to stop after the first failure. It supports a per-scanner &lt;code>timeout&lt;/code> so it does not block on a slow detector. When exposed as a FastAPI API, it supports a TTL cache to avoid rescanning repeated prompts (the case of bots with identical questions).&lt;/p>
&lt;p>&lt;strong>2. The scanner catalogue.&lt;/strong> Fifteen input scanners and twenty-one output scanners, each with its own backend model and its configurable threshold:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Family&lt;/th>
&lt;th>Input&lt;/th>
&lt;th>Output&lt;/th>
&lt;th>Dominant backend&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>PII&lt;/strong>&lt;/td>
&lt;td>Anonymize&lt;/td>
&lt;td>Deanonymize, Sensitive&lt;/td>
&lt;td>Presidio + BERT-NER&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Injection and jailbreak&lt;/strong>&lt;/td>
&lt;td>PromptInjection&lt;/td>
&lt;td>—&lt;/td>
&lt;td>Fine-tuned DeBERTa (Protect AI&amp;rsquo;s own)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Toxicity and bias&lt;/strong>&lt;/td>
&lt;td>Toxicity, Sentiment&lt;/td>
&lt;td>Toxicity, Bias, Sentiment&lt;/td>
&lt;td>Fine-tuned RoBERTa / BERT&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Banned topics&lt;/strong>&lt;/td>
&lt;td>BanTopics, BanCompetitors&lt;/td>
&lt;td>BanTopics, BanCompetitors&lt;/td>
&lt;td>Zero-shot BART-MNLI classifier&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Substrings and regex&lt;/strong>&lt;/td>
&lt;td>BanSubstrings, Regex&lt;/td>
&lt;td>BanSubstrings, Regex&lt;/td>
&lt;td>string matching + regex&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Secrets&lt;/strong>&lt;/td>
&lt;td>Secrets&lt;/td>
&lt;td>—&lt;/td>
&lt;td>detect-secrets (Yelp) + regex&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Structure&lt;/strong>&lt;/td>
&lt;td>TokenLimit, Language, InvisibleText, Gibberish&lt;/td>
&lt;td>JSON, Language, LanguageSame, Gibberish, ReadingTime&lt;/td>
&lt;td>tokeniser, lang-detect, JSON schema&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Code&lt;/strong>&lt;/td>
&lt;td>BanCode, Code&lt;/td>
&lt;td>BanCode, Code&lt;/td>
&lt;td>language classifier + regex&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>URLs&lt;/strong>&lt;/td>
&lt;td>—&lt;/td>
&lt;td>MaliciousURLs, URLReachability&lt;/td>
&lt;td>block list + DNS lookup&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Answer quality&lt;/strong>&lt;/td>
&lt;td>—&lt;/td>
&lt;td>NoRefusal, Relevance, FactualConsistency&lt;/td>
&lt;td>NLI cross-encoder + cosine similarity&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Each scanner is imported and instantiated individually, with its own threshold:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">llm_guard.input_scanners&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Anonymize&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">PromptInjection&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Toxicity&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Secrets&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">llm_guard.vault&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Vault&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">vault&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">Vault&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">scanners&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Anonymize&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">vault&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">threshold&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.5&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">PromptInjection&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">threshold&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.85&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Toxicity&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">threshold&lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="mf">0.7&lt;/span>&lt;span class="p">),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="n">Secrets&lt;/span>&lt;span class="p">(),&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">]&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>3. The Vault.&lt;/strong> A unique piece not found in NeMo Guardrails or Guardrails AI with the same model. It is an in-memory dictionary per session or request that stores the &lt;code>placeholder → original_value&lt;/code> mapping. The &lt;code>Anonymize&lt;/code> scanner writes it on input and the &lt;code>Deanonymize&lt;/code> scanner reads it on output. If the Vault is shared across multiple requests from the same user, the mapping persists (useful for multi-turn conversations). If it is per request, it is discarded after the answer.&lt;/p>
&lt;p>The basic Vault is a Python &lt;code>dict&lt;/code>; for distributed environments with multiple pods, it is replaced by a sticky Redis (same user → same pod) or by a custom Vault that reads from and writes to an external Redis, discarded after a TTL. This is operational, not part of the core library.&lt;/p>
&lt;h2 id="the-anonymize--llm--deanonymize-flow-in-detail">The Anonymize → LLM → Deanonymize flow in detail&lt;/h2>
&lt;p>The canonical usage pattern of LLM Guard breaks down into six exact steps:&lt;/p>
&lt;pre tabindex="0">&lt;code>1. Receive the user&amp;#39;s prompt:
&amp;#34;My name is Marta García and my IBAN is ES9121000418450200051332,
can you review the charge from 14 March?&amp;#34;
2. scan_prompt() with [Anonymize(vault), PromptInjection(), Toxicity()]
→ Anonymize redacts entities and stores them in the vault:
vault[&amp;#34;[REDACTED_PERSON_1]&amp;#34;] = &amp;#34;Marta García&amp;#34;
vault[&amp;#34;[REDACTED_IBAN_1]&amp;#34;] = &amp;#34;ES9121000418450200051332&amp;#34;
→ PromptInjection checks there is no jailbreak (there is none)
→ Toxicity checks there are no insults (there are none)
→ results_valid = {Anonymize: True, PromptInjection: True, Toxicity: True}
→ sanitized_prompt:
&amp;#34;My name is [REDACTED_PERSON_1] and my IBAN is [REDACTED_IBAN_1],
can you review the charge from 14 March?&amp;#34;
3. Call the LLM with sanitized_prompt:
→ vLLM receives the prompt with no real PII
→ generates the answer:
&amp;#34;Yes, [REDACTED_PERSON_1], I am going to review the charge on account
[REDACTED_IBAN_1]. Can you confirm the amount?&amp;#34;
4. scan_output() with [Deanonymize(vault), Toxicity(), Relevance(), Sensitive()]
→ Deanonymize replaces placeholders with values from the vault:
[REDACTED_PERSON_1] → &amp;#34;Marta García&amp;#34;
[REDACTED_IBAN_1] → &amp;#34;ES9121000418450200051332&amp;#34;
→ Toxicity checks the answer is not offensive
→ Relevance checks it answers the prompt
→ Sensitive checks no unauthorised PII appears
(in this case, the restored PII is authorised because the user
brought it themselves and the Vault signs it → the rule applies
only to new PII invented by the LLM)
→ sanitized_response:
&amp;#34;Yes, Marta García, I am going to review the charge on account
ES9121000418450200051332. Can you confirm the amount?&amp;#34;
5. Return sanitized_response to the user.
6. If the session continues, the vault persists and the next turns reuse
the same placeholders. When the session ends, the vault is discarded.
&lt;/code>&lt;/pre>&lt;p>Three details that matter operationally:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Persistent entities&lt;/strong> (&lt;code>[REDACTED_PERSON_1]&lt;/code> for &amp;ldquo;Marta García&amp;rdquo;) stay constant throughout the session. If the user mentions another person (&amp;ldquo;I spoke to Juan Pérez&amp;rdquo;), Anonymize will assign &lt;code>[REDACTED_PERSON_2]&lt;/code>. Cross-turn coherence is guaranteed by the Vault.&lt;/li>
&lt;li>&lt;strong>The LLM never sees the original data&lt;/strong> during the session. This is the key property for cases where the LLM is served from a cloud model or when the prompt is logged (Langfuse, OTel) without confidential access.&lt;/li>
&lt;li>&lt;strong>LLM Guard&amp;rsquo;s logging records the placeholders&lt;/strong>, not the original values. For audit with original values, an additional layer is needed (access to the Vault with privileged permissions), and this is by design, not by default.&lt;/li>
&lt;/ul>
&lt;h2 id="four-deployment-modes">Four deployment modes&lt;/h2>
&lt;h3 id="mode-1--in-process-python-library">Mode 1 — In-process Python library&lt;/h3>
&lt;p>The simplest: &lt;code>pip install llm-guard&lt;/code>, import the scanners in the application code, call &lt;code>scan_prompt&lt;/code>/&lt;code>scan_output&lt;/code> directly. The models load into the process. The advantage is minimum latency; the disadvantage is that each application replica loads its own models into memory.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-python" data-lang="python">&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># on the app server&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">llm_guard&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">scan_prompt&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">scan_output&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">llm_guard.input_scanners&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Anonymize&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">PromptInjection&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Toxicity&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">llm_guard.output_scanners&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Deanonymize&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Toxicity&lt;/span> &lt;span class="k">as&lt;/span> &lt;span class="n">OutToxicity&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">Relevance&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="kn">from&lt;/span> &lt;span class="nn">llm_guard.vault&lt;/span> &lt;span class="kn">import&lt;/span> &lt;span class="n">Vault&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">vault&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">Vault&lt;/span>&lt;span class="p">()&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">input_scanners&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="n">Anonymize&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">vault&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="n">PromptInjection&lt;/span>&lt;span class="p">(),&lt;/span> &lt;span class="n">Toxicity&lt;/span>&lt;span class="p">()]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">output_scanners&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="p">[&lt;/span>&lt;span class="n">Deanonymize&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">vault&lt;/span>&lt;span class="p">),&lt;/span> &lt;span class="n">OutToxicity&lt;/span>&lt;span class="p">(),&lt;/span> &lt;span class="n">Relevance&lt;/span>&lt;span class="p">()]&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="c1"># in the request handler&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">sanitized_prompt&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">valid_in&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">score_in&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">scan_prompt&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">input_scanners&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">user_prompt&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">if&lt;/span> &lt;span class="ow">not&lt;/span> &lt;span class="nb">all&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">valid_in&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">values&lt;/span>&lt;span class="p">()):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">error_response&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">score_in&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">response&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">vllm_client&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">complete&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">sanitized_prompt&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="n">sanitized_resp&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">valid_out&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">score_out&lt;/span> &lt;span class="o">=&lt;/span> &lt;span class="n">scan_output&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">output_scanners&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">sanitized_prompt&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="n">response&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">if&lt;/span> &lt;span class="ow">not&lt;/span> &lt;span class="nb">all&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">valid_out&lt;/span>&lt;span class="o">.&lt;/span>&lt;span class="n">values&lt;/span>&lt;span class="p">()):&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="k">return&lt;/span> &lt;span class="n">error_response&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">score_out&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="k">return&lt;/span> &lt;span class="n">sanitized_resp&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>It fits &lt;strong>pattern A (sidecar)&lt;/strong> from the &lt;a href="https://blog.lo0.es/en/posts/llm-guardrails-safety-four-lines-of-defence/">guardrails post&lt;/a> when the app and the sidecar share a process. And &lt;strong>pattern C (in-process)&lt;/strong> if the app is itself the inference layer.&lt;/p>
&lt;h3 id="mode-2--its-own-fastapi-api">Mode 2 — Its own FastAPI API&lt;/h3>
&lt;p>The project includes a ready-made FastAPI server (&lt;code>llm-guard-api&lt;/code>) that exposes the scanners behind two REST endpoints:&lt;/p>
&lt;pre tabindex="0">&lt;code>POST /analyze/prompt
body: {&amp;#34;prompt&amp;#34;: &amp;#34;...&amp;#34;, &amp;#34;scanners&amp;#34;: [...] (optional)}
response: {&amp;#34;sanitized_prompt&amp;#34;: &amp;#34;...&amp;#34;, &amp;#34;is_valid&amp;#34;: bool, &amp;#34;scanners&amp;#34;: {scanner: {is_valid, risk_score}}}
POST /analyze/output
body: {&amp;#34;prompt&amp;#34;: &amp;#34;...&amp;#34;, &amp;#34;output&amp;#34;: &amp;#34;...&amp;#34;, &amp;#34;scanners&amp;#34;: [...]}
response: analogous
&lt;/code>&lt;/pre>&lt;p>Configuration through &lt;code>config/scanners.yml&lt;/code> with environment variables (&lt;code>SCAN_FAIL_FAST&lt;/code>, &lt;code>CACHE_MAX_SIZE&lt;/code>, &lt;code>CACHE_TTL&lt;/code>, &lt;code>SCAN_PROMPT_TIMEOUT&lt;/code>…). It carries Prometheus metrics at &lt;code>/metrics&lt;/code> and OTel HTTP exporter traces by default.&lt;/p>
&lt;p>It fits &lt;strong>pattern B (centralised service behind an AI gateway)&lt;/strong> from the guardrails post.&lt;/p>
&lt;h3 id="mode-3--otel-sidecar-on-the-inference-engine-pod">Mode 3 — OTel sidecar on the inference engine pod&lt;/h3>
&lt;p>For vLLM deployments on Kubernetes, a variant of mode 2 is to deploy the LLM Guard API as a &lt;strong>sidecar container&lt;/strong> in the same vLLM pod, talking over localhost. The AI gateway in front invokes the sidecar before and after inference. The node&amp;rsquo;s OTel collector aggregates vLLM&amp;rsquo;s spans with LLM Guard&amp;rsquo;s &lt;code>gen_ai.guardrail.*&lt;/code> spans automatically because they share a &lt;code>trace_id&lt;/code> propagated via HTTP baggage.&lt;/p>
&lt;p>This fits &lt;strong>pattern A (sidecar)&lt;/strong> from the guardrails post, but with the discipline of a REST API so as not to couple languages (the AI gateway can be Envoy in C++, LLM Guard in Python).&lt;/p>
&lt;h3 id="mode-4--plugin-inside-an-ai-gateway">Mode 4 — Plugin inside an AI gateway&lt;/h3>
&lt;p>Three AI gateways support LLM Guard as a native plugin in 2026:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>LiteLLM Proxy&lt;/strong> (MIT, BerriAI) — &lt;code>llm_guard&lt;/code> plugin, enabled in config with &lt;code>guardrails: [&amp;quot;llm_guard&amp;quot;]&lt;/code>. It calls the API internally.&lt;/li>
&lt;li>&lt;strong>Envoy AI Gateway&lt;/strong> (CNCF, Apache 2.0) — &lt;code>ai-guardrails&lt;/code> filter with a pluggable backend pointing at the LLM Guard service.&lt;/li>
&lt;li>&lt;strong>Kong AI Gateway&lt;/strong> (Apache 2.0) — &lt;code>ai-proxy&lt;/code> plugin with a post-processor that invokes LLM Guard.&lt;/li>
&lt;/ul>
&lt;p>In all three cases, the AI gateway is the single entry point from the client app to the LLM; the gateway calls LLM Guard before and after passing to the inference engine. Advantage: zero lock-in in the application code; switching from LLM Guard to NeMo Guardrails means changing the gateway plugin, not rewriting the app. Disadvantage: the extra hop adds latency (typically 5-15 ms intra-cluster).&lt;/p>
&lt;h2 id="graphical-integration-with-langfuse-vllm-and-the-otel-stack">Graphical integration with Langfuse, vLLM and the OTel stack&lt;/h2>
&lt;div class="diagram" style="max-width:820px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 820 460" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Integration of LLM Guard with Langfuse, vLLM and the OTel stack">
&lt;style>
.b-app{fill:#7aafff;stroke:#444;stroke-width:1.4;rx:8}
.b-gw{fill:#a8e6a3;stroke:#444;stroke-width:1.4;rx:8}
.b-lg{fill:#ffd76b;stroke:#444;stroke-width:1.4;rx:8}
.b-vllm{fill:#ff8a4c;stroke:#444;stroke-width:1.4;rx:8}
.b-otel{fill:#c8b8ff;stroke:#444;stroke-width:1.4;rx:8}
.b-langfuse{fill:#f8a8d8;stroke:#444;stroke-width:1.4;rx:8}
.b-storage{fill:#f0e8c0;stroke:#444;stroke-width:1.4;rx:8}
.bl{font:600 13px sans-serif;fill:#222}
.bs{font:400 11px sans-serif;fill:#444}
.bn{font:italic 10px sans-serif;fill:#555}
.bar{stroke:#666;stroke-width:1.6;fill:none;marker-end:url(#mb1)}
.bart{stroke:#5a5;stroke-width:1.4;fill:none;stroke-dasharray:5 3;marker-end:url(#mb2)}
&lt;/style>
&lt;defs>
&lt;marker id="mb1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#666"/>&lt;/marker>
&lt;marker id="mb2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#5a5"/>&lt;/marker>
&lt;/defs>
&lt;rect x="20" y="40" width="140" height="50" class="b-app"/>
&lt;text x="90" y="60" text-anchor="middle" class="bl">Client app&lt;/text>
&lt;text x="90" y="78" text-anchor="middle" class="bs">chatbot · backend · agent&lt;/text>
&lt;rect x="200" y="40" width="180" height="50" class="b-gw"/>
&lt;text x="290" y="60" text-anchor="middle" class="bl">AI Gateway&lt;/text>
&lt;text x="290" y="78" text-anchor="middle" class="bs">LiteLLM · Envoy AI · Kong AI&lt;/text>
&lt;rect x="430" y="20" width="160" height="40" class="b-lg"/>
&lt;text x="510" y="38" text-anchor="middle" class="bl">LLM Guard API&lt;/text>
&lt;text x="510" y="54" text-anchor="middle" class="bs">scan_prompt + scan_output&lt;/text>
&lt;rect x="430" y="70" width="160" height="40" class="b-vllm"/>
&lt;text x="510" y="88" text-anchor="middle" class="bl">vLLM&lt;/text>
&lt;text x="510" y="104" text-anchor="middle" class="bs">inference engine + adapter&lt;/text>
&lt;rect x="640" y="40" width="160" height="50" class="b-storage"/>
&lt;text x="720" y="60" text-anchor="middle" class="bl">Vault Redis&lt;/text>
&lt;text x="720" y="78" text-anchor="middle" class="bs">placeholder→PII mapping&lt;/text>
&lt;path class="bar" d="M160,65 L200,65"/>
&lt;path class="bar" d="M380,55 L430,40"/>
&lt;path class="bar" d="M380,75 L430,90"/>
&lt;path class="bar" d="M510,60 L640,65"/>
&lt;text x="170" y="55" class="bn">1: prompt&lt;/text>
&lt;text x="390" y="35" class="bn">2: pre-scan&lt;/text>
&lt;text x="390" y="105" class="bn">3: inference&lt;/text>
&lt;text x="555" y="55" class="bn">vault R/W&lt;/text>
&lt;rect x="20" y="180" width="240" height="80" class="b-otel"/>
&lt;text x="140" y="202" text-anchor="middle" class="bl">OTel Collector (DaemonSet)&lt;/text>
&lt;text x="140" y="220" text-anchor="middle" class="bs">receives gen_ai.* and&lt;/text>
&lt;text x="140" y="234" text-anchor="middle" class="bs">gen_ai.guardrail.* spans from:&lt;/text>
&lt;text x="140" y="250" text-anchor="middle" class="bs">vLLM, LLM Guard, AI Gateway&lt;/text>
&lt;path class="bart" d="M510,110 Q260,140 140,178"/>
&lt;path class="bart" d="M510,60 Q330,140 200,178"/>
&lt;path class="bart" d="M290,90 Q230,140 140,178"/>
&lt;text x="320" y="135" class="bn">OTel HTTP spans&lt;/text>
&lt;rect x="300" y="180" width="200" height="80" class="b-langfuse"/>
&lt;text x="400" y="202" text-anchor="middle" class="bl">Langfuse&lt;/text>
&lt;text x="400" y="220" text-anchor="middle" class="bs">/api/public/otel ingestion&lt;/text>
&lt;text x="400" y="236" text-anchor="middle" class="bs">+ /api/public/scores&lt;/text>
&lt;text x="400" y="252" text-anchor="middle" class="bs">+ datasets + sessions&lt;/text>
&lt;path class="bar" d="M260,220 L300,220"/>
&lt;text x="270" y="215" class="bn">OTLP&lt;/text>
&lt;rect x="540" y="180" width="120" height="40" class="b-otel"/>
&lt;text x="600" y="200" text-anchor="middle" class="bl">Tempo / Jaeger&lt;/text>
&lt;text x="600" y="216" text-anchor="middle" class="bs">trace storage&lt;/text>
&lt;rect x="540" y="225" width="120" height="40" class="b-otel"/>
&lt;text x="600" y="245" text-anchor="middle" class="bl">VictoriaMetrics&lt;/text>
&lt;text x="600" y="261" text-anchor="middle" class="bs">Prom metrics&lt;/text>
&lt;path class="bar" d="M260,210 L540,200"/>
&lt;path class="bar" d="M260,235 L540,240"/>
&lt;rect x="700" y="180" width="100" height="80" class="b-storage"/>
&lt;text x="750" y="202" text-anchor="middle" class="bl">Grafana&lt;/text>
&lt;text x="750" y="220" text-anchor="middle" class="bs">datasource&lt;/text>
&lt;text x="750" y="234" text-anchor="middle" class="bs">Tempo + VM&lt;/text>
&lt;text x="750" y="252" text-anchor="middle" class="bs">+ Langfuse&lt;/text>
&lt;path class="bar" d="M660,220 L700,220"/>
&lt;rect x="20" y="320" width="780" height="50" class="b-gw"/>
&lt;text x="410" y="340" text-anchor="middle" class="bl">Langfuse scoring plane: the AI Gateway posts langfuse.score(trace_id, name="guardrail.PromptInjection", value=risk_score)&lt;/text>
&lt;text x="410" y="356" text-anchor="middle" class="bs">for each scanner run; that lets Langfuse build "% blocks per category" dashboards and time series&lt;/text>
&lt;path class="bar" d="M290,90 Q290,290 400,320"/>
&lt;text x="305" y="200" class="bn">HTTP scores&lt;/text>
&lt;text x="410" y="400" text-anchor="middle" class="bn">Three telemetry planes mix: traces (OTel → Tempo + Langfuse), metrics (Prometheus → VictoriaMetrics), scores (Langfuse SDK).&lt;/text>
&lt;text x="410" y="418" text-anchor="middle" class="bn">Grafana joins them by trace_id; Langfuse joins them by session_id + propagated trace_id.&lt;/text>
&lt;text x="410" y="438" text-anchor="middle" class="bn">The Vault Redis has its own data plane and is NOT exported to observability — the original PII never leaves it.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>The &lt;strong>three integration routes with Langfuse&lt;/strong> that matter operationally:&lt;/p>
&lt;p>&lt;strong>Route A — LLM Guard&amp;rsquo;s OTel HTTP exporter.&lt;/strong> LLM Guard has a native OTel HTTP exporter. By setting &lt;code>OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://langfuse.cluster/api/public/otel&lt;/code>, the &lt;code>gen_ai.guardrail.*&lt;/code> spans emitted by each scanner arrive directly at Langfuse and appear as child spans of the main LLM span (provided the &lt;code>trace_id&lt;/code> is propagated via HTTP baggage from the AI gateway). This is the canonical route in 2026.&lt;/p>
&lt;p>&lt;strong>Route B — Langfuse scoring API from the AI gateway.&lt;/strong> On receiving LLM Guard&amp;rsquo;s response with the per-scanner &lt;code>risk_score&lt;/code>, the AI gateway (LiteLLM, Envoy AI, Kong AI) issues a &lt;code>langfuse.score(trace_id, name=&amp;quot;guardrail.PromptInjection&amp;quot;, value=0.87, comment=&amp;quot;blocked&amp;quot;)&lt;/code> call for each scanner. In Langfuse it appears as scores attached to the same trace as the inference. It enables &amp;ldquo;blocks per category&amp;rdquo; dashboards and per-scanner time series. It is &lt;strong>complementary&lt;/strong> to route A: A brings the spans, B brings the numeric score that is easy to aggregate in SQL.&lt;/p>
&lt;p>&lt;strong>Route C — Langfuse sessions + Vault metadata.&lt;/strong> In conversational mode, the AI gateway propagates &lt;code>langfuse_session_id&lt;/code> to the Vault as its key. When a user has a multi-turn session, Langfuse shows the complete trace of the session, with the placeholders reused turn after turn. The original PII still never travels to Langfuse, only the placeholders and their categories.&lt;/p>
&lt;p>The node&amp;rsquo;s &lt;strong>OTel Collector&lt;/strong> is the glue: it receives spans from vLLM (via OpenLLMetry or native instrumentation), from LLM Guard (via its OTel exporter) and from the AI gateway (standard HTTP instrumentation), &lt;strong>joins them by trace_id&lt;/strong>, and sends them in parallel to Langfuse (via OTLP HTTP) and to Tempo/Jaeger. LLM Guard&amp;rsquo;s Prometheus metrics go to VictoriaMetrics via normal scraping. Grafana offers the unified view for cross-trace investigation; Langfuse offers the LLM-centric view with sessions and scores. The &lt;a href="https://blog.lo0.es/en/posts/llm-tracing-opentelemetry-genai/">OTel GenAI tracing post&lt;/a> details the complete mechanics of the Collector.&lt;/p>
&lt;h2 id="the-mathematics-that-matter">The mathematics that matter&lt;/h2>
&lt;h3 id="latency-per-scanner--the-real-numbers">Latency per scanner — the real numbers&lt;/h3>
&lt;p>The project publishes reproducible benchmarks. For the Anonymize scanner (input length 317 chars, batch 5), the reference data are:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Platform&lt;/th>
&lt;th>Backend&lt;/th>
&lt;th>Avg latency&lt;/th>
&lt;th>p99&lt;/th>
&lt;th>QPS&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>AWS m5.xlarge (CPU)&lt;/td>
&lt;td>Transformers&lt;/td>
&lt;td>177 ms&lt;/td>
&lt;td>326 ms&lt;/td>
&lt;td>1,789&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>AWS m5.xlarge (CPU)&lt;/td>
&lt;td>&lt;strong>ONNX runtime&lt;/strong>&lt;/td>
&lt;td>&lt;strong>128 ms&lt;/strong>&lt;/td>
&lt;td>180 ms&lt;/td>
&lt;td>2,464&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>AWS r6a.xlarge (AMD CPU)&lt;/td>
&lt;td>Transformers&lt;/td>
&lt;td>244 ms&lt;/td>
&lt;td>284 ms&lt;/td>
&lt;td>1,298&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>AWS g5.xlarge (NVIDIA A10G)&lt;/td>
&lt;td>Transformers FP16&lt;/td>
&lt;td>125 ms&lt;/td>
&lt;td>498 ms&lt;/td>
&lt;td>2,532&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>AWS g5.xlarge (A10G)&lt;/td>
&lt;td>&lt;strong>ONNX + GPU&lt;/strong>&lt;/td>
&lt;td>&lt;strong>38 ms&lt;/strong>&lt;/td>
&lt;td>99 ms&lt;/td>
&lt;td>8,317&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>Three operational observations:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>ONNX always wins.&lt;/strong> Even on CPU, ONNX brings the average down from 177 to 128 ms (a factor of 1.4×). On GPU with ONNX, it drops from 177 to 38 ms (a factor of 4.6×). The practical rule: &lt;strong>always export the scanner&amp;rsquo;s model to ONNX before production&lt;/strong>. The official SaaS preview uses it by default.&lt;/li>
&lt;li>&lt;strong>A GPU without ONNX does not perform as well as you might expect.&lt;/strong> An A10G without ONNX (125 ms) is comparable to an m5.xlarge with ONNX (128 ms). The GPU alone does not compensate if the inference graph is not optimised. The relevant pairing is ONNX + GPU.&lt;/li>
&lt;li>&lt;strong>p99 latency without ONNX explodes.&lt;/strong> On GPU without ONNX, the p99 of 498 ms triples the average of 125 ms — queues and batching produce high tail latencies. With ONNX, the p99/avg ratio drops to 2.6× (99/38), far more predictable.&lt;/li>
&lt;/ol>
&lt;p>For a guardrail layer with five scanners run sequentially (Anonymize, PromptInjection, Toxicity, Secrets, BanTopics), the sum of the p99s is what determines the budget for line 1 (input). Five scanners at ~100 ms p99 each = 500 ms accumulated p99, outside the budget for interactive chat. With ONNX we get down to ~50 ms each = 250 ms p99, which is manageable. &lt;strong>With &lt;code>fail_fast=True&lt;/code>&lt;/strong>, the expected time is lower (the most likely case is that the cheap ones pass and the expensive ones only fail if they run at all).&lt;/p>
&lt;p>For a finer calculation, the expected latency of the pipeline with &lt;code>fail_fast&lt;/code> is:&lt;/p>
\[
\mathbb{E}[L] = \sum_{i=1}^{N} L_i \cdot \prod_{j=1}^{i-1} p_j
\]
&lt;p>where \(L_i\) is the latency of scanner \(i\) and \(p_j\) the probability that scanner \(j\) returns valid. On well-behaved traffic (most prompts pass every scanner), \(\prod p_j \approx 1\) and the formula collapses to the direct sum. On adversarial traffic, the faster scanners at the start of the pipeline cut in earlier and the expected latency drops sharply.&lt;/p>
&lt;h3 id="computational-cost-per-scanner">Computational cost per scanner&lt;/h3>
&lt;p>The size of the backend model determines the cost and the possibility of running on CPU vs requiring a GPU:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Scanner&lt;/th>
&lt;th>Typical backend model&lt;/th>
&lt;th>Parameters&lt;/th>
&lt;th>VRAM FP16 / ONNX-INT8&lt;/th>
&lt;th>CPU viable&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>Anonymize (BERT-NER)&lt;/td>
&lt;td>dslim/bert-base-NER&lt;/td>
&lt;td>110 M&lt;/td>
&lt;td>220 MB / 55 MB&lt;/td>
&lt;td>Yes (with ONNX)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Anonymize (BERT-large)&lt;/td>
&lt;td>dslim/bert-large-NER&lt;/td>
&lt;td>335 M&lt;/td>
&lt;td>670 MB / 170 MB&lt;/td>
&lt;td>Yes but slow (~500 ms CPU)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>PromptInjection&lt;/td>
&lt;td>Fine-tuned DeBERTa-v3-base&lt;/td>
&lt;td>184 M&lt;/td>
&lt;td>370 MB / 90 MB&lt;/td>
&lt;td>Yes (with ONNX)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Toxicity&lt;/td>
&lt;td>unitary/toxic-bert&lt;/td>
&lt;td>110 M&lt;/td>
&lt;td>220 MB / 55 MB&lt;/td>
&lt;td>Yes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Sentiment&lt;/td>
&lt;td>distilbert-sst2&lt;/td>
&lt;td>67 M&lt;/td>
&lt;td>130 MB / 35 MB&lt;/td>
&lt;td>Yes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Gibberish&lt;/td>
&lt;td>small distilbert&lt;/td>
&lt;td>67 M&lt;/td>
&lt;td>130 MB / 35 MB&lt;/td>
&lt;td>Yes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>BanTopics&lt;/td>
&lt;td>BART-MNLI zero-shot&lt;/td>
&lt;td>407 M&lt;/td>
&lt;td>815 MB / 200 MB&lt;/td>
&lt;td>Slow on CPU (~400 ms)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Bias (output)&lt;/td>
&lt;td>RoBERTa-bias&lt;/td>
&lt;td>125 M&lt;/td>
&lt;td>250 MB / 65 MB&lt;/td>
&lt;td>Yes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>FactualConsistency&lt;/td>
&lt;td>cross-encoder/nli-deberta&lt;/td>
&lt;td>184 M&lt;/td>
&lt;td>370 MB / 90 MB&lt;/td>
&lt;td>Yes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Relevance&lt;/td>
&lt;td>sentence-transformers&lt;/td>
&lt;td>110 M&lt;/td>
&lt;td>220 MB / 55 MB&lt;/td>
&lt;td>Yes&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>TokenLimit, Regex, JSON, BanSubstrings, Secrets&lt;/td>
&lt;td>(no model)&lt;/td>
&lt;td>—&lt;/td>
&lt;td>0&lt;/td>
&lt;td>Trivial&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>&lt;strong>Sensible on-premise pattern&lt;/strong>: model-free scanners (TokenLimit, Regex, BanSubstrings, Secrets) run on CPU without blinking. Anonymize, PromptInjection, Toxicity, Sentiment and Relevance run comfortably on CPU with ONNX-INT8 at ~50-150 ms p99. BanTopics and the ones based on large cross-encoders (FactualConsistency) are the candidates to live on a shared GPU if you want p99 &amp;lt; 100 ms.&lt;/p>
&lt;h3 id="api-throughput-on-a-cluster">API throughput on a cluster&lt;/h3>
&lt;p>One instance of the FastAPI API with 4 Uvicorn workers on a node with 8 vCPUs reaches ~600-1,200 RPS over a typical 5-scanner pipeline on CPU + ONNX. To scale:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Horizontally&lt;/strong>: replicate pods behind a ClusterIP Service — linear scaling, because the scanners are stateless (except the Vault, which is per session and is externalised to Redis if you want it sticky or shared).&lt;/li>
&lt;li>&lt;strong>Vertically with GPU&lt;/strong>: 1 H100 serves ~5,000-10,000 RPS with all the scanners in ONNX-GPU. It is overkill for most deployments except multi-tenant ones with thousands of sustained QPS.&lt;/li>
&lt;/ul>
&lt;p>The practical rule from the &lt;a href="https://blog.lo0.es/en/posts/llm-guardrails-safety-four-lines-of-defence/">guardrails post&lt;/a> (1 guardrail GPU per 4-8 LLM GPUs) holds here: with a 4×H100 SXM cluster serving Llama 70B at TP=4, an L4 or RTX 4090 dedicated to the LLM Guard service covers the load.&lt;/p>
&lt;h2 id="comparison-with-nemo-guardrails-and-guardrails-ai">Comparison with NeMo Guardrails and Guardrails AI&lt;/h2>
&lt;p>The three tools solve the same problem from three different architectural models. The choice between them is not about quality, since all three are mature, it is about &lt;strong>fit with the rest of the stack&lt;/strong>:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Dimension&lt;/th>
&lt;th>LLM Guard&lt;/th>
&lt;th>NeMo Guardrails&lt;/th>
&lt;th>Guardrails AI&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;strong>Conceptual model&lt;/strong>&lt;/td>
&lt;td>Pipeline of compact scanners&lt;/td>
&lt;td>Declarative Colang graph (conversational flow)&lt;/td>
&lt;td>JSON contract-style validators&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Dominant detection&lt;/strong>&lt;/td>
&lt;td>Specialised ML models (BERT, DeBERTa) per category&lt;/td>
&lt;td>Rules + LLM-as-judge&lt;/td>
&lt;td>Heuristic validators + external LLM-as-judge&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>PII workflow&lt;/strong>&lt;/td>
&lt;td>Anonymize + Vault + Deanonymize&lt;/td>
&lt;td>Via integrated Presidio, no built-in Vault&lt;/td>
&lt;td>PII validators, no automatic restitution&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Licence&lt;/strong>&lt;/td>
&lt;td>MIT&lt;/td>
&lt;td>Apache 2.0&lt;/td>
&lt;td>Apache 2.0 (+ paid Hub)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Language&lt;/strong>&lt;/td>
&lt;td>Python&lt;/td>
&lt;td>Python + Colang DSL&lt;/td>
&lt;td>Python&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>API maturity&lt;/strong>&lt;/td>
&lt;td>Built-in FastAPI API, built-in OTel&lt;/td>
&lt;td>Built-in FastAPI server, partial OTel&lt;/td>
&lt;td>External API server&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Cluster deployment&lt;/strong>&lt;/td>
&lt;td>Lib + API + sidecar + gateway plugins&lt;/td>
&lt;td>Lib + server&lt;/td>
&lt;td>Lib + server + SaaS Hub&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>Typical latency (5 ONNX-GPU scanners)&lt;/strong>&lt;/td>
&lt;td>50-200 ms&lt;/td>
&lt;td>100-500 ms (more if there is an LLM judge)&lt;/td>
&lt;td>100-300 ms (depends on the validator)&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>When it shines&lt;/strong>&lt;/td>
&lt;td>Apps with heavy PII, multi-tenant with sessions, GDPR/HIPAA requirements&lt;/td>
&lt;td>Conversational systems with defined flows, agents with a dialogue policy&lt;/td>
&lt;td>Apps with strict JSON contracts, structured output with additional validation&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;strong>When it does not fit&lt;/strong>&lt;/td>
&lt;td>If you need a declarative dialogue policy&lt;/td>
&lt;td>If you want compact detectors with no LLM judge&lt;/td>
&lt;td>If you want an automatic Vault and Deanonymize&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>The three are &lt;strong>complementary in large deployments&lt;/strong>. A mature pattern in 2026 is:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>NeMo Guardrails&lt;/strong> orchestrates the dialogue flow (which tools the agent can invoke, in what order, with what cooldowns).&lt;/li>
&lt;li>&lt;strong>LLM Guard&lt;/strong> occupies the PII line + compact scanners on input and output, with its Vault doing the dirty work of anonymisation.&lt;/li>
&lt;li>&lt;strong>Guardrails AI&lt;/strong> validates structured outputs (JSON Schema, function calling) with its validators.&lt;/li>
&lt;/ul>
&lt;p>The separation of responsibilities avoids overlap and allows pieces to be swapped without rewriting everything. All three expose a FastAPI API and emit OTel spans; the AI gateway orchestrates them sequentially.&lt;/p>
&lt;h2 id="applied-to-on-premise-hardware">Applied to on-premise hardware&lt;/h2>
&lt;h3 id="on-the-rtx-4090-24-gb">On the RTX 4090 (24 GB)&lt;/h3>
&lt;p>A 4090 dedicated to the LLM Guard service pod comfortably serves the complete pipeline in medium-scale production:&lt;/p>
&lt;ul>
&lt;li>Anonymize (BERT-NER ONNX-INT8): ~50 MB VRAM.&lt;/li>
&lt;li>PromptInjection (DeBERTa ONNX-INT8): ~90 MB.&lt;/li>
&lt;li>Toxicity, Sentiment, Gibberish: ~150 MB total.&lt;/li>
&lt;li>BanTopics (BART-MNLI ONNX-INT8): ~200 MB.&lt;/li>
&lt;li>Bias, Relevance, FactualConsistency (output): ~250 MB total.&lt;/li>
&lt;/ul>
&lt;p>Total ~750 MB. The rest of the VRAM is idle or usable for aggressive batching. Sustained throughput of 3,000-6,000 RPS over the complete pipeline. For deployments with &amp;lt; 500 sustained RPS, the 4090 is under-used and can be shared with another workload (RAG embeddings, BGE reranker).&lt;/p>
&lt;h3 id="on-the-4h100-sxm-cluster-320-gb-total-nvlink">On the 4×H100 SXM cluster (320 GB total, NVLink)&lt;/h3>
&lt;p>There is capacity to spare by an order of magnitude. Sensible pattern:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>3 H100s&lt;/strong> serving the main LLM at TP=3 (Llama 70B FP8).&lt;/li>
&lt;li>&lt;strong>1 H100 split into MIG instances&lt;/strong> (1g.10gb or similar) — one slice for LLM Guard (~10 GB MIG is more than enough), another for the reranker, another for embeddings.&lt;/li>
&lt;/ul>
&lt;p>Aggregate throughput for LLM Guard at that scale: 15,000-30,000 RPS. Plenty for a large multi-tenant setup with long sessions.&lt;/p>
&lt;h2 id="the-specific-operational-pitfalls">The specific operational pitfalls&lt;/h2>
&lt;p>&lt;strong>Pitfall 1 — Vault with no TTL.&lt;/strong> The Vault grows without limit if it is not cleaned. In in-process lib mode per request there is no problem (the object is destroyed). In centralised service mode with Redis, &lt;strong>the TTL is missing&lt;/strong> and Redis fills up. A silent trap discovered when the Redis pod gets OOM-killed in production after six weeks.&lt;/p>
&lt;p>&lt;strong>Pitfall 2 — Vault not shared between pods + AI gateway with no sticky session.&lt;/strong> If the AI gateway distributes round-robin across multiple LLM Guard pods, one pod&amp;rsquo;s local Vault knows nothing of the mapping created by another. Result: on turn 2 of a session, Deanonymize does not find the placeholders from turn 1 and leaves a literal &lt;code>[REDACTED_PERSON_1]&lt;/code> in the answer. Solution: a shared Redis Vault &lt;strong>or&lt;/strong> a sticky session by user_id.&lt;/p>
&lt;p>&lt;strong>Pitfall 3 — Models not exported to ONNX in production.&lt;/strong> It is deployed with the default config (Transformers) and latency is 3-5× worse than the benchmarks report. The team assumes LLM Guard &amp;ldquo;is slow&amp;rdquo;. The solution is to export to ONNX (built into the project) and configure &lt;code>recognizer_conf&lt;/code> with the path to the model&amp;rsquo;s &lt;code>.onnx&lt;/code>.&lt;/p>
&lt;p>&lt;strong>Pitfall 4 — &lt;code>fail_fast=False&lt;/code> with many scanners.&lt;/strong> Without &lt;code>fail_fast&lt;/code>, every scanner always runs, even if the first one already blocked. Latency is 3-5× worse on adversarial traffic. For production, barring an explicit reason (wanting complete per-scanner metrics even when blocking), &lt;code>fail_fast=True&lt;/code> is the reasonable default.&lt;/p>
&lt;p>&lt;strong>Pitfall 5 — Infinite &lt;code>cache_ttl&lt;/code> + prompts with variable PII.&lt;/strong> If the API&amp;rsquo;s cache stores the &lt;code>sanitized_prompt&lt;/code> indefinitely, two different sessions with the same prompt structure but different PII can collide if the cache key does not include the Vault hash. You have to verify that the cache key includes either the complete content (without PII) or a hash of the original prompt.&lt;/p>
&lt;p>&lt;strong>Pitfall 6 — Structured logs with original PII.&lt;/strong> LLM Guard&amp;rsquo;s JSON stdout logs record only placeholders by default. But if custom hooks are added for debugging, it is easy to leak the original PII to the log. A regulatory audit (GDPR, ENS) detects this and it is a breach. Discipline: never add hooks that read from the Vault without explicit permission.&lt;/p>
&lt;p>&lt;strong>Pitfall 7 — &lt;code>scan_output&lt;/code> without the original &lt;code>prompt&lt;/code>.&lt;/strong> The &lt;code>scan_output&lt;/code> method expects (&lt;code>prompt&lt;/code>, &lt;code>output&lt;/code>) for validators that compare both (Relevance, LanguageSame, FactualConsistency). If only the output is passed, those scanners fail silently or return &lt;code>is_valid=True&lt;/code> by default. You have to keep the &lt;code>sanitized_prompt&lt;/code> in the AI gateway and pass it to scan_output.&lt;/p>
&lt;h2 id="when-to-choose-llm-guard-and-when-not-to">When to choose LLM Guard (and when not to)&lt;/h2>
&lt;p>&lt;strong>Choose LLM Guard when&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>The requirement for &lt;strong>PII anonymisation with automatic restitution&lt;/strong> is on the list. It is the number one reason to use it. Banking, healthcare, legal advice, HR — any case with heavy PII that must not reach the LLM even when it is local.&lt;/li>
&lt;li>You want a &lt;strong>Pythonic pipeline&lt;/strong> with no new DSL. If the team is pure Python and prefers composing scanners as objects to learning Colang.&lt;/li>
&lt;li>The stack already has an &lt;strong>AI gateway&lt;/strong> (LiteLLM, Envoy AI, Kong AI) and it integrates as a plugin without touching the app.&lt;/li>
&lt;li>You need &lt;strong>built-in OTel and Prometheus&lt;/strong> with no additional instrumentation.&lt;/li>
&lt;/ul>
&lt;p>&lt;strong>Do not choose LLM Guard when&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>The system is a &lt;strong>conversational agent with complex dialogue flows&lt;/strong> (policies, fallbacks, escalation to a human). There NeMo Guardrails with Colang is structurally better.&lt;/li>
&lt;li>The safety layer reduces to &lt;strong>validating structured outputs&lt;/strong> (JSON, function calling). Guardrails AI with its validators is more natural.&lt;/li>
&lt;li>Your &lt;strong>latency budget is ultra-aggressive&lt;/strong> (&amp;lt; 30 ms for the whole layer). You will have to cut scanners and accept lower coverage; perhaps a single PromptGuard 2 + Presidio in a sidecar (the pattern from the &lt;a href="https://blog.lo0.es/en/posts/llm-guardrails-safety-four-lines-of-defence/">guardrails post&lt;/a>) is simpler.&lt;/li>
&lt;li>You do not want to carry &lt;strong>the operational weight of a distributed Vault&lt;/strong> (Redis, TTL, sticky session). For small systems with no strong PII requirement, it is over-engineered.&lt;/li>
&lt;/ul>
&lt;h2 id="what-we-have-not-covered-upcoming-posts">What we have not covered (upcoming posts)&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>Custom scanners&lt;/strong>: how to write your own scanner when nothing in the catalogue fits (a complex domain regex, your own fine-tuned classifier). The project supports custom scanners by inheriting from &lt;code>InputScanner&lt;/code> / &lt;code>OutputScanner&lt;/code> with three methods.&lt;/li>
&lt;li>&lt;strong>Integration with SLSA / supply chain&lt;/strong>: how to sign the LLM Guard container with cosign, SLSA attestations, and verification in the cluster before admitting it. An operational &lt;a href="https://blog.lo0.es/en/posts/llm-guardrails-safety-four-lines-of-defence/">supply chain security&lt;/a> topic (OWASP LLM03).&lt;/li>
&lt;li>&lt;strong>Red teaming against LLM Guard&lt;/strong>: known techniques that evade detectors (homoglyphs, Unicode confusables, base64 encoding inside the prompt). The project publishes an adversarial test suite for doing your own benchmarking. How it is set up as a continuous gate in CI.&lt;/li>
&lt;li>&lt;strong>Comparative benchmark against Bedrock Guardrails and Azure AI Content Safety&lt;/strong>: F1 per category over real traffic across three different deployments. The &lt;a href="https://blog.lo0.es/en/posts/parallel-catalogue-llmops-stages-open-source-hyperscalers/">OSS vs hyperscalers post&lt;/a> has the strategic comparison; the technical detection comparison is still missing.&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>LLM Guard (Protect AI)&lt;/strong>: &lt;a href="https://llm-guard.com">https://llm-guard.com&lt;/a> — official documentation, scanner list, benchmarks.&lt;/li>
&lt;li>&lt;strong>Repository&lt;/strong>: &lt;a href="https://github.com/protectai/llm-guard">https://github.com/protectai/llm-guard&lt;/a>.&lt;/li>
&lt;li>&lt;strong>LLM Guard API&lt;/strong>: &lt;a href="https://github.com/protectai/llm-guard/tree/main/llm_guard_api">https://github.com/protectai/llm-guard/tree/main/llm_guard_api&lt;/a>.&lt;/li>
&lt;li>&lt;strong>Presidio (Microsoft)&lt;/strong>: &lt;a href="https://microsoft.github.io/presidio/">https://microsoft.github.io/presidio/&lt;/a> — basis of the Anonymize scanner.&lt;/li>
&lt;li>&lt;strong>detect-secrets (Yelp)&lt;/strong>: &lt;a href="https://github.com/Yelp/detect-secrets">https://github.com/Yelp/detect-secrets&lt;/a> — basis of the Secrets scanner.&lt;/li>
&lt;li>&lt;strong>Langfuse OTel ingestion&lt;/strong>: &lt;a href="https://langfuse.com/docs/opentelemetry/get-started">https://langfuse.com/docs/opentelemetry/get-started&lt;/a>.&lt;/li>
&lt;li>&lt;strong>LiteLLM guardrails&lt;/strong>: &lt;a href="https://docs.litellm.ai/docs/proxy/guardrails">https://docs.litellm.ai/docs/proxy/guardrails&lt;/a>.&lt;/li>
&lt;li>&lt;strong>Envoy AI Gateway&lt;/strong>: &lt;a href="https://aigateway.envoyproxy.io">https://aigateway.envoyproxy.io&lt;/a>.&lt;/li>
&lt;li>&lt;strong>Kong AI Gateway&lt;/strong>: &lt;a href="https://docs.konghq.com/hub/kong-inc/ai-prompt-guard/">https://docs.konghq.com/hub/kong-inc/ai-prompt-guard/&lt;/a>.&lt;/li>
&lt;li>&lt;strong>OWASP Top 10 for LLM Applications 2025&lt;/strong>: &lt;a href="https://owasp.org/www-project-top-10-for-large-language-model-applications/">https://owasp.org/www-project-top-10-for-large-language-model-applications/&lt;/a>.&lt;/li>
&lt;li>&lt;strong>ONNX Runtime&lt;/strong>: &lt;a href="https://onnxruntime.ai">https://onnxruntime.ai&lt;/a> — exporting HF models to ONNX for acceleration.&lt;/li>
&lt;/ul>
&lt;h2 id="see-also">See also&lt;/h2>
&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/hardening-secrets-sovereign-llm-stack-defence-in-depth/">Hardening and secrets of the sovereign LLM stack: defence in depth&lt;/a> — guardrails as one more layer of the stack&amp;rsquo;s defence in depth.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/llm-guardrails-safety-four-lines-of-defence/">Guardrails and safety in LLMs: the four lines of defence&lt;/a> — the framework that places LLM Guard as one of the tools within the layer. That post explains the four lines (input, retrieval, tool, output), the OWASP LLM Top 10 and compares NeMo Guardrails, Llama Guard 4, ShieldGemma, Granite Guardian, PromptGuard 2 and LLM Guard from a bird&amp;rsquo;s-eye view.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/oss-catalogue-llmops-six-stages-tool-by-tool/">The OSS catalogue for LLMOps in six stages&lt;/a> — an extended write-up of LLM Guard among the rest of the OSS tools by pipeline stage.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/rag-corpus-curation-active-librarian/">RAG corpus curation: the active librarian&lt;/a> — prevention at ingest shares the Presidio PII detector with LLM Guard; the Vault pattern is the new piece added at runtime.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/llm-tracing-opentelemetry-genai/">LLM tracing with OpenTelemetry GenAI&lt;/a> — the OTel plane over which LLM Guard emits the &lt;code>gen_ai.guardrail.*&lt;/code> spans that Langfuse and Tempo consume.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/prompt-versioning-contract-five-word-change/">Prompt versioning with Langfuse and MLflow&lt;/a> — the &lt;code>prompt_id+version&lt;/code> travels as a span attribute even when the prompt content is anonymised; it complements this post&amp;rsquo;s PII shielding.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/evals-llm-layer-after-tracing/">Evals for LLMs: the layer after tracing&lt;/a> — LLM Guard&amp;rsquo;s offline counterpart. When a scanner reports a high FP rate over real traffic, the offline exercise against an annotated golden set identifies whether to tune the threshold or change the backend model.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/retrain-closing-the-loop-feedback-dataset-adapter/">Retrain: closing the feedback → dataset → adapter loop&lt;/a> — the HIGH severity incidents that LLM Guard emits with &lt;code>risk_score &amp;gt; threshold&lt;/code> feed the incident-driven retrain loop.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/parallel-catalogue-llmops-stages-open-source-hyperscalers/">OSS vs hyperscalers in LLMOps&lt;/a> — the OSS column of the &amp;ldquo;Guardrails&amp;rdquo; row (NeMo + Presidio + Llama Guard 4 + &lt;strong>LLM Guard&lt;/strong>) against Bedrock Guardrails, Azure AI Content Safety and Vertex Model Armor.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/structured-output-bitmask-outlines-xgrammar-llguidance/">Structured output: function calling and constrained decoding&lt;/a> — LLM Guard&amp;rsquo;s JSON scanner validates the output structure as a safety net when the inference engine has already done constrained decoding.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>&lt;a href="https://blog.lo0.es/en/posts/six-stage-llmops-pipeline-architecture-and-deep-dive/">The six-stage LLMOps pipeline&lt;/a> — the master map where Guardrails (this post included) is the online counterpart of the Eval stage.&lt;/p>
&lt;/li>
&lt;/ul></description></item><item><title>LLM tracing with OpenTelemetry GenAI: the aircraft black box the field stabilised in 2026</title><link>https://blog.lo0.es/en/posts/llm-tracing-opentelemetry-genai/</link><pubDate>Wed, 27 May 2026 11:00:00 +0200</pubDate><guid>https://blog.lo0.es/en/posts/llm-tracing-opentelemetry-genai/</guid><description>&lt;blockquote>
&lt;p>This post complements the one on &lt;a href="https://blog.lo0.es/en/posts/prompt-versioning-contract-five-word-change/">Prompt versioning with Langfuse and MLflow&lt;/a>, where &lt;code>prompt_id@version&lt;/code> appeared as a span attribute without the whole pipeline being explained, and the one on &lt;a href="https://blog.lo0.es/en/posts/evals-llm-layer-after-tracing/">Evals for LLMs&lt;/a>, which distinguishes tracing from eval. Here we go inside tracing itself.&lt;/p>
&lt;/blockquote>
&lt;h2 id="tldr">TL;DR&lt;/h2>
&lt;p>OpenTelemetry GenAI, the &lt;code>gen_ai.*&lt;/code> and &lt;code>mcp.*&lt;/code> semantic conventions, have been &lt;strong>stable since late 2025&lt;/strong>, and as of May 2026 they are the substrate on which the whole ecosystem (Langfuse, Phoenix, LangSmith, Braintrust, Arize, Honeycomb, Datadog, New Relic) builds its LLM observability. That means your team instruments once, against OTel, and picks a backend afterwards; not the other way round. The canonical pipeline is &lt;strong>application → OTel SDK (OpenLLMetry or openinference) → OTel Collector → backend(s)&lt;/strong>, with two-layer sampling (head-based at 1-5 % to keep volume viable, tail-based at 100 % over errors and high latencies). This post takes apart the exact attributes you have to fill in on each span (&lt;code>gen_ai.system&lt;/code>, &lt;code>request.model&lt;/code>, &lt;code>usage.input_tokens&lt;/code>, and so on), the operational difference between the three usual SDKs, and the anatomy of a real chat-with-RAG-and-tool trace with all its child spans.&lt;/p>
&lt;h2 id="you-are-here-observe">You are here: OBSERVE&lt;/h2>
&lt;div class="diagram" style="max-width:780px;margin:1rem auto;">
&lt;svg viewBox="0 0 780 90" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="you are here: Observe">
&lt;style>.box{stroke:#444;stroke-width:1.4;rx:6}.active{fill:#c9a8e9;stroke-width:3}.idle{fill:#f4f4f4}.lbl{font:600 12px sans-serif;fill:#222}.arr{stroke:#666;stroke-width:1.4;fill:none;marker-end:url(#otm)}.cyc{stroke:#888;stroke-width:1.2;fill:none;stroke-dasharray:4 2;marker-end:url(#otm)}&lt;/style>
&lt;defs>&lt;marker id="otm" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#666"/>&lt;/marker>&lt;/defs>
&lt;text x="390" y="20" text-anchor="middle" class="lbl">You are here: OBSERVE · tracing with OpenTelemetry GenAI&lt;/text>
&lt;rect x="30" y="35" width="110" height="35" class="box idle"/>&lt;text x="85" y="58" text-anchor="middle" class="lbl">1 · Data&lt;/text>
&lt;rect x="155" y="35" width="110" height="35" class="box idle"/>&lt;text x="210" y="58" text-anchor="middle" class="lbl">2 · Tune&lt;/text>
&lt;rect x="280" y="35" width="110" height="35" class="box idle"/>&lt;text x="335" y="58" text-anchor="middle" class="lbl">3 · Eval&lt;/text>
&lt;rect x="405" y="35" width="110" height="35" class="box idle"/>&lt;text x="460" y="58" text-anchor="middle" class="lbl">4 · Deploy&lt;/text>
&lt;rect x="530" y="35" width="110" height="35" class="box active"/>&lt;text x="585" y="58" text-anchor="middle" class="lbl">5 · Observe&lt;/text>
&lt;rect x="655" y="35" width="110" height="35" class="box idle"/>&lt;text x="710" y="58" text-anchor="middle" class="lbl">6 · Retrain&lt;/text>
&lt;path class="arr" d="M140,52 L155,52"/>&lt;path class="arr" d="M265,52 L280,52"/>&lt;path class="arr" d="M390,52 L405,52"/>&lt;path class="arr" d="M515,52 L530,52"/>&lt;path class="arr" d="M640,52 L655,52"/>
&lt;path class="cyc" d="M710,72 L710,82 L85,82 L85,72"/>
&lt;/svg>
&lt;/div>
&lt;h2 id="the-analogy-the-aircraft-black-box">The analogy: the aircraft black box&lt;/h2>
&lt;p>An aircraft black box does three things at once:&lt;/p>
&lt;ol>
&lt;li>It records everything without anyone having to ask for it explicitly. Every flight parameter, every cockpit conversation, every action by the pilots is logged with a precise timestamp and a standardised format.&lt;/li>
&lt;li>It uses a format everybody knows. Any air accident investigator anywhere in the world can read the black box of any manufacturer, because the schema is agreed between all of them. There is no &amp;ldquo;Boeing black box&amp;rdquo; and &amp;ldquo;Airbus black box&amp;rdquo;: there is one single black box.&lt;/li>
&lt;li>It survives the event: it is designed on the assumption that the aircraft may go down. It does not depend on the aircraft itself to be stored or to be read.&lt;/li>
&lt;/ol>
&lt;p>LLM tracing with OTel GenAI does exactly those three things:&lt;/p>
&lt;ol>
&lt;li>It records everything automatically. Every model call, every agent step, every tool call, every RAG retrieval ends up as a span, a unit of work with a start, an end, attributes and a parent/child relationship with other spans.&lt;/li>
&lt;li>It uses a common format. The attributes &lt;code>gen_ai.request.model&lt;/code>, &lt;code>gen_ai.usage.input_tokens&lt;/code>, &lt;code>gen_ai.response.finish_reasons&lt;/code> and the rest are &lt;strong>agreed by the OpenTelemetry GenAI working group&lt;/strong> and every backend respects them.&lt;/li>
&lt;li>It survives the backend. Spans do not travel straight to Langfuse: they travel to an intermediate &lt;strong>OTel Collector&lt;/strong> that handles buffering, sampling and fan-out to 1, 2 or N backends. If Langfuse goes down, the Collector holds the spans.&lt;/li>
&lt;/ol>
&lt;p>The analogy is not decorative: it is the only way to understand why OTel GenAI beat the ecosystem of proprietary SDKs that every vendor shipped in 2023-2024. &lt;strong>The standardised black box beats the proprietary recorder, every time.&lt;/strong>&lt;/p>
&lt;h2 id="why-otel-genai-exists-and-why-it-won">Why OTel GenAI exists (and why it won)&lt;/h2>
&lt;p>The state of things at the end of 2024 was broken: every vendor shipped its own SDK with its own attribute names. LangSmith called it &lt;code>model_name&lt;/code>, OpenLLMetry called it &lt;code>llm.model&lt;/code>, Helicone called it &lt;code>model&lt;/code>. If you wanted to change observability provider, you re-instrumented the whole application. For serious teams, that was unacceptable.&lt;/p>
&lt;p>OpenTelemetry already had a framework to solve this: the &lt;strong>semantic conventions&lt;/strong>. A working group (the OpenTelemetry GenAI SIG) proposed a schema. In 2025 it reached &amp;ldquo;Stable&amp;rdquo; for the attributes of the basic modality (chat completions + tool calls), and in 2026 it also covers multimodal, embeddings and reasoning modalities.&lt;/p>
&lt;div class="diagram" style="max-width:760px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 760 290" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="OTel GenAI pipeline">
&lt;style>
.bx{fill:#f8f8f8;stroke:#444;stroke-width:1.4;rx:8}
.bs{fill:#ffe6d6}
.bc{fill:#d6eaff}
.bb{fill:#d9f5d6}
.bm{fill:#fff5b0}
.t{font:700 13px sans-serif;fill:#222}
.s{font:400 11px sans-serif;fill:#555}
.h{font:700 14px sans-serif;fill:#222}
.ar{stroke:#666;stroke-width:1.6;fill:none;marker-end:url(#ot1)}
.aw{stroke:#27ae60;stroke-width:1.8;fill:none;marker-end:url(#ot2)}
&lt;/style>
&lt;defs>
&lt;marker id="ot1" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#666"/>&lt;/marker>
&lt;marker id="ot2" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto">&lt;path d="M0,0 L10,5 L0,10 z" fill="#27ae60"/>&lt;/marker>
&lt;/defs>
&lt;text x="380" y="22" text-anchor="middle" class="h">OTel GenAI pipeline: instrument once, choose the backend later&lt;/text>
&lt;rect x="30" y="50" width="160" height="80" class="bx bs"/>
&lt;text x="110" y="74" text-anchor="middle" class="t">Application&lt;/text>
&lt;text x="110" y="92" text-anchor="middle" class="s">Python / Node / Go&lt;/text>
&lt;text x="110" y="108" text-anchor="middle" class="s">+ OpenLLMetry&lt;/text>
&lt;text x="110" y="124" text-anchor="middle" class="s">or openinference SDK&lt;/text>
&lt;rect x="230" y="50" width="160" height="80" class="bx bc"/>
&lt;text x="310" y="74" text-anchor="middle" class="t">OTel Collector&lt;/text>
&lt;text x="310" y="92" text-anchor="middle" class="s">buffering + sampling +&lt;/text>
&lt;text x="310" y="108" text-anchor="middle" class="s">batching + retry +&lt;/text>
&lt;text x="310" y="124" text-anchor="middle" class="s">routing per exporter&lt;/text>
&lt;rect x="430" y="20" width="160" height="40" class="bx bb"/>
&lt;text x="510" y="38" text-anchor="middle" class="t">Langfuse&lt;/text>
&lt;text x="510" y="52" text-anchor="middle" class="s">LLM-first UI, eval, prompts&lt;/text>
&lt;rect x="430" y="80" width="160" height="40" class="bx bb"/>
&lt;text x="510" y="98" text-anchor="middle" class="t">Tempo / Jaeger&lt;/text>
&lt;text x="510" y="112" text-anchor="middle" class="s">distributed tracing infra&lt;/text>
&lt;rect x="430" y="140" width="160" height="40" class="bx bm"/>
&lt;text x="510" y="158" text-anchor="middle" class="t">Prometheus&lt;/text>
&lt;text x="510" y="172" text-anchor="middle" class="s">aggregated metrics&lt;/text>
&lt;rect x="430" y="200" width="160" height="40" class="bx bm"/>
&lt;text x="510" y="218" text-anchor="middle" class="t">ClickHouse / OpenSearch&lt;/text>
&lt;text x="510" y="232" text-anchor="middle" class="s">log and event storage&lt;/text>
&lt;rect x="630" y="80" width="100" height="40" class="bx bb"/>
&lt;text x="680" y="98" text-anchor="middle" class="t">Phoenix&lt;/text>
&lt;text x="680" y="112" text-anchor="middle" class="s">optional, eval-first&lt;/text>
&lt;rect x="630" y="140" width="100" height="40" class="bx bb"/>
&lt;text x="680" y="158" text-anchor="middle" class="t">Datadog/NR&lt;/text>
&lt;text x="680" y="172" text-anchor="middle" class="s">infra-side&lt;/text>
&lt;path class="ar" d="M190,90 L230,90"/>
&lt;path class="ar" d="M390,90 L430,40"/>
&lt;path class="ar" d="M390,90 L430,100"/>
&lt;path class="ar" d="M390,90 L430,160"/>
&lt;path class="ar" d="M390,100 L430,220"/>
&lt;path class="aw" d="M590,100 L630,100"/>
&lt;path class="aw" d="M590,160 L630,160"/>
&lt;text x="110" y="170" text-anchor="middle" class="s" fill="#c0392b">the SDK adds spans automatically&lt;/text>
&lt;text x="110" y="184" text-anchor="middle" class="s" fill="#c0392b">with gen_ai.* attributes&lt;/text>
&lt;text x="310" y="170" text-anchor="middle" class="s" fill="#27ae60">you switch backend by touching only&lt;/text>
&lt;text x="310" y="184" text-anchor="middle" class="s" fill="#27ae60">the Collector's exporter&lt;/text>
&lt;text x="380" y="265" text-anchor="middle" class="s" font-style="italic">If Langfuse goes down, the Collector holds the spans and re-emits them when it returns.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>What changes in practice:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Before (proprietary SDKs)&lt;/strong>: you move from Langfuse to Phoenix → you re-instrument, re-deploy everything, lose the history.&lt;/li>
&lt;li>&lt;strong>Now (OTel)&lt;/strong>: you move from Langfuse to Phoenix → you edit the exporter in &lt;code>otel-collector-config.yaml&lt;/code>, reload the Collector, and the new spans go to the new destination without touching a line of application code.&lt;/li>
&lt;/ul>
&lt;h2 id="the-canonical-gen_ai-attributes">The canonical &lt;code>gen_ai.*&lt;/code> attributes&lt;/h2>
&lt;p>As of May 2026 the stable attributes, that is, the ones that are not going to change, are those in the table. There are more in &amp;ldquo;experimental&amp;rdquo; state (multimodal, reasoning) and others in &amp;ldquo;deprecated&amp;rdquo; (kept for compatibility).&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Attribute&lt;/th>
&lt;th>Meaning&lt;/th>
&lt;th>Example&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>gen_ai.system&lt;/code>&lt;/td>
&lt;td>Provider family&lt;/td>
&lt;td>&lt;code>openai&lt;/code>, &lt;code>anthropic&lt;/code>, &lt;code>vllm&lt;/code>, &lt;code>huggingface&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.request.model&lt;/code>&lt;/td>
&lt;td>Model requested&lt;/td>
&lt;td>&lt;code>gpt-4o&lt;/code>, &lt;code>meta-llama/Llama-3.1-8B-Instruct&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.request.temperature&lt;/code>&lt;/td>
&lt;td>Sampling temp&lt;/td>
&lt;td>&lt;code>0.7&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.request.max_tokens&lt;/code>&lt;/td>
&lt;td>Output cap&lt;/td>
&lt;td>&lt;code>1024&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.request.top_p&lt;/code>&lt;/td>
&lt;td>Nucleus sampling&lt;/td>
&lt;td>&lt;code>0.95&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.response.model&lt;/code>&lt;/td>
&lt;td>Model that answered (may differ)&lt;/td>
&lt;td>&lt;code>gpt-4o-2024-08-06&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.response.id&lt;/code>&lt;/td>
&lt;td>ID of the provider&amp;rsquo;s response&lt;/td>
&lt;td>&lt;code>chatcmpl-9xY...&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.response.finish_reasons&lt;/code>&lt;/td>
&lt;td>Finish reasons&lt;/td>
&lt;td>&lt;code>[&amp;quot;stop&amp;quot;]&lt;/code>, &lt;code>[&amp;quot;length&amp;quot;]&lt;/code>, &lt;code>[&amp;quot;tool_calls&amp;quot;]&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.usage.input_tokens&lt;/code>&lt;/td>
&lt;td>Input tokens&lt;/td>
&lt;td>&lt;code>1247&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.usage.output_tokens&lt;/code>&lt;/td>
&lt;td>Output tokens&lt;/td>
&lt;td>&lt;code>412&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.operation.name&lt;/code>&lt;/td>
&lt;td>Operation type&lt;/td>
&lt;td>&lt;code>chat&lt;/code>, &lt;code>text_completion&lt;/code>, &lt;code>embeddings&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.prompt.id&lt;/code>&lt;/td>
&lt;td>ID of the versioned prompt&lt;/td>
&lt;td>&lt;code>customer_support_v3&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.prompt.version&lt;/code>&lt;/td>
&lt;td>Specific version&lt;/td>
&lt;td>&lt;code>14&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.prompt.label&lt;/code>&lt;/td>
&lt;td>Semantic label&lt;/td>
&lt;td>&lt;code>production&lt;/code>, &lt;code>staging&lt;/code>, &lt;code>canary&lt;/code>&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.conversation.id&lt;/code>&lt;/td>
&lt;td>Multiturn conversation ID&lt;/td>
&lt;td>&lt;code>session_abc123&lt;/code>&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>And for tool calls (a function invoked by the model), the &lt;code>gen_ai.tool.*&lt;/code> attributes:&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>Attribute&lt;/th>
&lt;th>Meaning&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>&lt;code>gen_ai.tool.call.id&lt;/code>&lt;/td>
&lt;td>ID of the specific tool call&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.tool.name&lt;/code>&lt;/td>
&lt;td>Name of the tool&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.tool.type&lt;/code>&lt;/td>
&lt;td>&lt;code>function&lt;/code>, &lt;code>mcp&lt;/code>, and so on&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>&lt;code>gen_ai.tool.description&lt;/code>&lt;/td>
&lt;td>Short description&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;p>And for tool calls over MCP (Model Context Protocol), the &lt;code>mcp.*&lt;/code> attributes add a specific layer (&lt;code>mcp.server.name&lt;/code>, &lt;code>mcp.method&lt;/code>, &lt;code>mcp.session.id&lt;/code> and others) that coexists with the &lt;code>gen_ai.*&lt;/code> ones.&lt;/p>
&lt;p>&lt;strong>The practical rule&lt;/strong>: if your instrumentation fills in these attributes on every span, the Langfuse dashboard, the Tempo graph and the Prometheus metrics come out &amp;ldquo;for free&amp;rdquo;, because all three know how to read the convention.&lt;/p>
&lt;h2 id="the-canonical-pipeline-sdk--collector--backends">The canonical pipeline: SDK → Collector → backends&lt;/h2>
&lt;p>Three layers, each with its own responsibility:&lt;/p>
&lt;h3 id="1--the-sdk">1 · The SDK&lt;/h3>
&lt;p>Three dominant options in 2026:&lt;/p>
&lt;p>&lt;strong>OpenLLMetry (Traceloop)&lt;/strong> — the most widespread. It automatically instruments the OpenAI Python SDK, the Anthropic SDK, LangChain, LlamaIndex, Haystack, Cohere, Mistral, vLLM and almost any library in the ecosystem. A single line (&lt;code>Traceloop.init()&lt;/code>) instruments everything. Apache 2.0 licence. It maintains its own fork with extensions that are not yet in OTel core, but it exports in line with the convention.&lt;/p>
&lt;p>&lt;strong>openinference (Arize)&lt;/strong> — a direct competitor, also Apache 2.0. Closer to Phoenix (same vendor) but it exports standard OTel. Better instrumentation for LangChain/LlamaIndex/DSPy in some versions; worse for vLLM directly.&lt;/p>
&lt;p>&lt;strong>Langfuse SDK&lt;/strong> — proprietary in form (the API is Langfuse&amp;rsquo;s), but underneath it emits OTel spans. The natural choice if Langfuse is the main backend. It has the best support for &amp;ldquo;session&amp;rdquo; and &amp;ldquo;user&amp;rdquo; linking, concepts that are not yet in OTel core but that Langfuse maps to &lt;code>gen_ai.conversation.id&lt;/code> for compatibility.&lt;/p>
&lt;p>Practical recommendation for May 2026: &lt;strong>OpenLLMetry if you want to stay backend-agnostic&lt;/strong> (you will change provider); &lt;strong>the Langfuse SDK if Langfuse is already your bet&lt;/strong> (you save yourself a mapping). Both produce valid spans that any Collector consumes.&lt;/p>
&lt;h3 id="2--the-otel-collector">2 · The OTel Collector&lt;/h3>
&lt;p>The Collector is the &lt;strong>most important piece&lt;/strong> of the pipeline and the least talked about. Three responsibilities:&lt;/p>
&lt;p>&lt;strong>Buffering&lt;/strong>: if Langfuse or Tempo have a problem, the Collector holds the spans in memory (or on disk with persistence enabled) and re-emits them when the backend returns.&lt;/p>
&lt;p>&lt;strong>Sampling&lt;/strong>: it applies the two sampling layers (next section) without the application knowing anything about it.&lt;/p>
&lt;p>&lt;strong>Routing&lt;/strong>: with the &lt;code>exporters&lt;/code> config it points at one or several backends at once. The usual practice is to &lt;strong>send to Langfuse + Tempo + Prometheus simultaneously&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Langfuse for the LLM-first UI (prompts, evals, user sessions).&lt;/li>
&lt;li>Tempo (or Jaeger) for the full distributed context (an LLM span inside an HTTP request that has touched 12 microservices).&lt;/li>
&lt;li>Prometheus for aggregated metrics (P95 latency per model, tokens per second, error rate).&lt;/li>
&lt;/ul>
&lt;p>A representative production fragment of &lt;code>otel-collector-config.yaml&lt;/code>:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">receivers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">otlp&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">protocols&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">grpc&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">endpoint&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">0.0.0.0&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="m">4317&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">http&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">endpoint&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">0.0.0.0&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="m">4318&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">processors&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">batch&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">timeout&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">1s&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">send_batch_size&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">1024&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">tail_sampling&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">decision_wait&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">10s&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">policies&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">errors&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">type&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">status_code&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">status_code&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{&lt;span class="w"> &lt;/span>&lt;span class="nt">status_codes&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">ERROR] }&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">slow_traces&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">type&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">latency&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">latency&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{&lt;span class="w"> &lt;/span>&lt;span class="nt">threshold_ms&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">5000&lt;/span>&lt;span class="w"> &lt;/span>}&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">name&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">head_5pct&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">type&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">probabilistic&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">probabilistic&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{&lt;span class="w"> &lt;/span>&lt;span class="nt">sampling_percentage&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">5&lt;/span>&lt;span class="w"> &lt;/span>}&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">exporters&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">otlphttp/langfuse&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">endpoint&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">https://langfuse.internal:3000/api/public/otel/v1&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">headers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{&lt;span class="w"> &lt;/span>&lt;span class="nt">Authorization&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;Basic ${LANGFUSE_AUTH}&amp;#34;&lt;/span>&lt;span class="w"> &lt;/span>}&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">otlp/tempo&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">endpoint&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">tempo:4317&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">tls&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>{&lt;span class="w"> &lt;/span>&lt;span class="nt">insecure&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kc">true&lt;/span>&lt;span class="w"> &lt;/span>}&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">prometheus&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">endpoint&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="m">0.0.0.0&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="m">8889&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">service&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">pipelines&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">traces&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">receivers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">otlp]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">processors&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">tail_sampling, batch]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">exporters&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">otlphttp/langfuse, otlp/tempo]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">metrics&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">receivers&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">otlp]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">processors&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">batch]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">exporters&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">[&lt;/span>&lt;span class="l">prometheus]&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3--the-backends">3 · The backends&lt;/h3>
&lt;p>&lt;strong>Langfuse&lt;/strong> is the dominant option for OSS LLM observability (MIT licence, complete suite: tracing + evals + prompts + datasets). Its model assumes OTel &lt;code>trace_id&lt;/code> and &lt;code>span_id&lt;/code> and draws them in the UI with the LLM context expanded (formatted messages, counted tokens, costs calculated from a model→price mapping).&lt;/p>
&lt;p>&lt;strong>Phoenix&lt;/strong> (Arize, ELv2 licence) has a more eval-first focus. Useful if your team comes from classic NLP and wants UMAP embedding visualisation by default.&lt;/p>
&lt;p>&lt;strong>LangSmith&lt;/strong> (LangChain) is proprietary, not OSS. Excellent integration with LangChain/LangGraph; less relevant if you do not use that stack.&lt;/p>
&lt;p>&lt;strong>Tempo / Jaeger&lt;/strong> show the LLM traces &lt;strong>inside the context of the distributed request&lt;/strong>. It is what you need when a customer reports that &amp;ldquo;the page takes 8 seconds&amp;rdquo; and you want to see whether those 8 seconds are the model, the retrieval or the downstream microservice.&lt;/p>
&lt;h2 id="sampling-the-two-layers-that-coexist">Sampling: the two layers that coexist&lt;/h2>
&lt;p>Without sampling, a system at 10 req/s generates about 26 million spans a month. The backend drowns, the cost explodes and most of the spans are redundant (200 similar requests tell you no more than 20).&lt;/p>
&lt;p>The canonical pattern in 2026 is &lt;strong>two combined layers&lt;/strong>:&lt;/p>
&lt;h3 id="head-based-sampling-on-the-way-in">Head-based sampling (on the way in)&lt;/h3>
&lt;p>You decide &lt;strong>before&lt;/strong> the span exists whether you are going to trace it or not, based on a probabilistic decision (1-5 % typically) or on a deterministic rule (always trace if the user is premium, if the model is the new one in canary, and so on).&lt;/p>
&lt;p>Pros: cheap (the span is not generated at all), deterministic.&lt;/p>
&lt;p>Cons: &lt;strong>you can miss infrequent errors&lt;/strong>. If an error happens once in every 1,000 and you trace 1 %, you will see it once in every 100,000, which is no longer debuggable.&lt;/p>
&lt;h3 id="tail-based-sampling-on-the-way-out">Tail-based sampling (on the way out)&lt;/h3>
&lt;p>The complete span is generated and at the end you decide whether to keep it or throw it away. The decision can be:&lt;/p>
&lt;ul>
&lt;li>Keep 100 % of errors.&lt;/li>
&lt;li>Keep 100 % of traces with latency &amp;gt; X ms.&lt;/li>
&lt;li>Keep 100 % of traces that triggered a guardrail.&lt;/li>
&lt;li>Keep a random sample of the rest (1-5 %).&lt;/li>
&lt;/ul>
&lt;p>Pros: it guarantees that you see the errors and the latency outliers. Without it, the most interesting problems are the ones most likely to be left out.&lt;/p>
&lt;p>Cons: you need a buffer, because until the trace finishes you cannot decide. The Collector&amp;rsquo;s &lt;code>tail_sampling&lt;/code> processor keeps the spans in memory for 5-30 seconds until it takes the decision.&lt;/p>
&lt;p>The practical rule in 2026 is to &lt;strong>combine both&lt;/strong>: head-based at 5 % + tail-based capturing 100 % of errors and latencies &amp;gt; 5s. That gives you around 5 % of baseline traffic plus 100 % of what is interesting.&lt;/p>
&lt;h2 id="anatomy-of-a-real-trace">Anatomy of a real trace&lt;/h2>
&lt;p>We are going to take apart the trace of a single user question to a typical chat-with-RAG-and-tool system. The question is &amp;ldquo;what is the balance of my main account?&amp;rdquo;.&lt;/p>
&lt;div class="diagram" style="max-width:760px;margin:1.5rem auto;">
&lt;svg viewBox="0 0 760 360" xmlns="http://www.w3.org/2000/svg" role="img" aria-label="Anatomy of a complete LLM trace">
&lt;style>
.tr{fill:#f4f4f4;stroke:#999;stroke-width:1}
.s1{fill:#d6eaff;stroke:#222;stroke-width:1}
.s2{fill:#ffe9d6;stroke:#222;stroke-width:1}
.s3{fill:#d9f5d6;stroke:#222;stroke-width:1}
.s4{fill:#fff5b0;stroke:#222;stroke-width:1}
.s5{fill:#e9d6f5;stroke:#222;stroke-width:1}
.lb{font:600 11px sans-serif;fill:#222}
.sm{font:400 10px sans-serif;fill:#444}
.h{font:700 13px sans-serif;fill:#222}
.tm{font:400 10px sans-serif;fill:#888}
&lt;/style>
&lt;text x="380" y="20" text-anchor="middle" class="h">Trace_id = abc123 · "what is the balance of my main account?"&lt;/text>
&lt;text x="380" y="38" text-anchor="middle" class="tm">total duration: 2,847 ms · 7 spans · 1 trace&lt;/text>
&lt;line x1="60" y1="55" x2="700" y2="55" stroke="#ccc"/>
&lt;text x="60" y="68" class="tm">0 ms&lt;/text>
&lt;text x="700" y="68" text-anchor="end" class="tm">2847 ms&lt;/text>
&lt;rect x="60" y="80" width="640" height="22" class="s1"/>
&lt;text x="70" y="96" class="lb">HTTP POST /chat — root span (app)&lt;/text>
&lt;rect x="80" y="112" width="100" height="20" class="s2"/>
&lt;text x="86" y="126" class="sm">guardrail.input · 38ms&lt;/text>
&lt;rect x="190" y="112" width="220" height="20" class="s3"/>
&lt;text x="196" y="126" class="sm">rag.retrieve · 218ms · BGE-M3 + Qdrant&lt;/text>
&lt;rect x="190" y="136" width="80" height="18" class="s3" opacity="0.7"/>
&lt;text x="195" y="149" class="sm">embed · 28ms&lt;/text>
&lt;rect x="280" y="136" width="125" height="18" class="s3" opacity="0.7"/>
&lt;text x="285" y="149" class="sm">vector_search · 80ms&lt;/text>
&lt;rect x="420" y="112" width="280" height="20" class="s4"/>
&lt;text x="426" y="126" class="lb">gen_ai.chat · 2104ms · llama-3.1-70b-instruct&lt;/text>
&lt;rect x="510" y="136" width="80" height="18" class="s5" opacity="0.85"/>
&lt;text x="515" y="149" class="sm">tool.get_balance · 60ms&lt;/text>
&lt;rect x="600" y="112" width="60" height="20" class="s2"/>
&lt;text x="606" y="126" class="sm">guardrail.output · 28ms&lt;/text>
&lt;line x1="60" y1="170" x2="700" y2="170" stroke="#ccc"/>
&lt;text x="60" y="190" class="h">Key attributes per span&lt;/text>
&lt;text x="60" y="208" class="sm">root: &lt;tspan font-family="monospace">http.method=POST, user.id=42, conversation.id=session_abc&lt;/tspan>&lt;/text>
&lt;text x="60" y="224" class="sm">guardrail.input: &lt;tspan font-family="monospace">gen_ai.tool.name=llm_guard, gen_ai.tool.type=guardrail, gen_ai.guardrail.decision=allow&lt;/tspan>&lt;/text>
&lt;text x="60" y="240" class="sm">rag.retrieve: &lt;tspan font-family="monospace">gen_ai.operation.name=embeddings, gen_ai.request.model=bge-m3, db.system=qdrant&lt;/tspan>&lt;/text>
&lt;text x="60" y="256" class="sm">vector_search: &lt;tspan font-family="monospace">db.operation=query, db.collection=docs_prod, db.qdrant.top_k=20, db.qdrant.score=0.83&lt;/tspan>&lt;/text>
&lt;text x="60" y="272" class="sm">gen_ai.chat: &lt;tspan font-family="monospace">gen_ai.system=vllm, request.model=llama-3.1-70b, usage.input=1247, usage.output=412&lt;/tspan>&lt;/text>
&lt;text x="60" y="288" class="sm"> prompt.id=customer_support_v3, prompt.version=14, prompt.label=production&lt;/text>
&lt;text x="60" y="304" class="sm">tool.get_balance: &lt;tspan font-family="monospace">gen_ai.tool.name=get_balance, gen_ai.tool.type=function, gen_ai.tool.call.id=call_xy&lt;/tspan>&lt;/text>
&lt;text x="60" y="320" class="sm">guardrail.output: &lt;tspan font-family="monospace">gen_ai.tool.name=llama_guard_4, gen_ai.guardrail.decision=allow&lt;/tspan>&lt;/text>
&lt;text x="60" y="344" class="sm" font-style="italic">All the spans share trace_id=abc123. Langfuse draws them as a tree; Tempo as a flat timeline.&lt;/text>
&lt;/svg>
&lt;/div>
&lt;p>Seven spans, one single trace. The information you can exploit:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Latency broken down&lt;/strong>: 38 ms guardrail + 218 ms retrieval + 2104 ms LLM + 60 ms tool + 28 ms guardrail = 2,448 ms (the rest is orchestration overhead). The bottleneck is the LLM (74 % of the time). If the user complains about slowness, you know where to look.&lt;/li>
&lt;li>&lt;strong>Tokens and cost&lt;/strong>: 1,247 input + 412 output. With Llama 3.1 70B on-prem at about 12 W/token of equivalent energy cost, roughly 3.5 c€ per response. Multiplied by volume, that gives you the inference bill.&lt;/li>
&lt;li>&lt;strong>&lt;code>prompt.id+version&lt;/code> travelling along&lt;/strong>: if in a month&amp;rsquo;s time you notice that quality has dropped, you filter by &lt;code>prompt.version&lt;/code> and see whether it coincides with a change to the prompt.&lt;/li>
&lt;li>&lt;strong>Guardrail decisions traced&lt;/strong>: if a guardrail blocked the response, it stays in the trace with &lt;code>gen_ai.guardrail.decision=block&lt;/code> and a reason. ENS audit satisfied.&lt;/li>
&lt;li>&lt;strong>Correlated tool calls&lt;/strong>: &lt;code>tool.get_balance&lt;/code> is a child span of &lt;code>gen_ai.chat&lt;/code>. If the tool failed, you see the error directly in its span; it does not turn up only in separate logs.&lt;/li>
&lt;/ul>
&lt;h2 id="implications-for-on-premise-hardware">Implications for on-premise hardware&lt;/h2>
&lt;p>Tracing is not free, but its overhead, properly sized, is negligible.&lt;/p>
&lt;h3 id="cost-per-span">Cost per span&lt;/h3>
&lt;p>At the SDK level, an LLM span adds around 50-200 µs of overhead (creation, attributes, serialisation). For an LLM call lasting 2 seconds, that is &amp;lt; 0.01 % of the latency.&lt;/p>
&lt;p>At the network level, a typical compressed OTLP span weighs around 1-3 KB. For a system at 100 req/s with 7 spans per request, that is 700 spans/s × 2 KB ≈ 1.4 MB/s to the Collector. Trivial.&lt;/p>
&lt;h3 id="storage">Storage&lt;/h3>
&lt;p>This is where the money goes. Without sampling, a month at 100 req/s is about 18 GB of spans. With head-based at 5 % + tail-based on errors, about 1-2 GB a month. Manageable in any self-hosted ClickHouse or Loki.&lt;/p>
&lt;h3 id="on-an-rtx-4090-24-gb--collector-and-langfuse-on-prem">On an RTX 4090 (24 GB) + Collector and Langfuse on-prem&lt;/h3>
&lt;p>For a demo service or a small single-tenant: Langfuse + Postgres + Clickhouse + Collector on the same host as the model. It uses around 8 GB of RAM and &amp;lt; 1 % of CPU continuously. The 4090 serves the model, the rest lives on the CPU. Minimum viable setup for a startup or a small team.&lt;/p>
&lt;h3 id="on-a-generic-4h100-sxm-cluster--central-observability">On a generic 4×H100 SXM cluster + central observability&lt;/h3>
&lt;p>A dedicated pod for the OTel Collector (a DaemonSet on each node + a central Gateway). Langfuse + ClickHouse + Tempo + Prometheus + Grafana in an &lt;code>observability&lt;/code> namespace separate from the &lt;code>serving&lt;/code> namespace. This is the canonical architecture of any serious ENS/NIS2 production deployment: observability does not share resources with the model.&lt;/p>
&lt;h2 id="what-we-have-not-covered-upcoming-articles">What we have not covered (upcoming articles)&lt;/h2>
&lt;ul>
&lt;li>&lt;strong>LLM metrics (Prometheus): the canonical counters and histograms&lt;/strong> — &lt;code>gen_ai_client_request_duration_seconds&lt;/code>, &lt;code>gen_ai_client_input_tokens_total&lt;/code> and the rest. How Grafana dashboards are built on that base.&lt;/li>
&lt;li>&lt;strong>Guardrails as spans&lt;/strong>: how to model Llama Guard 4, NeMo Guardrails and LLM Guard as child spans of the LLM span, and what attributes they carry. Covered in the &lt;a href="https://blog.lo0.es/en/posts/llm-guardrails-safety-four-lines-of-defence/">post on guardrails&lt;/a> — attributes &lt;code>gen_ai.guardrail.line&lt;/code>, &lt;code>gen_ai.guardrail.detector&lt;/code>, &lt;code>gen_ai.guardrail.category&lt;/code>, &lt;code>gen_ai.guardrail.score&lt;/code>, &lt;code>gen_ai.guardrail.action&lt;/code>.&lt;/li>
&lt;li>&lt;strong>Distributed tracing with MCP&lt;/strong> — &lt;code>traceparent&lt;/code> propagation from the LLM client to the MCP server, &lt;code>mcp.*&lt;/code> attributes, known problems.&lt;/li>
&lt;li>&lt;strong>eBPF for automatic tracing without an SDK&lt;/strong> — Tetragon and Hubble extracting LLM traces without explicit instrumentation, for cases where the code cannot be modified.&lt;/li>
&lt;/ul>
&lt;h2 id="see-also">See also&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/prompt-versioning-contract-five-word-change/">Prompt versioning with Langfuse and MLflow&lt;/a> — the &lt;code>prompt_id@version&lt;/code> that travels as &lt;code>gen_ai.prompt.id&lt;/code> in the spans described here.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/evals-llm-layer-after-tracing/">Evals for LLMs: the layer after tracing&lt;/a> — the &amp;ldquo;the judge runs over a sample of the traces&amp;rdquo; pattern rests on this pipeline.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/llm-as-judge-exam-marker-not-oracle/">LLM-as-judge: the exam marker&lt;/a> — the judge consumes traces to evaluate quality continuously. The traces kept by tail-sampling are its input.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/continuous-fine-tuning-production-real-traffic-deployed-adapter/">Continuous fine-tuning in production&lt;/a> — traces are the origin of the fine-tuning dataset. When a user regenerates, that span with &lt;code>gen_ai.response.finish_reasons=[&amp;quot;stop&amp;quot;]&lt;/code> rejected enters the DPO pipeline.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/six-stage-llmops-pipeline-architecture-and-deep-dive/">The six-stage LLMOps pipeline&lt;/a> — the master map where OBSERVE is stage 5.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/llm-guardrails-safety-four-lines-of-defence/">Guardrails and safety in LLMs&lt;/a> — the online safety layer whose decisions are modelled as child spans of the LLM span with &lt;code>gen_ai.guardrail.*&lt;/code> attributes. The traceability of every block / redact / flag is the basis for ENS / NIS2 / EU AI Act audits.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/llm-guard-anatomy-scanners-langfuse-vllm-litellm/">LLM Guard: anatomy and integration with Langfuse&lt;/a> — the concrete tool whose OTel HTTP export described in this post closes the circle: &lt;code>gen_ai.guardrail.*&lt;/code> spans for each scanner executed, ingestable directly by Langfuse via &lt;code>/api/public/otel&lt;/code>.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/iso-42001-aims-on-premise-llm-platform/">ISO/IEC 42001: the operations manual for the AI system&lt;/a> — the OTel + Langfuse tracing described here materialises control A.8 (information to interested parties) of Annex A: per-request traceability, forensic reporting capability and incident notification to users and regulators.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/eu-ai-act-technical-dossier-on-premise-llm-architecture/">EU AI Act: the technical file article by article&lt;/a> — the OTel traceability described here is the canonical materialisation of Arts. 12 + 19 (record-keeping and automatic logs) of the Regulation; a minimum retention of 6 months + WORM + redacted PII are the explicit legal requirements.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/technical-controls-ens-iso-42001-eu-ai-act-cross-mapping/">Technical controls ENS × 42001 × EU AI Act&lt;/a> — OTel &lt;code>gen_ai.*&lt;/code> spans with the right metadata satisfy &lt;code>op.exp.8 + .10&lt;/code> ENS + A.8.2 ISO 42001 + Arts. 12 + 19 AI Act &lt;strong>in a single piece&lt;/strong> when they are labelled with a common vocabulary.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/gpu-observability-llm-inference-twelve-dcgm-vllm-metrics/">GPU observability for LLM inference&lt;/a> — the other half of LLM observability: the DCGM (hardware) and vLLM (engine) metrics complement the semantic tracing of &lt;code>gen_ai.*&lt;/code> to cover the questions &amp;ldquo;is the GPU healthy?&amp;rdquo; and &amp;ldquo;is it meeting the SLO?&amp;rdquo;.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/langfuse-inside-sorting-centre-bottleneck/">Inside Langfuse: v3 architecture and the 10 backend knobs&lt;/a> — here Langfuse is the destination of the pipeline; there the box is opened: the six services (Web, Worker, Postgres, ClickHouse, Redis, S3), asynchronous ingestion and self-hosted tuning. The two-layer sampling in this post is the &amp;ldquo;knob 0&amp;rdquo; that multiplies the ten in that one.&lt;/li>
&lt;li>&lt;a href="https://blog.lo0.es/en/posts/langfuse-v4-what-goes-into-a-trace/">Langfuse v4: what goes into a trace&lt;/a> — the precedence chain with which a real backend resolves these attributes, and the scores that do not travel over OTLP.&lt;/li>
&lt;/ul>
&lt;h2 id="references">References&lt;/h2>
&lt;ul>
&lt;li>OpenTelemetry GenAI Semantic Conventions: &lt;a href="https://opentelemetry.io/docs/specs/semconv/gen-ai/">https://opentelemetry.io/docs/specs/semconv/gen-ai/&lt;/a>.&lt;/li>
&lt;li>OpenLLMetry (Traceloop): &lt;a href="https://github.com/traceloop/openllmetry">https://github.com/traceloop/openllmetry&lt;/a>.&lt;/li>
&lt;li>openinference (Arize): &lt;a href="https://github.com/Arize-ai/openinference">https://github.com/Arize-ai/openinference&lt;/a>.&lt;/li>
&lt;li>Langfuse OTel integration: &lt;a href="https://langfuse.com/docs/opentelemetry/get-started">https://langfuse.com/docs/opentelemetry/get-started&lt;/a>.&lt;/li>
&lt;li>OTel Collector tail-sampling processor: &lt;a href="https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor">https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/processor/tailsamplingprocessor&lt;/a>.&lt;/li>
&lt;li>Phoenix (Arize) docs: &lt;a href="https://docs.arize.com/phoenix">https://docs.arize.com/phoenix&lt;/a>.&lt;/li>
&lt;li>Model Context Protocol observability (&lt;code>mcp.*&lt;/code> semconv): &lt;a href="https://modelcontextprotocol.io/docs/observability">https://modelcontextprotocol.io/docs/observability&lt;/a>.&lt;/li>
&lt;/ul></description></item></channel></rss>