DEV Community

Nova Elvaris
Nova Elvaris

Posted on

The 3-Prompt Rule: Why Limiting AI Turns Produces Better Code

Here's a counterintuitive trick: the fewer prompts you send, the better your AI-generated code gets.

I call it the 3-prompt rule. For any coding task, limit yourself to three interactions. If you can't get a good result in three turns, the problem isn't the AI — it's your approach.

Why 3?

Most AI coding sessions go wrong after turn 3:

  • Turn 1: Clear instruction → good output
  • Turn 2: Focused refinement → better output
  • Turn 3: Edge case or final adjustment → done
  • Turn 4+: "Actually, change this..." → context degradation, contradictions, regression

By turn 5-6, you're often debugging problems the AI introduced while "fixing" earlier problems. The context window is polluted with conflicting instructions.

The 3-Prompt Structure

Prompt 1: The Spec

Give everything upfront. Don't trickle requirements.

Implement a rate limiter middleware for Express.

Requirements:
- Token bucket algorithm
- Configurable: max tokens, refill rate, refill interval
- Per-IP tracking using a Map (no Redis dependency)
- Returns 429 with Retry-After header when limit exceeded
- TypeScript, no external dependencies
- Include JSDoc comments

Edge cases to handle:
- IPv6 addresses
- X-Forwarded-For header (proxy support)
- Memory cleanup for stale entries (>1 hour idle)
Enter fullscreen mode Exit fullscreen mode

This is detailed. That's the point. Front-load your thinking.

Prompt 2: The Fix

Review the output. Identify what's wrong. Fix it all at once.

Two changes needed:

1. The stale entry cleanup runs every 60 seconds but doesn't 
   clear the interval on server shutdown. Add a cleanup() method 
   that clears the interval.

2. The X-Forwarded-For parsing doesn't handle comma-separated 
   lists. Split on comma and take the first (leftmost) IP.

Keep everything else unchanged.
Enter fullscreen mode Exit fullscreen mode

Not "fix the cleanup." Not "also fix the IP parsing." Both, together, in one prompt.

Prompt 3: The Polish

Final adjustments. Tests, documentation, or minor tweaks.

Add 5 unit tests using vitest:
1. Allows requests under the limit
2. Blocks requests over the limit (returns 429)
3. Refills tokens after interval
4. Handles X-Forwarded-For with multiple IPs
5. cleanup() clears the interval and the map
Enter fullscreen mode Exit fullscreen mode

Done. Three prompts. Clean code.

What If 3 Isn't Enough?

If you can't get it done in 3 prompts, that's a signal:

Symptom Root Cause Fix
Prompt 1 output is wrong Your spec is vague Write a better spec before prompting
Prompt 2 introduces new bugs Too many changes at once Break the task into smaller pieces
Prompt 3 still isn't right Task is too complex for one session Split into 2 separate 3-prompt sessions

The rule isn't "never use more than 3 prompts." It's "if you need more than 3, restart with a better plan."

The Pre-Prompt Checklist

Before your first prompt, spend 2 minutes on this:

- [ ] I can describe the exact input and output
- [ ] I've listed all edge cases I know about
- [ ] I've specified the language, framework, and style
- [ ] I've noted what NOT to do (common AI mistakes for this task)
- [ ] The task is small enough for one file or one function
Enter fullscreen mode Exit fullscreen mode

If you can't check all five boxes, you're not ready to prompt yet. Think more, prompt less.

Real Numbers

I tracked my AI coding sessions for two weeks:

Before the 3-prompt rule:

  • Average turns per task: 6.2
  • Tasks completed successfully: 71%
  • Average time per task: 18 minutes

After the 3-prompt rule:

  • Average turns per task: 2.8
  • Tasks completed successfully: 89%
  • Average time per task: 11 minutes

Fewer prompts. Better results. Less time. The constraint forces better preparation.

Try It This Week

  1. Pick a coding task
  2. Write the full spec before opening the AI chat
  3. Limit yourself to 3 prompts
  4. If it's not done in 3, stop — figure out what your spec was missing

The best prompt engineers aren't the ones who write the cleverest prompts. They're the ones who think clearly enough to need fewer of them.

Top comments (0)