<?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: sanchar10</title>
    <description>The latest articles on DEV Community by sanchar10 (@sanchar10).</description>
    <link>https://dev.to/sanchar10</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%2F3666366%2Fa3be2b5f-7250-47c4-a850-8f279465ed0a.png</url>
      <title>DEV Community: sanchar10</title>
      <link>https://dev.to/sanchar10</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sanchar10"/>
    <language>en</language>
    <item>
      <title>SQL Access for AI Agents — Flexibility with Guardrails</title>
      <dc:creator>sanchar10</dc:creator>
      <pubDate>Wed, 17 Dec 2025 07:38:31 +0000</pubDate>
      <link>https://dev.to/sanchar10/sql-access-for-ai-agents-flexibility-with-guardrails-e50</link>
      <guid>https://dev.to/sanchar10/sql-access-for-ai-agents-flexibility-with-guardrails-e50</guid>
      <description>&lt;p&gt;Learn how to safely expose SQL data to AI agents using a two-part pattern: MCP for AI communication and a schema-driven query builder for secure queries."&lt;/p&gt;

&lt;h2&gt;
  
  
  Operational AI Agents Need Boundaries
&lt;/h2&gt;

&lt;p&gt;AI agents are increasingly used for operational tasks like customer support:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What’s the status of my subscription?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To answer, an agent must:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Look up the customer by email or phone
&lt;/li&gt;
&lt;li&gt;Check active subscriptions
&lt;/li&gt;
&lt;li&gt;Review recent interactions
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The challenge:&lt;/strong&gt; Allowing AI to query databases safely without giving unrestricted access.  &lt;/p&gt;




&lt;h2&gt;
  
  
  Why Common Solutions Fall Short
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Challenge for AI Agents&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Raw SQL&lt;/td&gt;
&lt;td&gt;Risky, prone to injection and errors&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Hardcoded APIs&lt;/td&gt;
&lt;td&gt;Inflexible, needs code changes for every query&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;GraphQL / OData&lt;/td&gt;
&lt;td&gt;Powerful but generic; lacks safeguards and declarative interfaces for reliable agentic queries&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Key insight:&lt;/strong&gt; AI agents don’t need full database flexibility — they need &lt;strong&gt;predictable, bounded access&lt;/strong&gt;.  &lt;/p&gt;




&lt;h2&gt;
  
  
  Our Two-Part Solution
&lt;/h2&gt;

&lt;p&gt;We combined two patterns:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Model Context Protocol (MCP)&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Standardized interface for AI → tool communication
&lt;/li&gt;
&lt;li&gt;Enables tool discovery, structured parameters, predictable responses
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Schema-Driven Query Builder&lt;/strong&gt;  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Converts JSON-defined entity schemas into safe SQL
&lt;/li&gt;
&lt;li&gt;Handles relationships, field allowlists, and multiple backends&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Supports multiple SQL backends — SQLite for demos, SQL Server or PostgreSQL for production — with the same query logic.&lt;/em&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Outcome:&lt;/strong&gt; Minimal boilerplate, safe boundaries, LLM-friendly query syntax.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Security is built in: explicit field allowlists (allowedFilterFields) prevent AI from accessing unauthorized data.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why It Matters
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AI-ready APIs:&lt;/strong&gt; Enable operational queries safely &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dual interface:&lt;/strong&gt; Same engine serves AI (MCP) and REST clients
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extensible:&lt;/strong&gt; Add new tools with minimal code
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secure:&lt;/strong&gt; Explicit allowlists prevent unauthorized access
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Operational AI queries ≠ ad-hoc analytics
&lt;/li&gt;
&lt;li&gt;Bounded interfaces improve reliability and predictability
&lt;/li&gt;
&lt;li&gt;Separation of transport (MCP) and query logic (query builder) maximizes flexibility
&lt;/li&gt;
&lt;li&gt;MongoDB-style JSON filters align with LLM training
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What’s Next
&lt;/h2&gt;

&lt;p&gt;In the &lt;strong&gt;next post&lt;/strong&gt;, we’ll dive into &lt;strong&gt;MCP in detail&lt;/strong&gt;: how AI discovers and calls tools, with real examples.  &lt;/p&gt;

&lt;p&gt;Check out the GitHub repo for the &lt;strong&gt;full implementation, diagrams, and code&lt;/strong&gt;: &lt;a href="https://github.com/sanchar10/mcp-sql-query-dotnet" rel="noopener noreferrer"&gt;https://github.com/sanchar10/mcp-sql-query-dotnet&lt;/a&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Follow me for more AI architecture deep-dives, and drop a comment if you have questions!&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>mcp</category>
      <category>dotnet</category>
      <category>database</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
