<?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: Kishan GC</title>
    <description>The latest articles on DEV Community by Kishan GC (@kishangc).</description>
    <link>https://dev.to/kishangc</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%2F3944657%2Feee57f45-d0a9-4eec-8ffb-89552f2c2d13.png</url>
      <title>DEV Community: Kishan GC</title>
      <link>https://dev.to/kishangc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kishangc"/>
    <language>en</language>
    <item>
      <title>We prevented our agents going rogue at runtime.</title>
      <dc:creator>Kishan GC</dc:creator>
      <pubDate>Fri, 22 May 2026 18:12:11 +0000</pubDate>
      <link>https://dev.to/kishangc/we-prevented-our-agents-going-rogue-at-runtime-12de</link>
      <guid>https://dev.to/kishangc/we-prevented-our-agents-going-rogue-at-runtime-12de</guid>
      <description>&lt;p&gt;Building an AI chatbot is trivial. Building an AI agent that you actually trust to audit your enterprise infrastructure and financial data is terrifying.&lt;br&gt;
When I started building SentinelOps, the goal was to create an operational advisor for our compliance and engineering teams. But during early testing, the agent went rogue. It would confidently give terrible advice, hallucinate regulatory frameworks, and sometimes just dump out verbose paragraphs of useless prose when all we needed was a "Yes" or "No".&lt;br&gt;
I realized that if we were going to put an LLM in the critical path of our governance workflows, we couldn't just "chat" with it. We had to put it in a straitjacket.&lt;br&gt;
Here is how I forced our rogue agent into strict compliance using JSON-schema constraints, CascadeFlow routing, and Hindsight memory.&lt;br&gt;
The straitjacket: Strict JSON Enforcement&lt;br&gt;
The biggest mistake developers make is letting the LLM dictate the output format. To fix our agent, I ripped out the standard chat interface and rewrote the system prompt to enforce a massive, unforgiving JSON schema.&lt;br&gt;
Instead of answering freely, the agent is forced to populate specific intelligence fields:&lt;br&gt;
&lt;/p&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="nx"&gt;DECISION&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;_SYSTEM&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nx"&gt;_PROMPT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
You are an Enterprise Decision Intelligence Agent.
You MUST output your response as a valid JSON object. Do not include markdown formatting or conversational filler.

{
  "decisionSummary": "One-paragraph executive summary.",
  "riskLevel": "low | medium | high | critical",
  "financialImpact": {
    "estimatedLoss": "$X",
    "estimatedSavings": "$X"
  },
  "governanceSeverity": "informational | advisory | mandatory | critical-block",
  "escalationRequired": true,
  "operationalRecommendation": "Step-by-step remediation."
}
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the agent detects a compliance issue, it must flag &lt;code&gt;escalationRequired: true&lt;/code&gt;. This structured output fundamentally changes the frontend. We don't render a chat bubble; we render a dashboard card that turns red if governance severity is high.&lt;br&gt;
Contextual Grounding with Hindsight&lt;br&gt;
To prevent the agent from hallucinating compliance policies, it needed grounding. I integrated agent memory using the Hindsight GitHub repository.&lt;br&gt;
Now, before the agent makes a decision, it searches our organizational history. If a user asks about HIPAA data handling, Hindsight injects our actual historical audits into the prompt. It can't go rogue if it's literally reading from the company rulebook.&lt;br&gt;
Guardrails via CascadeFlow&lt;br&gt;
Even with strict JSON and memory, relying on a single model is risky. Using the cascadeflow docs, I built a routing safety net.&lt;br&gt;
If an incoming query triggers our regex for high-sensitivity keywords (e.g., &lt;code&gt;PHI&lt;/code&gt;, &lt;code&gt;financial&lt;/code&gt;, &lt;code&gt;breach&lt;/code&gt;), CascadeFlow forcibly routes the request to our most powerful, heavily-steered reasoning model, bypassing the cheaper, more erratic models entirely.&lt;br&gt;
&lt;/p&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="nx"&gt;sensitivityLevel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sensitivityLevel&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;targetModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;llama3-8b-8192&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sensitivityLevel&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;secret&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;sensitivityLevel&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;confidential&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Force routing to the heavy reasoning engine for safety&lt;/span&gt;
    &lt;span class="nx"&gt;targetModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;llama3-70b-8192&lt;/span&gt;&lt;span class="dl"&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;The Results&lt;br&gt;
By combining strict JSON extraction, historical grounding, and intelligent routing, the system stopped being a toy and became a tool.&lt;br&gt;
&lt;a href="/absolute/path/to/media__1779348442324.png" class="article-body-image-wrapper"&gt;&lt;img src="/absolute/path/to/media__1779348442324.png" alt="Decision Interface"&gt;&lt;/a&gt;&lt;br&gt;
When an engineer asks about deploying a new database without encryption, the agent doesn't write a poem about security. It outputs a &lt;code&gt;critical-block&lt;/code&gt; governance severity, flags &lt;code&gt;escalationRequired: true&lt;/code&gt;, and cites the exact incident from Hindsight where we were audited for the same issue six months ago.&lt;br&gt;
Takeaways&lt;br&gt;
Never trust conversational UI for enterprise data. Force your agents into JSON schemas. It allows you to build programmatic guardrails and UI alerts.&lt;br&gt;
Memory is your best defense against hallucinations. Use Hindsight docs to ground your agent in reality.&lt;br&gt;
Route based on risk. Use orchestration tools to ensure critical decisions are handled by your best models, not your cheapest ones.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>javascript</category>
      <category>llm</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
