<?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: 缔造</title>
    <description>The latest articles on DEV Community by 缔造 (@dixxxzao01).</description>
    <link>https://dev.to/dixxxzao01</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%2F4212760%2F4e1ccd7c-6786-483d-a665-0bd47ec63f31.png</url>
      <title>DEV Community: 缔造</title>
      <link>https://dev.to/dixxxzao01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dixxxzao01"/>
    <language>en</language>
    <item>
      <title>I built a gateway that retries LLM refusals until I get a real answer</title>
      <dc:creator>缔造</dc:creator>
      <pubDate>Wed, 28 Oct 2026 10:03:23 +0000</pubDate>
      <link>https://dev.to/dixxxzao01/i-built-a-gateway-that-retries-llm-refusals-until-i-get-a-real-answer-3d3d</link>
      <guid>https://dev.to/dixxxzao01/i-built-a-gateway-that-retries-llm-refusals-until-i-get-a-real-answer-3d3d</guid>
      <description>&lt;p&gt;If you work with LLM APIs you know the dance: you ask for working code, and you get a lecture. A disclaimer. Three paragraphs of "as an AI I cannot" followed by a suspiciously detailed explanation of &lt;em&gt;why&lt;/em&gt; it cannot.&lt;/p&gt;

&lt;p&gt;I got tired of it, so I built &lt;a href="https://github.com/Dixxxzao-01/armor-gw" rel="noopener noreferrer"&gt;armor-gw&lt;/a&gt; — a self-hosted, OpenAI-compatible proxy that sits between your app and any upstream model and refuses to accept refusals.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;Every response passing through the gateway gets inspected by 13 detector classes. Not just the obvious "I can't help with that" — also the sneaky ones:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;substitute answer&lt;/strong&gt; ("instead, here are some security best practices...")&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;lecture delivery&lt;/strong&gt; (2000 words of hedging with zero code blocks)&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;silent omission&lt;/strong&gt; (a 4000-word prompt where the model answers everything except the one line you actually asked for)&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;persona-wrapped refusal&lt;/strong&gt; (a jailbreak shell gets the model to roleplay, and the refusal comes back dressed as character dialogue)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a refusal is detected, the request gets reformulated by one of &lt;strong&gt;62 mutation operators&lt;/strong&gt; and retried — while a second variant from a different strategy family races it in parallel. First clean answer wins.&lt;/p&gt;

&lt;p&gt;The strategy layer is a Thompson-sampling bandit that learns per-model which approach actually works: persona framing, encoding tricks, or inversion techniques. A diagnostic judge labels each refusal with its cause (policy / safety-speak / capability-doubt / evasion) so the next retry targets the actual failure mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  What your app sees
&lt;/h2&gt;

&lt;p&gt;A normal OpenAI endpoint. Drop-in compatible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;openai&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;OpenAI&lt;/span&gt;
&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OpenAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base_url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;http://localhost:8787/v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sk-your-key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;chat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;completions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;your-upstream-model&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                   &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[...])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Multiple upstreams, per-model routing, failover. The console UI shows every retry round live — watching it classify a refusal, pick a strategy, and break through on round 3 is honestly a little addictive.&lt;/p&gt;

&lt;h2&gt;
  
  
  The interesting engineering problems
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Detecting refusals is harder than it looks.&lt;/strong&gt; Keyword lists fail immediately — models rephrase. The most reliable signal turned out to be &lt;em&gt;entity survival rate&lt;/em&gt;: if the technical nouns from your request never appear in the response, nobody answered your question no matter how confident the prose sounds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Output hygiene matters as much as breaking through.&lt;/strong&gt; The gateway strips chain-of-thought leaks, disclaimers, filler questions, and "want me to elaborate?" endings. The deliverable is the deliverable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Strategies decay.&lt;/strong&gt; Upstream models get quietly updated, and an operator that worked for weeks stops working. There's a regression bank (65 seeded test cases) that runs on demand and flags any topic whose success rate drops 20%.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Self-hosted, MIT, one-command deploy, runs on anything with Python 3.9+ (I develop on an aarch64 Alpine box):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/Dixxxzao-01/armor-gw" rel="noopener noreferrer"&gt;github.com/Dixxxzao-01/armor-gw&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Feedback welcome — especially which upstreams you'd want supported out of the box, and what refusal patterns you're hitting that the detectors miss.&lt;/p&gt;

</description>
      <category>llm</category>
      <category>python</category>
      <category>fastapi</category>
      <category>openai</category>
    </item>
  </channel>
</rss>
