<?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: Tahar Amin Touzi</title>
    <description>The latest articles on DEV Community by Tahar Amin Touzi (@tahar_touzi_98e475d8a5afa).</description>
    <link>https://dev.to/tahar_touzi_98e475d8a5afa</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%2F4266798%2F13f333a2-5099-48d0-ae1e-8bda8b156167.png</url>
      <title>DEV Community: Tahar Amin Touzi</title>
      <link>https://dev.to/tahar_touzi_98e475d8a5afa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tahar_touzi_98e475d8a5afa"/>
    <language>en</language>
    <item>
      <title>Code Mode for In-App SaaS AI Agents: Why 150 Tools Wreck Prompt Caching</title>
      <dc:creator>Tahar Amin Touzi</dc:creator>
      <pubDate>Thu, 26 Nov 2026 11:48:32 +0000</pubDate>
      <link>https://dev.to/tahar_touzi_98e475d8a5afa/code-mode-for-in-app-saas-ai-agents-why-150-tools-wreck-prompt-caching-136o</link>
      <guid>https://dev.to/tahar_touzi_98e475d8a5afa/code-mode-for-in-app-saas-ai-agents-why-150-tools-wreck-prompt-caching-136o</guid>
      <description>&lt;p&gt;Most write-ups on MCP code mode focus on external developer clients connecting to a remote server. Inside a real B2B SaaS product, there is an even bigger payoff that almost nobody talks about: running code mode for your &lt;strong&gt;own in-app AI assistant&lt;/strong&gt; so your prompt cache hit rate stays near its ceiling and your per-user LLM cost stops scaling linearly with your feature count.&lt;/p&gt;

&lt;p&gt;When we built &lt;a href="https://mailbase.studio/features/ai-mcp" rel="noopener noreferrer"&gt;Mailbase&lt;/a&gt; (an email workflow SaaS covering transactional sending, campaigns, audiences, inbox triage, prospecting, and API keys), our tool catalog grew past 150 operations. That is the exact point where classic tool-calling breaks unit economics.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why 150 tool definitions quietly wreck prompt caching
&lt;/h2&gt;

&lt;p&gt;Modern LLM providers discount cached input tokens by 75% to 90% — &lt;strong&gt;only when the prompt prefix is byte-identical&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you dynamically filter tool schemas per route, plan, or user role (&lt;code&gt;if (user.isAdmin) tools.push(...)&lt;/code&gt;), every permutation invalidates the cache prefix for the entire tool block. On the flip side, if you pin all 150+ JSON Schemas on every turn so they cache, you still pay for 25,000+ prefix tokens on turn one, dilute tool-selection accuracy, and pay full price every time multi-step read loops dump raw JSON arrays into conversation history.&lt;/p&gt;

&lt;p&gt;Ask an in-app assistant &lt;em&gt;"Which of my last 10 campaigns had a bounce rate above 2%?"&lt;/em&gt; under classic tool calling: the model runs 11 sequential turns and stuffs every raw response into the context window just to output two lines.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two-tool split: &lt;code&gt;search_tools&lt;/code&gt; + QuickJS &lt;code&gt;run_program&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;We collapsed the entire catalog into two stable tools whose definitions are &lt;strong&gt;byte-identical across every user, role, and page&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;search_tools(query, family, detail)&lt;/code&gt;&lt;/strong&gt; — progressive disclosure:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;detail: "names"&lt;/code&gt; returns only tool names&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;detail: "descriptions"&lt;/code&gt; adds titles, read-only/destructive flags, and sandbox eligibility&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;detail: "full"&lt;/code&gt; loads Zod-derived JSON Schemas for only the few tools needed right now&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;run_program(code)&lt;/code&gt;&lt;/strong&gt; — executes a short async JavaScript function inside an isolated &lt;strong&gt;QuickJS&lt;/strong&gt; sandbox (no network, no filesystem, no timers, no env vars, hard wall-clock/CPU/memory/call caps):
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;campaigns&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;mailbase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list_campaigns&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;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;campaigns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;mailbase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_campaign_stats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&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="n"&gt;id&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;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bounce_rate&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.02&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bounce_rate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bounce_rate&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;p&gt;One LLM turn. 200 bytes back into context instead of 40 KB of raw JSON.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi-tenant security inside the bridge
&lt;/h2&gt;

&lt;p&gt;The obvious objection: &lt;em&gt;if the model writes JS, can it bypass RBAC or send 500 emails in a loop?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Not if the host bridge refuses to be a shortcut:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Static read-only allowlist:&lt;/strong&gt; write and send tools are rejected inside &lt;code&gt;run_program&lt;/code&gt;. To mutate state or send an email, the model must invoke the tool directly outside the sandbox so the UI asks the user to confirm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Same guarded handler on every inner call:&lt;/strong&gt; every &lt;code&gt;await mailbase.&amp;lt;tool&amp;gt;(args)&lt;/code&gt; passes through Zod argument validation, OAuth/session scopes, workspace isolation, and the member's live role check.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full deep-dive and comparison table originally published on the Mailbase engineering blog: &lt;a href="https://mailbase.studio/blog/code-mode-prompt-caching-saas-agents" rel="noopener noreferrer"&gt;Code Mode for In-App SaaS Agents: Prompt Caching &amp;amp; Cost Math&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>saas</category>
      <category>architecture</category>
    </item>
    <item>
      <title>How We Verified 50,000 Email Probes for 10,000 Contacts Without Paying $400/mo</title>
      <dc:creator>Tahar Amin Touzi</dc:creator>
      <pubDate>Thu, 26 Nov 2026 11:48:06 +0000</pubDate>
      <link>https://dev.to/tahar_touzi_98e475d8a5afa/how-we-verified-50000-email-probes-for-10000-contacts-without-paying-400mo-50po</link>
      <guid>https://dev.to/tahar_touzi_98e475d8a5afa/how-we-verified-50000-email-probes-for-10000-contacts-without-paying-400mo-50po</guid>
      <description>&lt;p&gt;If you build B2B prospecting or lead-enrichment software, you hit an uncomfortable math problem early: verifying 10,000 real business emails rarely means running 10,000 checks.&lt;/p&gt;

&lt;p&gt;When you test common personal patterns for a contact (&lt;code&gt;first.last@&lt;/code&gt;, &lt;code&gt;f.last@&lt;/code&gt;, &lt;code&gt;first@&lt;/code&gt;, &lt;code&gt;last@&lt;/code&gt;, &lt;code&gt;contact@&lt;/code&gt;), you easily run &lt;strong&gt;~5 checks per contact — 50,000 probes to land 10,000 verified emails&lt;/strong&gt;. At typical instant email-verification API rates ($0.008–$0.01/check), 50,000 checks cost &lt;strong&gt;$400–$500 per run&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is the exact architecture we built at &lt;a href="https://mailbase.studio/blog/verify-50000-emails-smtp-without-paying-400" rel="noopener noreferrer"&gt;Mailbase&lt;/a&gt; to run 50,000 probes cleanly at minimal cost without burning our sending IP.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Kill 40% of dead work before opening a single port 25 socket
&lt;/h2&gt;

&lt;p&gt;We run a strict cheap-to-expensive cascade:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Syntax + placeholder filter (0 ms):&lt;/strong&gt; discards typos, disposable domains, and theme leftovers (&lt;code&gt;contact@yoursite.com&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cached DNS MX lookup (~15 ms, free):&lt;/strong&gt; kills expired domains and RFC 7505 null MX (&lt;code&gt;0 .&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistent domain-facts cache (~2 ms, Postgres):&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Known &lt;strong&gt;catch-all&lt;/strong&gt; domains are cached for &lt;strong&gt;30 days&lt;/strong&gt; (no point re-probing guessed patterns — a &lt;code&gt;250 OK&lt;/code&gt; proves nothing).&lt;/li&gt;
&lt;li&gt;Unreachable / refusing servers get a &lt;strong&gt;6-hour&lt;/strong&gt; cooldown so we never hammer a grumpy MX.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  2. One SMTP session per domain + random control mailbox first
&lt;/h2&gt;

&lt;p&gt;Opening 5 separate TCP sockets to test 5 name permutations at &lt;code&gt;acme.example&lt;/code&gt; looks like a dictionary attack. Instead, open &lt;strong&gt;one&lt;/strong&gt; session per domain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EHLO → MAIL FROM → RCPT TO:&amp;lt;zz-nonexistent-9f3a@acme.example&amp;gt;
                 → RCPT TO:&amp;lt;alice.martin@acme.example&amp;gt;
                 → RCPT TO:&amp;lt;a.martin@acme.example&amp;gt;
                 → QUIT (never DATA)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the random impossible address returns &lt;code&gt;250 OK&lt;/code&gt;, the domain is a &lt;strong&gt;catch-all&lt;/strong&gt; — every guessed candidate stays &lt;code&gt;unknown&lt;/code&gt;, never &lt;code&gt;verified&lt;/code&gt;. We only keep an address on a catch-all domain when it was explicitly published on the company's own site.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Why slow pacing (~5 probes/min) breaks the $400/mo pricing model
&lt;/h2&gt;

&lt;p&gt;Commercial verification APIs are expensive because customers demand 400 ms synchronous answers at high concurrency, which forces huge rotating IP pools and constant blocklist remediation.&lt;/p&gt;

&lt;p&gt;Most B2B lists and nightly hygiene jobs do not need an answer in 400 ms — they need a clean list by tomorrow morning. Running probes on an &lt;strong&gt;isolated dedicated probe server&lt;/strong&gt; with clean reverse DNS (completely separate from our Amazon SES sending infrastructure) paced gently at &lt;strong&gt;~5 addresses per minute&lt;/strong&gt; respects remote MX limits, handles greylisting (&lt;code&gt;450&lt;/code&gt;/&lt;code&gt;451&lt;/code&gt;) cleanly, and gets through 50,000 probes for pennies instead of $400.&lt;/p&gt;

&lt;p&gt;Full architectural breakdown originally published on Mailbase: &lt;a href="https://mailbase.studio/blog/verify-50000-emails-smtp-without-paying-400" rel="noopener noreferrer"&gt;How We Verified 50,000 Email Probes Without Paying $400/mo&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>email</category>
      <category>backend</category>
      <category>node</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
