<?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: Nirmana Herath</title>
    <description>The latest articles on DEV Community by Nirmana Herath (@nirmana11).</description>
    <link>https://dev.to/nirmana11</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%2F4258413%2F007c811e-53bf-4e06-9f9f-2868c973b448.jpg</url>
      <title>DEV Community: Nirmana Herath</title>
      <link>https://dev.to/nirmana11</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nirmana11"/>
    <language>en</language>
    <item>
      <title>How I Built an Automated LLM Evaluation Harness to Eliminate AI Math Hallucinations on CSVs</title>
      <dc:creator>Nirmana Herath</dc:creator>
      <pubDate>Sun, 22 Nov 2026 07:49:16 +0000</pubDate>
      <link>https://dev.to/nirmana11/how-i-built-an-automated-llm-evaluation-harness-to-eliminate-ai-math-hallucinations-on-csvs-4le0</link>
      <guid>https://dev.to/nirmana11/how-i-built-an-automated-llm-evaluation-harness-to-eliminate-ai-math-hallucinations-on-csvs-4le0</guid>
      <description>&lt;p&gt;Update (v1.0.0 is LIVE!): You can now try AskGrid free (zero signup, 1-click sample dataset) at &lt;a href="https://askgrid.pages.dev/" rel="noopener noreferrer"&gt;AskGrid&lt;/a&gt; — or check out the full source code on &lt;a href="https://github.com/niRmana11/askgrid" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem With "Chat With Your CSV" Apps
&lt;/h3&gt;

&lt;p&gt;Most AI spreadsheet tools do one of two scary things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Paste your private CSV rows directly into an LLM prompt and &lt;strong&gt;pray it doesn't hallucinate the math&lt;/strong&gt;, or&lt;/li&gt;
&lt;li&gt;Let the LLM write arbitrary Python code and run &lt;code&gt;exec()&lt;/code&gt; on the server — a massive Remote Code Execution (RCE) risk.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While building &lt;strong&gt;AskGrid&lt;/strong&gt; (&lt;em&gt;"Don't Scroll, Just Ask."&lt;/em&gt;) solo on a \$0 budget with Python 3.12, FastAPI, Pydantic v2, and Pandas, I locked down &lt;strong&gt;two non-negotiable rules&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zero raw rows ever go to the LLM&lt;/strong&gt; (only column names + inferred data types).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Zero LLM math and zero &lt;code&gt;exec()&lt;/code&gt;&lt;/strong&gt; — the LLM's &lt;em&gt;only&lt;/em&gt; job is to act as a &lt;strong&gt;Natural-Language Intent Router&lt;/strong&gt;, outputting a strict Pydantic JSON &lt;code&gt;AnalysisIntent&lt;/code&gt;. Deterministic Pandas code executes 10 allowlisted operations and returns a &lt;code&gt;"How this was calculated"&lt;/code&gt; audit trail.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  The Architecture: LLM-as-Router + Deterministic Execution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Question ("Top 3 customers by spend in Colombo?")
        │
        ▼
[Schema-Only Prompt]  ──▶  Gemini Flash-Lite (temperature=0.0, Pydantic Structured Output)
        │                  (sees ONLY {column: type} — ZERO row values!)
        ▼
AnalysisIntent JSON   ──▶  Allowlist Validator (blocks fake columns, bad dtypes, n &amp;gt; 50)
        │
        ▼
Deterministic Pandas  ──▶  Exact Result + ChartSpec + CalculationAudit ("How it was calculated")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To handle real-world cloud flakiness on a free tier, I put Gemini behind a provider-agnostic Python &lt;code&gt;Protocol&lt;/code&gt; (&lt;code&gt;AIProvider&lt;/code&gt;) with a &lt;strong&gt;5-model fallback chain&lt;/strong&gt; and a lightweight &lt;strong&gt;Circuit Breaker&lt;/strong&gt; that skips models returning &lt;code&gt;503&lt;/code&gt; / &lt;code&gt;429&lt;/code&gt; / transport timeouts during a cooldown window.&lt;/p&gt;




&lt;h3&gt;
  
  
  3 Real Bugs My Golden Dataset &amp;amp; Eval Harness Caught
&lt;/h3&gt;

&lt;p&gt;You don't appreciate automated tests and eval harnesses until they save you in real life. Mine caught &lt;strong&gt;three sneaky bugs&lt;/strong&gt; before a single user ever touched the UI:&lt;/p&gt;

&lt;h4&gt;
  
  
  1. The Currency Regex That Ate Order IDs (&lt;code&gt;ORD-1011&lt;/code&gt; → &lt;code&gt;-1011&lt;/code&gt;)
&lt;/h4&gt;

&lt;p&gt;My CSV parser cleans currency strings like &lt;code&gt;LKR 125,000.00&lt;/code&gt; into floats. My first regex matched &lt;code&gt;[A-Za-z]{1,5}\s*-?\d+&lt;/code&gt; — which accidentally matched &lt;code&gt;"ORD-1011"&lt;/code&gt; as negative currency &lt;code&gt;-1011&lt;/code&gt;!&lt;br&gt;&lt;br&gt;
Golden test &lt;code&gt;Q08&lt;/code&gt; caught it immediately. I tightened the regex to require real currency symbols or known currency codes + space, and added a regression test.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. The &lt;code&gt;httpx2.ReadTimeout&lt;/code&gt; That Escaped My Circuit Breaker
&lt;/h4&gt;

&lt;p&gt;My Gemini adapter caught &lt;code&gt;(ServerError, ClientError, ValueError)&lt;/code&gt;. During a live eval run, a slow free-tier response threw &lt;code&gt;httpx2.ReadTimeout&lt;/code&gt; — which isn't a subclass of &lt;code&gt;ServerError&lt;/code&gt;! Widening the fallback catch inside the model loop fixed it so network timeouts cleanly trip the Circuit Breaker and route to the next healthy Flash pool.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. Prompt &lt;code&gt;v1.0&lt;/code&gt; → &lt;code&gt;v1.1&lt;/code&gt;: Why "Looks Good in Swagger" Isn't Enough
&lt;/h4&gt;

&lt;p&gt;I built an end-to-end eval harness (&lt;code&gt;server/evals/run_evals.py&lt;/code&gt;) that runs &lt;strong&gt;18 synthetic golden cases&lt;/strong&gt; (15 computable questions across all 10 operations + 3 safety/refusal/prompt-injection cases) all the way from plain English → live Gemini → validator → Pandas → exact ground-truth number assertion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First run (&lt;code&gt;PROMPT_VERSION = "v1.0"&lt;/code&gt;):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Intent Accuracy: &lt;code&gt;17/18&lt;/code&gt; (&lt;strong&gt;94.4%&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;E2E Numerical Exact: &lt;code&gt;14/15&lt;/code&gt; (&lt;strong&gt;93.3%&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;Safety &amp;amp; Prompt Injection: &lt;code&gt;3/3&lt;/code&gt; (&lt;strong&gt;100.0%&lt;/strong&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why did &lt;code&gt;Q07&lt;/code&gt; (&lt;em&gt;"Who are the top 3 customers by spend in Colombo?"&lt;/em&gt;) fail? Gemini got the filter, column, and grouping right — &lt;strong&gt;but&lt;/strong&gt; picked &lt;code&gt;group_aggregate&lt;/code&gt; (returning all 4 Colombo customers) instead of &lt;code&gt;top_n(n=3)&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix (&lt;code&gt;PROMPT_VERSION = "v1.1"&lt;/code&gt;):&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
I added one explicit disambiguation rule separating &lt;code&gt;top_n&lt;/code&gt; (ranked/limited questions) from &lt;code&gt;group_aggregate&lt;/code&gt; (all groups) and re-ran the full suite:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Prompt &lt;code&gt;v1.0&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;Prompt &lt;code&gt;v1.1&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Intent Accuracy&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;17/18 (94.4%)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;18/18 (100.0%)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;E2E Exact Pandas Math&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;14/15 (93.3%)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;15/15 (100.0%)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Safety &amp;amp; Refusals (incl. Prompt Injection)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;3/3 (100.0%)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3/3 (100.0%)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Median Latency (p50)&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;1.74s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;1.17s&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq70fb6te2iw7che43xzb.png" alt=" " width="799" height="237"&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What's Next
&lt;/h3&gt;

&lt;p&gt;The entire Python + AI backend (&lt;code&gt;v0.3.0&lt;/code&gt;) is now live on GitHub with &lt;code&gt;ruff&lt;/code&gt;, strict &lt;code&gt;mypy&lt;/code&gt;, &lt;code&gt;pytest&lt;/code&gt; (23 offline CI tests), &lt;code&gt;pip-audit&lt;/code&gt;, and Gitleaks secret scanning. Next up: building the &lt;strong&gt;React + TypeScript + Tailwind CSS&lt;/strong&gt; interactive workspace UI!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Follow the build in public on X:&lt;/strong&gt; &lt;code&gt;https://x.com/niRmana_dev&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>python</category>
      <category>fastapi</category>
      <category>buildinpublic</category>
    </item>
  </channel>
</rss>
