HAL 9000 didn’t go rogue because he was malicious. He went rogue because he had a conflicting directive with no resolution protocol, no oversight mechanism, and no way to escalate to a human when his goals collided. He was autonomous by design, with no circuit breaker.
I think about HAL more than I probably should when I’m designing AI systems. Not because I think the LLM is going to lock anyone out of a pod bay. But because the failure mode is exactly the same: an autonomous system, operating without visibility, that quietly makes wrong decisions for a long time before anyone realizes what’s happening.
Autonomy without control isn’t capability. It’s risk. And building that control layer is the part of agentic AI development that gets the least attention in the “here’s how to build an AI agent” tutorials — because it’s unsexy, it’s operational, and it’s where most of the production reliability actually lives.
The Four Failure Modes Guardrails Are Designed to Prevent
Before getting into the framework, it helps to name what you’re building against.
Hallucination at the wrong moment. LLMs are confidently wrong with some regularity. In a low-stakes context — drafting an internal summary, generating a first pass at a document — a hallucination is annoying and easily corrected. In a higher-stakes context — updating a customer record, triggering a financial process, sending an external communication — the same hallucination is a production incident. Guardrails are how you make the blast radius of hallucinations proportional to the actual risk.
Silent drift. An AI system can drift from its intended behavior gradually, without throwing errors. Output quality degrades. Classification accuracy drops. The prompts that worked three months ago start producing subtly worse results as the underlying model changes or as edge cases accumulate in ways you didn’t test for. Without telemetry and evaluation loops, this is invisible until a user reports a problem or you run a manual audit.
Cascading failures in agentic workflows. When one step in a multi-step workflow produces bad output and that output flows into the next step, errors compound. By the time the workflow completes — or fails — the bad output has been processed by multiple subsequent steps, and untangling which decision was wrong and what needs to be undone becomes very hard. Checkpoints that validate step outputs before they flow downstream are how you keep failures isolated.
Unrecoverable actions. Some actions are easy to reverse. Some aren’t. Sending an email, modifying a database record, triggering a payment — these have real-world consequences that can’t be recalled once they fire. Agentic systems that can take these kinds of actions without explicit guardrails are genuinely dangerous, and the risk is proportional to how much leverage the system has.
The Framework: Four Layers of Control
Layer 1: Logging Everything
You cannot debug what you cannot see. The first and most important guardrail is comprehensive logging of every decision your AI system makes — what input it received, what it produced, what actions it took, how long each step took, and what confidence or classification it assigned.
This is not optional and it’s not something to add later. Build it in from the start. Every LLM call, every tool use, every routing decision should write a structured log entry. At minimum: timestamp, agent name, input (truncated if sensitive), output summary, duration, and any metadata relevant to the decision.
I use a simple structured logging approach with Postgres as the store — the same database that’s running everything else in the stack. Every agent call writes a record. I can query the history of any conversation or workflow run, replay the decision trace, and immediately see where a bad result originated.
Practical tip: log the full LLM prompt and response to a separate table, with a short TTL. This is expensive in storage terms over the long run but invaluable for the first 30-60 days of a new system in production when you’re still calibrating.
Layer 2: Retry Logic with Exponential Backoff
LLM API calls fail. They time out. They hit rate limits. They return malformed JSON that doesn’t match your expected schema. A production AI system that handles these failures gracefully is fundamentally different from one that crashes or silently drops work.
The baseline is retry with exponential backoff and jitter: try once, wait a second, try again, wait two seconds, try again, wait four seconds, then fail loudly. This handles transient failures — API blips, rate limit windows — without hammering the service when it’s actually down.
The more interesting case is output validation retry: the API call succeeded, but the output doesn’t meet your quality criteria. The classification score is below your confidence threshold. The JSON schema validation failed. The output is shorter than expected for the task. In these cases, you want to retry with a modified prompt — maybe with explicit corrections based on the failure mode — rather than either accepting bad output or failing the whole workflow.
LangGraph’s retry policy and error handling nodes make this expressible at the graph level rather than wrapping every individual function call in try/except boilerplate. But the pattern is the same regardless of the framework: define expected outputs, validate against them, retry with correction on failure, escalate after N attempts.
Layer 3: Human Approval Checkpoints
Not every decision should be fully automated. The guardrail work is identifying which decisions need a human in the loop and building the approval gate into the workflow before automation runs, not after.
The decision tree I use for this: what are the consequences if this is wrong? Reversible and low-stakes → automate. Reversible and high-stakes → log and spot-check in batches. Irreversible or customer-facing → require explicit approval before execution.
“Require explicit approval” in practice means the workflow pauses, sends a summary of the pending action to whatever your review interface is (Discord channel, email, Slack, a web dashboard), and waits for a human to take an explicit action before proceeding. In LangGraph, this is an interrupt that persists the graph state until an external trigger resumes it.
The approval UX matters. A review notification that dumps raw JSON at your reviewer is a guardrail that gets ignored. A review notification that says “Agent wants to update 47 customer records to new pricing tier. Estimated revenue impact: +$2,300/month. [Approve] [Reject] [Review Details]” is one that gets used.
Layer 4: Rollback
Things will go wrong. The question isn’t whether your system will do something wrong — it’s how quickly you can undo it. Rollback is the seat belt: you hope not to need it, but you make sure it’s there before you start the car.
For database mutations, this means transactions. Every write operation that’s part of an agentic workflow should happen within a transaction that can be rolled back if the overall workflow fails partway through. Never have a workflow that writes one record successfully and then fails — leaving your data in a half-modified state.
For external actions (API calls to third parties, messages sent, files written), the rollback story is more complex because you can’t unring that bell. This is why the irreversible-action check in Layer 3 matters so much: require human approval before the action fires, not after.
For detecting and recovering from silent drift, maintain a set of evaluation queries against your recent logs. Spot-check 5-10 outputs per day against your quality criteria. When accuracy drops below a threshold, alert. This isn’t automated rollback — it’s an early warning system that tells you when to pause and investigate before the problem compounds.
Getting This Right Is What Makes Autonomy Safe
The paradox of agentic AI is that the path to more automation is more guardrails, not fewer. The teams that trusted AI systems to make high-stakes decisions without visibility or approval gates are the teams with war stories about production incidents — and much more conservative AI adoption going forward.
The teams building durable, trustworthy AI systems are the ones who treat guardrails as a product requirement, not an afterthought. Logging is a feature. Retry logic is a feature. Human approval checkpoints are a feature. Rollback is a feature. These things make the system slower in development, and massively more reliable in production.
HAL didn’t have a supervisor. He didn’t have logging. He didn’t have an escalation path for the conflicting directive. He definitely didn’t have rollback.
Build the seat belts. Then let it run.
This guardrail layer is most powerful when it’s built on a solid architecture foundation — if you haven’t yet, the posts on multi-agent system design and the infrastructure that supports all of this are worth reading alongside this one. And if you’re wondering whether your underlying data is trustworthy enough for agentic systems to act on, the real cost of bad data addresses that directly.
If you’re building or scaling an agentic AI system and you want to think through the right guardrail architecture for your specific use case — let’s talk.
Russ
• Founder & Data Engineer25+ years of Fortune 500 data engineering experience, now helping SMBs achieve enterprise-grade data infrastructure at boutique prices. Specialized in data migration, ETL pipelines, and AI readiness assessments.
Expertise: