Key takeaways

  • AI coding agent guardrails are rules you set before the agent touches your code: plan first, work on a new branch, never push, never touch production, and name the files it must not edit.
  • A plan you approve is the cheapest safety check. In my workflow every change starts as a written plan, and I read it before any code is written.
  • Review catches real mistakes. In my project a plan would have skipped database migrations in production, and a security rule would have blocked real article URLs. Both were fixed before they shipped.
  • Guardrails are not only for the agent. Backups, a rollback tag, a config test and a deploy runbook protect you when a human or an agent gets it wrong.

Why I use AI coding agent guardrails on a live site

I run buildwithjit.com as a solo project. The site uses TanStack Start for the front end, FastAPI for the API and Oracle Autonomous Database for storage. I use Google Antigravity, an AI coding agent, to write most of the code changes. Then I merge a pull request on GitHub and deploy by hand on the server.

An agent that can edit files, run commands and commit code is useful, and it is also a risk. The security risks of AI coding agents are real: a bad instruction, a wrong assumption or an overconfident change can reach your live site. Cognitive surrender is the other risk, where you stop checking because the output looks fine. Security researchers call the general problem excessive agency, where a model is given more power than it needs (see OWASP LLM06: Excessive Agency). The guardrails below are how I stay in control. This is what I actually do, not a product review.

The rules I give the agent every time

I keep a short block of hard rules and paste it into every task:

Hard rules:
1. Plan first. Do not write code until I approve the plan.
2. Work on a new branch. Never push. Never touch main.
3. Never connect to the production database or any live service.
4. Run only the named tests. No broad test discovery.
5. Do not touch the protected files (ads.txt, the AdSense meta tag,
   the share image, the global stylesheet, existing article URLs,
   and the body of the legal pages).
6. No new dependencies.
7. Run the guard scripts before every commit.
8. End with what was verified and what could not be verified.

Each rule closes a specific hole. On GitHub, protected branches can enforce the pull request rule for you:

RuleThe risk it closes
Plan firstThe agent builds the wrong thing quickly
New branch, no push, no mainA bad change reaches the live code or my history
No production databaseA test or migration touches real data
Named tests onlyA broad test run triggers side effects or takes too long
Protected filesRevenue, SEO and legal pages get edited by accident
Guard scriptsStyle and content rules (in my case, no long dashes and no hardcoded page content) are checked by code, not by memory
"What could not be verified"The agent has to admit what it did not check

Plan first: why it matters more than the code review

When I approve a plan, I am reviewing a few paragraphs, not a diff of hundreds of lines. A good plan lists the files to change, the tests to write, the risks and the open questions. If the plan is wrong, I reject it before any code exists.

I also ask a second AI assistant to review the plan. A second reader finds different problems, but I still make the final call myself.

Two real mistakes my review caught

1. A safety switch that would have skipped migrations

One plan proposed gating database migrations behind an environment variable, so they would run only when that variable was set. On my production server that variable is not set. The gate would have silently skipped the migrations on the live site. I told the agent not to implement it. A plan review caught it. A passing test would not have, because the test environment is not production.

2. A security rule that would have blocked real pages

I added nginx rules to return a not-found response for sensitive files such as configuration files and the database wallet. The first version used a pattern that matched any path starting with the word "credentials". That would also have blocked a real article whose URL begins with that word. The fix was to match only file-like names that end in an extension, and to add a smoke test that checks that real article URLs still load.

The lesson is the same in both cases: rules that protect you can also break you, so test the safe path as well as the blocked one.

Guardrails beyond the agent: deploy safety

The agent never deploys. I do, from a written runbook:

  1. Take a database backup before any change that touches the schema.
  2. Start the API with a single worker for the first restart after a migration, because my migrations have no cross-process lock and two workers could try to change the same table at once.
  3. Run nginx -t before reloading nginx, so a broken config never goes live.
  4. Clear the cache with a scan-based command, never with a blocking key search on a shared Redis.
  5. Run a small set of smoke tests: redirects, headers, blocked files, allowed slugs, sitemap.
  6. Keep a rollback tag at the last good commit, and push it to the remote so the server can use it.

For risky actions in automation, human-in-the-loop approval steps follow the same idea: a person approves before the irreversible step.

A checklist you can copy

Before the agent startsAfter the agent finishes
Write the hard rules and paste themRead the "could not verify" list
List protected filesDiff only the files in the plan
Ask for a plan, not codeRun the guard scripts yourself
Name the tests it may runMerge by pull request, not by direct push
Decide the rollback pointDeploy from a runbook, with a backup

What guardrails do not do

They do not make the agent correct. They make mistakes cheaper to find and cheaper to undo. Some risks stay with you: a plan can look fine and still be wrong, and an agent can follow every rule and still misunderstand the goal. Read the plan, read the diff, and keep backups.

If you want a second pair of eyes on an AI coding workflow, you can reach me through the contact page. I take on AI and automation work under JIGNESH IT SERVICE.

FAQ

What are AI coding agent guardrails? They are rules and checks that limit what an AI coding agent can do: which branch it works on, which files it may edit, which commands it may run and what it must report at the end.

Should an AI coding agent be allowed to push to main? I do not allow it. The agent works on a new branch, and I merge by pull request after review.

Why ask for a plan before code? A plan is short and easy to review. Rejecting a wrong plan costs a minute. Rejecting wrong code costs much more.

Can an AI coding agent run database migrations safely? Only if it never touches the production database, and you apply migrations yourself with a backup, a single worker and a rollback plan. Test migrations against a fake cursor or a copy, not live data.

Do guardrails remove the need to review the code? No. They reduce the chance and the cost of mistakes. You still read the plan and the diff.

NEXT IN SERIES

AI Coding Agents Are a Security Risk: How Malicious Instructions Can Hijack Your Workflow

AI coding agents can read files, run commands and install packages. Here is how attackers can misuse them and a practical checklist to keep your projects safe.

Continue Reading