<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Franklin Alejandro Bonalde</title>
    <description>The latest articles on DEV Community by Franklin Alejandro Bonalde (@technobonal).</description>
    <link>https://dev.to/technobonal</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4269144%2F54985a54-eaa1-4e88-8834-02500e797ba0.jpg</url>
      <title>DEV Community: Franklin Alejandro Bonalde</title>
      <link>https://dev.to/technobonal</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/technobonal"/>
    <language>en</language>
    <item>
      <title>Building a Root Cause Analysis Agent with RAG — and the first thing that broke</title>
      <dc:creator>Franklin Alejandro Bonalde</dc:creator>
      <pubDate>Fri, 27 Nov 2026 14:25:50 +0000</pubDate>
      <link>https://dev.to/technobonal/building-a-root-cause-analysis-agent-with-rag-and-the-first-thing-that-broke-2k2</link>
      <guid>https://dev.to/technobonal/building-a-root-cause-analysis-agent-with-rag-and-the-first-thing-that-broke-2k2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I'm Frank Bonalde, an AI Engineer based in São Paulo. I build agentic systems and RAG applications. This is a write-up of one of my projects — what it does, how I measured it, and the first thing that broke. Portfolio: &lt;a href="https://technobonal.github.io" rel="noopener noreferrer"&gt;https://technobonal.github.io&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;In logistics operations, when something fails — a delayed shipment, a sync error, a stuck order — an operator usually has to dig through past incident reports and runbooks by hand to figure out the cause. It's slow, and the knowledge lives in people's heads.&lt;/p&gt;

&lt;p&gt;I wanted an assistant where the operator describes the symptom in plain language and gets back something they can actually act on: the likely &lt;strong&gt;root cause&lt;/strong&gt;, a recommended &lt;strong&gt;fix&lt;/strong&gt;, a &lt;strong&gt;confidence level&lt;/strong&gt;, and the &lt;strong&gt;evidence&lt;/strong&gt; behind it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The stack
&lt;/h2&gt;

&lt;p&gt;I kept it deliberately simple and production-friendly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Streamlit&lt;/strong&gt; — front end, fast to iterate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LangChain&lt;/strong&gt; — agent orchestration.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Groq&lt;/strong&gt; running &lt;code&gt;openai/gpt-oss-120b&lt;/code&gt; — fast inference.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cohere&lt;/strong&gt; multilingual embeddings — operators write in Spanish and Portuguese, not just English.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pinecone&lt;/strong&gt; — vector store built from the incident documentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The core idea: never let the model answer from thin air. Every answer is anchored to retrieved chunks, and each piece of evidence is shown with its &lt;strong&gt;source&lt;/strong&gt; and &lt;strong&gt;relevance score&lt;/strong&gt;, so the user can verify instead of trusting blindly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Structured output, on purpose
&lt;/h2&gt;

&lt;p&gt;Instead of free-form text, I forced the agent to return a structured object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# The agent must return this shape, not prose.&lt;/span&gt;
&lt;span class="c1"&gt;# Structured output makes every answer checkable the same way.&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"root_cause"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"…"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;# the most likely cause, one statement&lt;/span&gt;
    &lt;span class="s2"&gt;"solution"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"…"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;        &lt;span class="c1"&gt;# recommended fix&lt;/span&gt;
    &lt;span class="s2"&gt;"confidence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;# how sure the agent is (0–1)&lt;/span&gt;
    &lt;span class="s2"&gt;"evidence"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;           &lt;span class="c1"&gt;# retrieved chunks that support the answer&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"runbook_42.md"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"relevance"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.81&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"text"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"…"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This one decision paid off everywhere: it made the UI predictable, and it made the output &lt;strong&gt;measurable&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I measured quality
&lt;/h2&gt;

&lt;p&gt;With structured output, evaluation becomes concrete. I ran known incidents through the agent and checked two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Retrieval&lt;/strong&gt; — did the right documents come back for the symptom?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Root cause match&lt;/strong&gt; — did the reported cause match the real one?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's not a formal benchmark yet, but it's enough to catch regressions and, more importantly, to see &lt;em&gt;where&lt;/em&gt; the system is weak instead of guessing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The first thing that broke: confidence
&lt;/h2&gt;

&lt;p&gt;Here's the interesting part. The first thing that broke wasn't retrieval or the model's reasoning — it was the &lt;strong&gt;confidence score&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The model happily reported &lt;strong&gt;high confidence even when the retrieved evidence was weak&lt;/strong&gt;. A barely-relevant chunk, and it would still say "0.9". That's the worst kind of failure in a tool meant to be trusted: confidently wrong.&lt;/p&gt;

&lt;p&gt;The root of it: I was letting the model self-report a single confidence number that silently mixed two very different things — &lt;em&gt;how sure the model feels&lt;/em&gt; and &lt;em&gt;how good the evidence actually is&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix
&lt;/h3&gt;

&lt;p&gt;I separated the two signals and showed both:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Model confidence and retrieval relevance are NOT the same thing.&lt;/span&gt;
&lt;span class="c1"&gt;# Keeping them separate stops a confident model from hiding weak evidence.&lt;/span&gt;
&lt;span class="n"&gt;model_confidence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"confidence"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;          &lt;span class="c1"&gt;# what the model claims&lt;/span&gt;
&lt;span class="n"&gt;evidence_strength&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"relevance"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# what retrieval found&lt;/span&gt;

&lt;span class="c1"&gt;# If the evidence is weak, the user sees it immediately —&lt;/span&gt;
&lt;span class="c1"&gt;# regardless of how sure the model sounds.&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;evidence_strength&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;show_warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Low-evidence answer — verify before acting."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when the evidence is weak, the user sees it right away. The model's self-assurance can no longer paper over a thin retrieval.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lessons
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Structure first.&lt;/strong&gt; Forcing a structured answer made everything downstream — UI, evaluation, debugging — easier.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separate your signals.&lt;/strong&gt; A single "confidence" number that blends model certainty and evidence quality will lie to you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Show the evidence.&lt;/strong&gt; Letting users see sources and relevance turns a black box into a tool people trust.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;Formal retrieval metrics (Recall@k, MRR) and citations quoted word-for-word from the source documents, so a user can jump straight to the sentence that backs each claim.&lt;/p&gt;




&lt;p&gt;If you're working on RAG or agentic systems, I'd love to compare notes.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Portfolio:&lt;/strong&gt; &lt;a href="https://technobonal.github.io" rel="noopener noreferrer"&gt;https://technobonal.github.io&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/technobonal" rel="noopener noreferrer"&gt;https://github.com/technobonal&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;LinkedIn:&lt;/strong&gt; &lt;a href="https://www.linkedin.com/in/franklinalejandrobonaldeai/" rel="noopener noreferrer"&gt;https://www.linkedin.com/in/franklinalejandrobonaldeai/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>rag</category>
      <category>python</category>
      <category>machinelearning</category>
    </item>
  </channel>
</rss>
