---
title: "Guardrails in Harness Engineering"
url: "https://zuey.me/articles/guardrails-trong-harness-engineering?lang=en"
locale: en
access: members
full_text: false
published_at: "2026-05-11T02:00:00.000Z"
tags: ["Claude Code", "Vibe Coding", "AI Agents", "AI", "SaaS"]
translations:
  vi: "https://zuey.me/articles/guardrails-trong-harness-engineering.md?lang=vi"
  zh: "https://zuey.me/articles/guardrails-trong-harness-engineering.md?lang=zh"
  ko: "https://zuey.me/articles/guardrails-trong-harness-engineering.md?lang=ko"
  ja: "https://zuey.me/articles/guardrails-trong-harness-engineering.md?lang=ja"
---
# 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.

![Guardrails in Harness Engineering](https://media.zuey.me/blog/2026/bcba6286-260511-guardrails-trong-harness-engineering-177960.webp)

> **INFO:** **TL;DR:** A prompt is just a suggestion; guardrails are the contract. Write "don't do X" 11 times in all caps and the agent can still do X. If you really want to stop it, you have to build "guardrails" at the infrastructure layer: hooks, permission gates, sandboxes, and separated credentials.

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" =))))

[YouTube: https://www.youtube.com/watch?v=7H0rz_3uv04](https://www.youtube.com/watch?v=7H0rz_3uv04)

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

> **WARN:** **This isn't the model's fault. It's the HARNESS's fault.** More specifically, it's the fault of MISSING GUARDRAILS.

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

> **INFO:** The most important point: guardrails must live AT THE INFRASTRUCTURE LAYER, not the prompt layer. I'll explain why in the next section.

---

### 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:

| Layer | Control type | Reliability | Example |
| --- | --- | --- | --- |
| 1 | Administrative (weakest) | Probabilistic | System prompt, AGENTS.md, "don't do X" |
| 2 | Engineering | Stronger | Tool design, context gates |
| 3 | **Guardrails / hooks** (strongest) | **Deterministic** | **PreToolUse hooks, permission system, sandbox** |
| 4 | Substitution | Absolute | Fully 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.

> **WARN:** Most important of all: **a system prompt is an administrative control, not an engineering control**. You're writing a "policy" for the AI - and policies can be violated.

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:

---

*Phần còn lại dành cho thành viên có quyền đọc toàn bài (Knowledges, Kết hợp, Cộng đồng) — see plans at https://zuey.me/pricing*
