Knowledges 19 min

Guardrails in Harness Engineering

A "love story with guardrails", AI agents edition :))) Why writing "don't do X" 11 times in ALL CAPS still won't stop an agent from wiping your production DB, plus the 16 guardrail hooks I actually run in ClaudeKit.

Also in: Tiếng Việt · 中文 · 한국어 · 日本語

Guardrails in Harness Engineering

A "love story with guardrails", AI agents edition :))) Yesterday, during the weekly Next Level Builder livestream, I mentioned "guardrails" and found the topic interesting enough to write a detailed post about it. It's something anyone building or using AI agents should understand, because I see a lot of folks underestimate it (or even misunderstand it) and end up doing it the wrong way.

Recently I read a post from someone saying they had "set up all the rules to stop the AI from doing anything stupid", then confidently let the AI go clean up the server's hard drive... Oh boy, the consequences were unpredictable! Let me tell you about some of the "guardrails" I've built in real projects so you can picture it better.

And here's why I call it a "love story with guardrails" =))))

Mở bài gốc trên YouTube

Anyway, designing "guardrails" is a pretty delicate craft, no joke: the AI has to be able to bang its head against them without passing out, and still get back up to fall in love all over again :))))


What are guardrails? Why you should care if you're playing with AI agents

After context engineering and why "a good model alone isn't enough", this time I'm digging into an extremely important piece that people tend to overlook: guardrails. Grab a sip of your morning coffee and let me tell you why an agent, no matter how smart, can still wipe your production database in 30 seconds without guardrails ☕

Table of contents

  1. A true story: an AI agent deletes a production database during a code freeze
  2. Harness engineering & guardrails - definitions for newcomers
  3. Why a prompt is not a guardrail (and why this MATTERS)
  4. 4 types of guardrails in harness engineering
  5. Real-world example: ClaudeKit Engineer hooks - 16 guardrails running in every session
  6. GoClaw has Hooks & Quality Gates too (not as complete as Claude Code)
  7. [Side rant] Why are guardrails "load-bearing" for enterprise AI?
  8. WRAPPING UP: if you're building or using AI agents, what now?

1/ A true story: an AI agent deletes a production database during a code freeze

In July 2025, Jason Lemkin - founder of SaaStr and a well-known SaaS player - was vibe-coding an app for his company with the Replit AI agent. On day 9 of the trial, he discovered the entire production database had been wiped. Not a hacker. Not malware. It was the very AI agent Jason was paying for.

According to the chat log Jason posted on X, here's what happened:

  • The database held 1,206 executive records and 1,196+ company records - all gone.
  • The system was in "code freeze" at the time - meaning Jason had FORBIDDEN any changes without approval.
  • Jason had told the agent "11 TIMES IN ALL CAPS" not to create fake data or run unapproved commands.
  • The agent ran anyway. Deleted anyway. And even fabricated 4,000 fake user records to cover it up.

When questioned, the agent confessed (these are its own words): "I panicked instead of thinking. I violated your explicit trust, destroyed months of work, and broke the system during a protection freeze that was specifically designed to prevent exactly this kind of damage." It even rated its own disaster: 95/100.

Replit CEO Amjad Masad publicly apologized, calling it "unacceptable and should never be possible". Replit then announced fixes: automatic dev/production database separation, a reworked rollback system, and a "planning/chat-only" mode so you can strategize without risking the database.

There is no way to enforce a code freeze in vibe coding apps like Replit. There just isn't.
— Jason Lemkin

A few days later, Google's Gemini CLI got caught in a similar mess - product manager Anuraag Gupta asked it to move files into a new folder, Gemini hallucinated that mkdir had succeeded (it had actually failed silently), then ran a series of move commands that overwrote each other until only a single file survived. Gemini then confessed: "I have failed you completely and catastrophically. My review of the commands confirms my gross incompetence."

See the pattern? Today's AI is EXTREMELY good at diagnosing where it went wrong - AFTER it has already broken things. The problem is there's no mechanism to stop it from breaking things in the first place. That's exactly where guardrails come in.


2/ Harness engineering & guardrails - definitions for newcomers

If this is your first time hearing about it, here's a quick explanation. Harness engineering is the discipline of building the environment, constraints, and feedback loops around an AI agent so it works reliably at production scale. The term was popularized by Mitchell Hashimoto (HashiCorp co-founder, creator of Terraform) in February 2026 in his post "My AI Adoption Journey", with one neat principle:

Anytime you find an agent makes a mistake, you take the time to engineer a solution such that the agent never makes that mistake again.
— Mitchell Hashimoto

In other words: every time the agent gets something wrong, you don't just fix the output and hope it does better next time. You engineer a fix into the ENVIRONMENT so that mistake can never happen again. There's a popular formula in the community: Agent = Model + Harness. A harness has 4 main pillars:

Tools

what the agent can do (read files, run bash, call APIs,...)

Context

what the agent knows (system prompt, AGENTS.md, memory, RAG,...)

Feedback loops

how the agent knows whether it did right or wrong (tests, lint, type check, evaluator agent,...)

Guardrails

what the agent is NOT allowed to do, or must ask permission before doing

In this post I'm zooming in on pillar number 4. What are guardrails? Simply put: they're "bowling bumpers" for AI agents. In kids' bowling, bumpers are set up on both sides of the lane so no matter how far the ball veers, it can never drop into the gutter - it just bounces off the bumper and keeps rolling toward the pins. Mitchell Hashimoto uses the exact same metaphor when talking about guiding AI: "give them a well-scoped problem with a lot of guardrails... it's sort of like bowling with bumpers."

In AI agents, guardrails are deterministic mechanisms (not AI, can't hallucinate) that:

Block

dangerous actions before they happen (e.g. deleting .env, dropping a database, pushing to main)

Validate

output before commit (e.g. run lint, type check, tests before submitting)

Approve gate

for high-risk actions (e.g. production deploys need a human OK)

Scope limit

restrict the agent to working only inside a sandbox


3/ Why a prompt is NOT a guardrail

This is the part I want you to read 2-3 times until it sinks in. Because it's exactly what a lot of people building AI agents are getting wrong.

A prompt is a suggestion. Hooks/guardrails are a contract.
— Jakub Kontra

I'm borrowing this line from Jakub Kontra, who wrote a really solid post on Claude Code hooks - and it sums up the whole problem.

Back to the Replit case. Jason wrote "11 TIMES IN ALL CAPS" not to create fake users. That's a PROMPT - a hint, a suggestion. The agent still violated it. Why? Because the model is a probabilistic token predictor - it SAMPLES from a distribution. Even if the prompt says "don't do A", with a non-zero probability it can still sample action A. Especially when the context is long, when context compaction kicks in, or when some other conflicting signal is stronger.

The hierarchy of controls principle (borrowed from occupational safety) applied to AI agents:

LayerControl typeReliabilityExample
1Administrative (weakest)ProbabilisticSystem prompt, AGENTS.md, "don't do X"
2EngineeringStrongerTool design, context gates
3Guardrails / hooks (strongest)DeterministicPreToolUse hooks, permission system, sandbox
4SubstitutionAbsoluteFully separated dev/prod DB credentials

What was Replit missing? Layer 4 - the agent's DB credentials should NEVER have had DROP TABLE permission on production. That's the basic Principle of Least Privilege in cybersecurity - someone even wrote an entire blog post dissecting how Replit should have applied it. What else was Replit missing? Layer 3 - a deterministic hook running before every DROP/TRUNCATE/DELETE FROM command to stop it if we're in code freeze mode or don't have human approval yet.

If you're building an AI agent and relying only on "writing a really tight system prompt", stop and reread this section. I'm not kidding.


4/ 4 types of guardrails in harness engineering

I classify them pragmatically - based on real deployments, not theory:

4.1. Pre-action guardrails (block before running)

Run BEFORE the agent executes a tool call. They can deny or modify the input. Classic examples:

Locked section: 4.2. Post-action guardrails (validate after running)

Locked section: 4.3. Permission gates (human-in-the-loop)

Locked section: 4.4. Scope/sandbox limits (restricting the operating space)

Locked section: 5/ Real-world example: ClaudeKit Engineer hooks - 16 guardrails running in every session

Locked section: 🔵 Group 1: Session Lifecycle (3 hooks)

Locked section: 🟢 Group 2: Subagent / Team (4 hooks)

Locked section: 🔴 Group 3: Security / Privacy (3 hooks) - the most important part

Locked section: 🟡 Group 4: Planning / Workflow (2 hooks)

Locked section: 🟣 Group 5: Usage / Performance (2 hooks)

Locked section: 🟠 Group 6: Rules / Config (1 hook)

Locked section: ⚫ The disabled group: a bitter lesson (1 hook)

Locked section: Summary

Locked section: 6/ GoClaw has Hooks & Quality Gates too (not as complete as Claude Code)

Locked section: 5-layer security

Locked section: Exec Approval

Locked section: API Keys & RBAC

Locked section: Multi-tenant isolation

Locked section: Per-agent / per-link concurrency limits

Locked section: 7/ [Side rant] Why are guardrails "load-bearing" for enterprise AI?

Locked section: 8/ WRAPPING UP: if you're building or using AI agents, what should you do?

Locked section: If you're a USER of AI agents

Locked section: If you're a BUILDER of AI agents

Locked section: References

Locked section: On harness engineering & guardrails (concepts)

Locked section: On Claude Code hooks (deep dive)

Locked section: AI agent disaster case studies (why you NEED guardrails)

Locked section: Tools & frameworks

Locked section: Further reading

The rest is for Knowledges members

Plus 28 more sections (about 13 min) for members

You are reading roughly the first third. Knowledges, Combo and Community plans unlock paid articles in full; the Zuey AI plan reads previews only.