<?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: Kshitij Dubey</title>
    <description>The latest articles on DEV Community by Kshitij Dubey (@kshitij_dubey_380f7d1e26b).</description>
    <link>https://dev.to/kshitij_dubey_380f7d1e26b</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3644287%2F37b3625f-0b89-4a65-b11e-1b22470f0429.png</url>
      <title>DEV Community: Kshitij Dubey</title>
      <link>https://dev.to/kshitij_dubey_380f7d1e26b</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kshitij_dubey_380f7d1e26b"/>
    <language>en</language>
    <item>
      <title>Building a Hallucination-Proof Analytics Agent with Google’s ADK</title>
      <dc:creator>Kshitij Dubey</dc:creator>
      <pubDate>Fri, 05 Dec 2025 16:03:58 +0000</pubDate>
      <link>https://dev.to/kshitij_dubey_380f7d1e26b/building-a-hallucination-proof-analytics-agent-with-googles-adk-19he</link>
      <guid>https://dev.to/kshitij_dubey_380f7d1e26b/building-a-hallucination-proof-analytics-agent-with-googles-adk-19he</guid>
      <description>&lt;h2&gt;
  
  
  The "Trusted Analyst" Problem
&lt;/h2&gt;

&lt;p&gt;We’ve all seen the flashy demos: &lt;em&gt;"Upload a CSV, ask a question, get a chart."&lt;/em&gt; It looks like magic.&lt;/p&gt;

&lt;p&gt;But in an enterprise environment, "magic" is dangerous. If a CEO asks, &lt;em&gt;"What was our Q3 revenue?"&lt;/em&gt; and the AI hallucinates a number because it wrote bad SQL or misread a column header, that’s not a bug—it’s a liability.&lt;/p&gt;

&lt;p&gt;For my Google AI Agents Capstone, I didn't want to build just another chatbot. I wanted to build a &lt;strong&gt;Cyber-Physical System for Data&lt;/strong&gt;: an agent that is secure, deterministic, and self-correcting.&lt;/p&gt;

&lt;p&gt;Meet &lt;strong&gt;ECIA (Enterprise CSV Intelligence Agent)&lt;/strong&gt;, a multi-agent system that separates "thinking" from "doing" to guarantee accurate insights.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Architecture: A 6-Agent Assembly Line&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Most beginners build a single "Super Agent" with 20 tools. This confuses the LLM. Instead, I used the &lt;strong&gt;Google Agent Development Kit (ADK)&lt;/strong&gt; to build a sequential assembly line. Think of it like a real data team:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Router (Manager):&lt;/strong&gt; Understands if you want a chart, a summary, or a statistical test.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Data Prep (Junior Analyst):&lt;/strong&gt; Sanitizes inputs and fuzzy-matches column names (so "rev" maps to "Total_Revenue").&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Analyst (Statistician):&lt;/strong&gt; crunches the numbers using &lt;em&gt;deterministic&lt;/em&gt; tools—no random Python execution allowed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Chart Specialist (Designer):&lt;/strong&gt; Decides if this data needs a Bar Chart, a Funnel, or a Heatmap.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Visualizer (Frontend Dev):&lt;/strong&gt; Generates the actual Plotly code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Evaluator (QA Lead):&lt;/strong&gt; A separate agent that critiques the output before showing it to the user. "Did we actually answer the question?"&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Visualizing the Flow&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;USER QUERY: "What are the top 5 products by revenue?"
                            │
                            ▼
┌──────────────────────────────────────────────────────────────────┐
│  AGENT 1: QueryUnderstanding (Router)                            │
│  ────────────────────────────────────────────────────────────────│
│  • Semantic intent classification                                │
│  • Entity extraction (columns, metrics, filters)                 │
│  • Query complexity assessment                                   │
│  TOOL: extract_entities_logic()                                  │
└──────────────────────────────────────────────────────────────────┘
                            │
                            ▼
┌──────────────────────────────────────────────────────────────────┐
│  AGENT 2: DataPrep (Data Loader)                                 │
│  ────────────────────────────────────────────────────────────────│
│  • Schema validation against extracted entities                  │
│  • Fuzzy column name matching (handles typos)                    │
│  • Loads DataFrame into SessionContext                           │
│  TOOL: prepare_data_logic()                                      │
└──────────────────────────────────────────────────────────────────┘
                            │
                            ▼
┌──────────────────────────────────────────────────────────────────┐
│  AGENT 3: DataAnalysis (Statistical Analyst)                     │
│  ────────────────────────────────────────────────────────────────│
│  • Pattern matching: ranking, aggregation, trends, correlation   │
│  • Intelligent chart type selection                              │
│  • Semantic column mapping ("Region" → "Country")                │
│  TOOL: perform_analysis_logic()                                  │
└──────────────────────────────────────────────────────────────────┘
                            │
                            ▼
┌──────────────────────────────────────────────────────────────────┐
│  AGENT 4: DataViz (Visualization Architect)                      │
│  ────────────────────────────────────────────────────────────────│
│  • 12+ chart types (bar, line, scatter, heatmap, funnel, etc.)   │
│  • Plotly figure generation with enterprise styling              │
│  • Interactive element configuration                             │
│  TOOL: create_visualization_logic()                              │
└──────────────────────────────────────────────────────────────────┘
                            │
                            ▼
┌──────────────────────────────────────────────────────────────────┐
│  AGENT 5: ResponseBuilder (Executive Synthesizer)                │
│  ────────────────────────────────────────────────────────────────│
│  • Compiles analysis summary in business language                │
│  • Integrates visualization with narrative context               │
│  • Suggests alternative visualization approaches                 │
│  TOOL: build_response_logic()                                    │
└──────────────────────────────────────────────────────────────────┘
                            │
                            ▼
┌──────────────────────────────────────────────────────────────────┐
│  AGENT 6: Evaluator (Quality Assurance Judge)                    │
│  ────────────────────────────────────────────────────────────────│
│  • Reviews query-response alignment                              │
│  • Validates intent fulfillment                                  │
│  • Generates QA score (1-10) with critique                       │
│  OUTPUT: QA_SCORE: X/10 | CRITIQUE: [Assessment]                 │
└──────────────────────────────────────────────────────────────────┘
                            │
                            ▼
               FINAL USER-FACING RESPONSE
               + Interactive Plotly Visualization

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;The "Secret Sauce": Deterministic Tools&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The biggest risk in Agentic AI is &lt;strong&gt;arbitrary code execution&lt;/strong&gt;. If you let an LLM write and run its own Python code, you open the door to security vulnerabilities and broken loops.&lt;/p&gt;

&lt;p&gt;ECIA takes a different approach. I built &lt;strong&gt;6 custom Python tools&lt;/strong&gt; that act as guardrails. The Agent can &lt;em&gt;call&lt;/em&gt; these tools, but it cannot &lt;em&gt;rewrite&lt;/em&gt; them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Snippet: The Safe Tool Pattern&lt;/strong&gt; Here is how I implemented the "Analyst" logic using Google's ADK. Notice how the agent is restricted to specific analysis types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# The agent can only "choose" the analysis, not invent the math
def statistical_analysis_tool(analysis_type: str, target_column: str, group_column: str = None):
    """
    Performs deterministic statistical analysis. 
    Secure: No eval() or exec() used.
    """
    df = session.get_data()

    if analysis_type == "ranking":
        return df.groupby(group_column)[target_column].sum().sort_values(ascending=False).head(5)

    elif analysis_type == "correlation":
        return df[target_column].corr(df[group_column])

    # ... handle other deterministic types
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures that when a user asks for "Top 5 Products," the math is &lt;strong&gt;always&lt;/strong&gt; correct, regardless of the LLM's "creativity."&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Handling the "Messy Reality" of Data&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Real-world data is never clean. Users make typos. Column headers are cryptic (&lt;code&gt;Q3_24_Rev_Adj&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;ECIA uses a &lt;strong&gt;Semantic Mapping Layer&lt;/strong&gt;. If a user asks about "Sales," but the column is named &lt;code&gt;gross_merch_vol&lt;/code&gt;, a standard regex fails. My &lt;strong&gt;DataPrep Agent&lt;/strong&gt; uses the Gemini model's reasoning capabilities to map the &lt;em&gt;intent&lt;/em&gt; to the &lt;em&gt;schema&lt;/em&gt; before any code is run.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;User:&lt;/strong&gt; "Show me the trend of injuries."&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dataset Column:&lt;/strong&gt; &lt;code&gt;n_wounded&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Agent Decision:&lt;/strong&gt; "Map 'injuries' to &lt;code&gt;n_wounded&lt;/code&gt; with 98% confidence."&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The "Evaluator" Loop: AI Checking AI&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The final piece of the puzzle is the &lt;strong&gt;Evaluator Agent&lt;/strong&gt;. It acts as a "critic." It reads the user's original prompt and the system's generated chart, then asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Does this chart actually answer the specific question asked?"&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If the answer is "No," it triggers a retry loop. This significantly reduces the "lazy agent" problem where models give a generic answer to a specific question.&lt;/p&gt;

&lt;p&gt;Here's one of the queries from the demo&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj4xtkl3kmdcb8wqwb5fu.png" class="article-body-image-wrapper"&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.amazonaws.com%2Fuploads%2Farticles%2Fj4xtkl3kmdcb8wqwb5fu.png" alt=" " width="699" height="1217"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Try It Yourself&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This project was built for the &lt;strong&gt;Google AI Agents Intensive&lt;/strong&gt;. It taught me that while LLMs are powerful, &lt;strong&gt;architecture is what makes them production-ready.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check out the Code:&lt;/strong&gt; &lt;a href="https://github.com/kshitij0001/ECIA/" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;See the Kaggle Notebook:&lt;/strong&gt; &lt;a href="https://www.kaggle.com/code/kshitijdubey01/enterprise-csv-intelligence-agent-ecia" rel="noopener noreferrer"&gt;Run the Agent Here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'd love to hear your feedback—especially on how you handle security in your own agent pipelines!&lt;/p&gt;

</description>
      <category>googleaichallenge</category>
      <category>ai</category>
      <category>agents</category>
      <category>python</category>
    </item>
  </channel>
</rss>
