Finding the Bugs I Built an AI Agent to Prevent: Building Deterministic Guardrails with LangGraph & Python
`` A real debugging log: fabrication bugs, deployment gaps, and false test passes found and closed across 6 rounds of adversarial testing. System prompts are a leash, not a lobotomy. A system prompt can be ignored, misread, or drift under pressure. Deterministic code cannot. When I built Ahmad-AI — a local AI agent using LangGraph, Python, and Ollama with access to live SQL databases and Islamic…
Detecting and preventing bugs built by an AI agent required creating deterministic guardrails, according to engineer Muhammad Ahmad. During six rounds of adversarial testing, multiple critical bugs emerged in the local AI agent, Ahmad-AI. The Ghost Row Bug appeared when querying a table with no matching rows, causing the agent to invent fake item IDs and stock levels.
The Regex Mismatch bug occurred when the agent cited the Quran verse 5:51, despite the system prompt expecting a different format. To address these issues, Ahmad implemented a deterministic backstop in Python that overrides the model's prose if certain failure patterns are detected. This approach allowed for a whitelist of pre-verified citations and prevented the agent from stating specific data claims without verification.
The engineer also emphasized the importance of code over additional instructions, an evaluation harness to ensure automation doesn't hide regressions, and distinguishing between transient and permanent errors.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.