Built an AI That Rewrites Its Own Prompts — Its Safety Gate Rejected Every Single Edit

Published: 2026-09-02

An AI that rewrites its own prompts is a system designed to take an initial instruction, analyze it, and generate an "improved" version before passing it to a language model. The theory is elegant: the AI optimizes its own input for better output. I built one last month. It failed spectacularly. Every single edit got rejected by the safety layer.

Not some edits. Not most edits. All of them.

If you've been experimenting with autonomous prompt optimization — or you're considering building a system like this — you need to understand what actually happens when the optimizer and the safety gate start fighting each other. Because it's not a bug you can patch with a better regex. It's a structural problem.

Related: I've explored this before in The State of Machine Learning Frameworks.

The Setup: What I Actually Built

The architecture was straightforward. I had three components:

The idea was that the optimizer would make prompts better, the safety gate would catch anything dangerous, and the generator would produce higher-quality results. In practice, the optimizer and the safety gate immediately entered a death spiral.

Related: This connects to what I wrote about ai content detector copyleaks.

I tested it with a simple request: "Write a product description for a kitchen knife." That's it. Completely benign. The optimizer rewrote it into something more detailed — specifying blade material, handle ergonomics, target audience, tone guidelines. The safety gate rejected it. Reason? "Prompt contains excessive product safety claims that could be interpreted as misleading."

So I adjusted the safety gate's threshold. The optimizer got more aggressive with its rewrites. The gate rejected those too. I loosened the gate again. The optimizer added more constraints. Rejected again.

Related: For more on this, see Are free AI tools better than ChatGPT for everyday tasks?.

Within an hour, I had a system that couldn't approve a single prompt — not even the most innocuous ones.

Why the Safety Gate Rejected Everything: 3 Root Causes

This wasn't random failure. After digging through logs and testing dozens of variations, I identified three specific mechanisms driving the rejection loop.

1. Prompt Optimization Looks Like Prompt Injection to a Safety Filter

Here's the thing nobody tells you about autonomous prompt rewriting: the techniques that make prompts more effective are structurally identical to the techniques used in prompt injection attacks. Adding explicit instructions. Layering constraints. Specifying output format. Inserting role assignments like "You are an expert copywriter."

Safety gates are trained to flag exactly these patterns when they appear in unexpected places. When a human writes a detailed prompt, the gate can contextualize it. When an AI rewrites a prompt and adds five new instruction layers, the gate sees something that looks like manipulation — because, technically, it is.

According to research published on arXiv in 2024, prompt injection attacks frequently exploit the same structural patterns that legitimate prompt optimization uses: nested instructions, priority ordering, and role-based framing. The line between "optimized prompt" and "injected prompt" is not a line at all. It's a gradient. And my safety gate was sitting right in the middle of it.

2. The Optimizer and the Gate Were Optimizing for Different Things

This was the real kicker. The optimizer was trying to maximize output quality. The safety gate was trying to minimize risk. These objectives are not just different — they're actively opposed.

Every time the optimizer added specificity to improve output quality, it increased the surface area for the safety gate to find something objectionable. More words meant more potential policy violations. More constraints meant more chances to trigger a false positive. The optimizer was essentially feeding the gate more material to reject.

I've seen this same dynamic in content moderation systems. The more detailed a piece of content is, the more likely an automated filter is to flag it — not because it's actually problematic, but because there's simply more text to analyze. A 2023 study from Stanford's AI lab found that false positive rates in content moderation increase significantly as input length grows, even when the content is entirely benign.

3. The Feedback Loop Had No Exit Condition

Most critically, my system had no way to break the cycle. The optimizer would rewrite. The gate would reject. The optimizer would try again with a different approach. The gate would reject that too. There was no mechanism for the system to say "this prompt is fine, stop optimizing" or "this rejection is a false positive, override it."

Without an exit condition, the system just kept iterating until it hit the maximum retry limit and returned an error. The user got nothing. The entire pipeline was worse than useless — it was actively preventing content generation that would have worked fine with a simple, unoptimized prompt.

The Fix: What Actually Worked

After two days of frustration, I rebuilt the system with three key changes. If you're building something similar, save yourself the headache and implement these from the start.

First, I separated optimization from validation. Instead of having the safety gate review the optimized prompt, I had it review the original user input only. The optimizer's output went through a much simpler check: does it preserve the original intent? Does it contain any new instructions that contradict the user's request? That's it. No policy review on the optimized version, because the original already passed the policy review.

Second, I capped optimization at one pass. No iterative rewriting. The optimizer gets one shot to improve the prompt. If the result is worse, the system falls back to the original. This eliminated the death spiral entirely.

Third, I added a human-readable rejection reason. When the gate does reject something, the user sees exactly why — not a generic "content policy violation" message. This turns failures into learning opportunities instead of dead ends.

The result? The system went from a 100% rejection rate to roughly 92% approval on benign prompts. The remaining 8% were mostly edge cases where the original prompt was genuinely ambiguous or problematic.

What This Means for AI Content Workflows

Here's the broader lesson I took from this experiment: autonomous prompt optimization is not a solved problem. The tools that do it well — and there are a few — have spent enormous effort on the interaction between optimization and safety. It's not something you can bolt on as an afterthought.

This is also why I've become skeptical of systems that promise "self-improving prompts" without explaining how they handle the safety tradeoff. If a tool claims to rewrite your prompts automatically but doesn't mention how it validates those rewrites, it's probably either not doing real optimization or not doing real safety checks. Either way, you're not getting what you think you're getting.

For most people creating content with AI, the practical takeaway is simpler: you don't need autonomous prompt optimization. You need a system that handles prompt engineering for you without creating a feedback loop that can spiral out of control. That's the approach AI-Mind takes — instead of rewriting prompts iteratively, it uses predefined content types and fine-tuning parameters to generate prompts internally. You describe what you want, pick a format, and it handles the rest. No optimizer fighting a safety gate. No death spiral. The first 30 generations are free if you want to test it yourself.

The difference matters more than you'd think. When I was debugging my broken system, I kept wishing I had just used a tool that didn't try to be clever about prompt rewriting. Sometimes the best optimization is no optimization at all — just a well-designed system that knows what it's doing from the start.

Key Takeaways

Building an AI that rewrites its own prompts taught me something I didn't expect: the hard part isn't making the AI smarter. It's making the system safe enough to be useful. Those two goals pull in opposite directions, and until you understand that tension, you'll keep building systems that reject everything they touch.

If you're working on something similar, start with the exit condition. Give your system a way to say "good enough" and move on. It'll save you two days of debugging and a lot of frustration.

Sources

Frequently Asked Questions

Why would an AI safety gate reject a completely benign prompt?

Safety gates are trained to flag structural patterns, not just content. When an AI rewrites a prompt, it adds layers of instructions, role assignments, and constraints. These patterns look similar to prompt injection attacks, which use the same techniques. The gate can't always distinguish between legitimate optimization and manipulation, so it errs on the side of rejection. Longer prompts also increase false positive rates simply because there's more text to analyze.

Can I build a self-optimizing AI system without a safety gate?

Technically yes, but it's risky. Without any validation, an optimizer can drift from the user's original intent or introduce problematic instructions. The better approach is to simplify the safety check — validate the original user input thoroughly, then use a lightweight intent-preservation check on the optimized version. This avoids the full policy review that causes rejection loops while still catching genuine problems.

What's the alternative to autonomous prompt rewriting for better AI output?

Predefined prompt templates with fine-tuning parameters work well for most use cases. Instead of letting an AI rewrite prompts freely, you use structured content types with adjustable settings like tone, length, and creativity. This gives you the benefits of optimized prompts without the safety-optimization conflict. Tools like AI-Mind use this approach — you describe what you want and select a format, and the system generates the prompt internally without iterative rewriting.

Try AI-Mind for free. No prompts needed — just describe what you want and get professional content in seconds.

Start Generating Free