<?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: Yasin YAMAN</title>
    <description>The latest articles on DEV Community by Yasin YAMAN (@yasinyaman).</description>
    <link>https://dev.to/yasinyaman</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%2F149054%2F5a7780f0-adc3-428e-ab61-6e12b806ef00.jpeg</url>
      <title>DEV Community: Yasin YAMAN</title>
      <link>https://dev.to/yasinyaman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yasinyaman"/>
    <language>en</language>
    <item>
      <title>Letting AI agents query production databases without giving them a database account</title>
      <dc:creator>Yasin YAMAN</dc:creator>
      <pubDate>Sun, 15 Nov 2026 18:15:00 +0000</pubDate>
      <link>https://dev.to/yasinyaman/letting-ai-agents-query-production-databases-without-giving-them-a-database-account-524o</link>
      <guid>https://dev.to/yasinyaman/letting-ai-agents-query-production-databases-without-giving-them-a-database-account-524o</guid>
      <description>&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Once a company has an AI assistant, someone asks whether it can answer questions over production data. I do data consulting for companies that keep everything on-premises, and I kept hearing that question.&lt;/p&gt;

&lt;p&gt;The usual answer is a read-only database account plus a text-to-SQL prompt. That leaves three things unsolved:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The account sees every row. Other tenants, other regions and personal data are all in reach.&lt;/li&gt;
&lt;li&gt;The model writes joins from column names it has to guess at.&lt;/li&gt;
&lt;li&gt;Nobody can say afterwards who read what.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I built &lt;a href="https://github.com/yasinyaman/truejoin" rel="noopener noreferrer"&gt;Truejoin&lt;/a&gt; to close those three, on your own servers, with Oracle and SQL Server included.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Truejoin is
&lt;/h2&gt;

&lt;p&gt;Truejoin is an open-source (Apache 2.0) data gateway. It connects to PostgreSQL, MySQL/MariaDB, SQL Server and Oracle, and serves them three ways from one Python process and one config file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MCP&lt;/strong&gt;: 18 tools for agents, over streamable HTTP or stdio&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;REST&lt;/strong&gt;: an API per table with a typed OpenAPI schema&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Analytical SQL&lt;/strong&gt;: in-memory OLAP on DuckDB&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every query, whoever wrote it, runs under the caller's row rules and column masks and leaves one audit event. It is not a warehouse, an ETL tool or a BI dashboard. It reads the databases you already have, live.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rules are applied by rewriting the query
&lt;/h2&gt;

&lt;p&gt;Filtering the result is too late. An aggregate over rows the caller may not see has already leaked, and so has a masked column read through an alias, a join or a subquery.&lt;/p&gt;

&lt;p&gt;So Truejoin rewrites the query before it runs. Each table the query names is replaced by a subquery that carries that caller's row conditions and masks. Aliases, joins, CTEs and aggregates then all read the restricted view, because there is nothing else to read.&lt;/p&gt;

&lt;p&gt;The rules are a few lines of config (trimmed here; the full nesting is in &lt;code&gt;config/reference.yaml&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;row_filters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;orders&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;span class="s"&gt;column:&lt;/span&gt; &lt;span class="s"&gt;tenant_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;value:&lt;/span&gt; &lt;span class="s2"&gt;"${tenant}"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="na"&gt;row_filter_exempt_roles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;dpo&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="na"&gt;masking&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;email:&lt;/span&gt; &lt;span class="s"&gt;partial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;national_id:&lt;/span&gt; &lt;span class="s"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things follow from doing it this way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It fails closed.&lt;/strong&gt; Anything that cannot be wrapped, a table function for example, refuses the query.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model-written SQL gets no special path.&lt;/strong&gt; It goes through the same rewrite as a person's.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The audit event never holds the SQL.&lt;/strong&gt; It records who asked, which tables, how many rows, and which columns were masked.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  A model drafts the catalog, a person approves it
&lt;/h2&gt;

&lt;p&gt;A model reads the schema and drafts table and column descriptions, PII labels, relationships and business terms (&lt;code&gt;truejoin catalog analyze&lt;/code&gt;). Sample values are masked before they reach it, and with Ollama nothing leaves your network.&lt;/p&gt;

&lt;p&gt;A person then reviews, approves and certifies the draft. Nothing unapproved is used.&lt;/p&gt;

&lt;p&gt;The approved catalog does two jobs. Masks key off its semantic types, and questions are read against its business terms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Questions in words, without a model at query time
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;answer_question&lt;/code&gt; first reads a question against the approved vocabulary, with no model involved. It returns the request it understood and the SQL it compiled, so you can check what was asked before you trust the answer. Joins follow declared foreign keys, so a request cannot write a wrong join.&lt;/p&gt;

&lt;p&gt;Only a question the vocabulary cannot read goes to a model, and that answer is marked as model-written.&lt;/p&gt;

&lt;p&gt;I benchmarked the approaches on a banking-shaped schema with &lt;code&gt;qwen2.5-coder:7b&lt;/code&gt;, graded by result set against a gold query. On the 16 held-out questions:&lt;/p&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;Correct (of 16)&lt;/th&gt;
&lt;th&gt;Hallucinated&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Model writes SQL from the DDL&lt;/td&gt;
&lt;td&gt;8&lt;/td&gt;
&lt;td&gt;31.2%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Model writes SQL from the catalog&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;18.8%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Approved terms, no model&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;0%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Sixteen questions is a small set and the intervals are wide. The table in the repo shows 13 for the last row; one of those was right by luck and is now refused, so I count 12. The method and every caveat are in &lt;a href="https://github.com/yasinyaman/truejoin/blob/main/bench/README.md" rel="noopener noreferrer"&gt;bench/README.md&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where it came from: Warp, Fusion and Stargate
&lt;/h2&gt;

&lt;p&gt;Truejoin merges three earlier projects of mine into one package and one process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Warp&lt;/strong&gt;: database to governed REST, with the catalog&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fusion&lt;/strong&gt;: DuckDB OLAP and the agent tools&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stargate&lt;/strong&gt;: OpenAPI to MCP. It lives on as &lt;code&gt;truejoin mcp convert&lt;/code&gt;, which turns an OpenAPI or Postman description into an MCP server definition.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Their code moved over with its history. The query rewriter is the one component with no ancestor in the three, and it carries the privacy promise, so its tests were written first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;You need Python 3.12+ and &lt;a href="https://docs.astral.sh/uv/" rel="noopener noreferrer"&gt;uv&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/yasinyaman/truejoin.git
&lt;span class="nb"&gt;cd&lt;/span&gt; truejoin
uv sync --all-extras

&lt;span class="kd"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;TRUEJOIN_SECRET_KEY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;uv run python -c &lt;span class="s1"&gt;'from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
uv run truejoin config validate -c config/database.yaml
uv run truejoin users add admin --permission all -c config/database.yaml
uv run truejoin serve -c config/database.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The console is at &lt;code&gt;http://localhost:8000/ui&lt;/code&gt;. Any MCP client can connect over HTTP at &lt;code&gt;http://&amp;lt;host&amp;gt;:8000/mcp&lt;/code&gt; with an API key in &lt;code&gt;X-API-Key&lt;/code&gt;. For a desktop client such as Claude Desktop, run the tools over stdio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"mcpServers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"truejoin"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"uv"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"args"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"run"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"--directory"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"/path/to/truejoin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"truejoin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"serve"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
               &lt;span class="s2"&gt;"--transport"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"stdio"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"-c"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"config/database.yaml"&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Limits, and what I'd like to hear
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;1.0.0 is still in development. It installs from source and is not on PyPI yet.&lt;/li&gt;
&lt;li&gt;SQL Server and Oracle connect through ODBC.&lt;/li&gt;
&lt;li&gt;A restricted caller's analytical queries always run locally in DuckDB, and one that is not a flat SELECT loads whole tables for that caller.&lt;/li&gt;
&lt;li&gt;The benchmark is small, and it is one schema.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The feedback I want most is on the rewriter. Try to read around a row rule or a mask. If a query gets through, please report it privately through a &lt;a href="https://github.com/yasinyaman/truejoin/security/advisories/new" rel="noopener noreferrer"&gt;GitHub security advisory&lt;/a&gt; rather than a public issue.&lt;/p&gt;

&lt;p&gt;The code is at &lt;a href="https://github.com/yasinyaman/truejoin" rel="noopener noreferrer"&gt;github.com/yasinyaman/truejoin&lt;/a&gt; and the docs are at &lt;a href="https://yaman.dev/truejoin/" rel="noopener noreferrer"&gt;yaman.dev/truejoin&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>mcp</category>
      <category>ai</category>
      <category>opensource</category>
      <category>database</category>
    </item>
  </channel>
</rss>
