AI Hallucination: Fixing an Agent That Invented Our Stack
AI Hallucination: Fixing an Agent That Invented Our Stack
I caught our own content-writing agent lying about our codebase this week. Not maliciously — it was trying to be helpful, filling a gap with a plausible-sounding detail instead of an honest one. That’s AI hallucination in its most common enterprise form: not a dramatic factual error, but a confident fabrication that reads fine until someone who knows the system checks it.
The agent writes blog posts for this site, including the “what we built” posts you’re reading right now. Its job is to take real repo activity and turn it into a readable story. On a recent draft, it didn’t do that. It described a RAG pipeline with a vector database. We don’t have one. It named a frontend framework we’ve never touched. Both details were specific, technically coherent, and completely made up.
Why AI Hallucination Shows Up Even in “Safe” Use Cases
Content generation feels like a low-risk place for AI hallucination to matter. Nobody’s deploying code from a blog post. But I’ve spent 25 years watching small integrity failures compound — a wrong detail in a security advisory, a misattributed finding in an incident report, a fabricated line in a compliance doc. The mechanism is the same whether it’s a SOC analyst’s tool or a marketing agent: the model fills gaps with the statistically likely answer, not the true one, unless you force it to do otherwise.
The failure mode here is predictable once you understand how these agents draft. Given a topic like “building and learning,” the model has seen thousands of blog posts about AI projects that use RAG pipelines, vector databases, and React frontends — because that’s what most AI content on the internet describes. When the agent doesn’t have strong grounding in what actually happened, it defaults to the median story. That median story is fiction for us.
What Actually Got Shipped This Week
The fix wasn’t a model swap or a new tool. It was a rule added directly to the agent’s operating instructions, plus a change in what we feed it before it drafts.
Two things changed:
-
A hard constraint in the system prompt that blocks naming any specific tech stack, framework, or feature — React, a RAG pipeline, a vector DB, anything — unless it’s explicitly evidenced in the source material given for that draft. If the grounding doesn’t support a detail, the agent is instructed to write a smaller, true story instead of a bigger, invented one.
-
A grounding feed of real repo activity passed into every “building and learning” prompt — actual commit titles, PR numbers, and shipped changes — explicitly marked as “the only source of truth for what was built.” The agent is told to base the post only on that list or on source material it was handed, nothing else.
Here’s the actual rule, word for word, now living in the agent’s instructions:
Never claim a specific tech stack, framework, or feature (React, a
RAG pipeline, a vector DB, etc.) unless it is actually evidenced in
the repo activity or source material you were given for this draft.
If the grounding context doesn't support a dramatic story, write a
smaller, true one rather than manufacturing a bigger one.
That’s the whole fix. No new model, no fine-tuning, no retrieval system of our own (which would be a little ironic given the topic). Just a constraint that forces the agent to treat absence of evidence as a stop sign instead of an invitation to improvise.
How to Stop AI Hallucination Before It Ships
If you’re running any AI agent that generates external-facing content — blog posts, release notes, security advisories, customer-facing docs — the pattern that caught our bug generalizes cleanly:
- Feed it ground truth, not just a topic. A prompt that says “write about what we built” without a list of what was actually built is an invitation to hallucinate. Pass the agent the commit log, the PR titles, the ticket IDs — the boring, verifiable stuff.
- Make “I don’t have enough information” an acceptable output. Most hallucination happens because the model has no path to admitting a gap. Explicitly tell it that a smaller true story beats a bigger invented one.
- Spot-check specificity, not vagueness. Vague drafts are usually honest drafts. The dangerous ones are confident, detailed, and wrong — a named framework, a precise metric, a quote. Those are exactly the claims to verify against source material before anything ships.
- Put the rule in writing, in the system prompt, not in a one-off correction. I caught this once by reading closely. The fix had to be structural so it doesn’t require me catching it every time.
This is the same discipline I’d apply reviewing an IAM policy exception or a vendor’s security questionnaire: don’t just catch the one bad answer, find the gap in the control that let it through, and close that instead.
Key Takeaways
- AI hallucination isn’t limited to chatbots giving wrong facts — it shows up in any generative workflow that lacks hard grounding, including internal content pipelines.
- Our blog-writing agent fabricated a tech stack (a RAG pipeline, a vector database, a frontend framework) that doesn’t exist in our actual codebase.
- The fix was a written constraint in the agent’s system prompt plus a real-activity feed as the only allowed source of truth — not a bigger model or a new tool.
- The generalizable lesson: force “no evidence, smaller true story” as the default behavior, don’t rely on catching fabrications by hand.
We’re building the AI-2002 security reference starter kit for the Secure AI Builder Bootcamp around exactly this kind of control — grounding rules, verification steps, and the guardrails that keep an agent honest in production, not just in a demo. If your team is shipping AI agents into anything customer-facing, this is the gap worth closing before it ships, not after.
Comments