DEV Community

Nova Elvaris
Nova Elvaris

Posted on

The Dependency Firewall: Isolate AI Changes So One Bad Prompt Can't Break Your Build

You've been there: you ask your AI assistant to refactor one function, and suddenly three unrelated tests are failing.

The problem isn't the AI. It's that you gave it access to everything and hoped for the best.

The Dependency Firewall Pattern

Before you let AI touch any code, draw a boundary. Define exactly which files it can modify — and which files must remain untouched.

Here's the prompt structure I use:

You are modifying ONLY these files:
- src/auth/login.ts
- src/auth/login.test.ts

DO NOT modify, reference, or suggest changes to:
- src/auth/session.ts
- src/api/routes.ts
- Any file outside src/auth/

If your change requires modifications outside this boundary,
STOP and list the dependencies instead of making the change.
Enter fullscreen mode Exit fullscreen mode

Why This Works

Most AI coding failures happen at the boundary — the AI "helpfully" edits a shared utility, renames an export, or changes a type signature that ripples through your codebase.

The Dependency Firewall forces the AI to treat your codebase like a microservice architecture: each task has a blast radius, and nothing leaks outside it.

Three Rules for Setting Your Firewall

1. One directory per prompt. If your change spans multiple directories, split it into multiple prompts. Each prompt gets its own firewall.

2. List the untouchables explicitly. Don't just say "only edit X." Also say "do NOT edit Y and Z." AI models respond better to explicit exclusions.

3. Require a dependency report. End every prompt with: "If this change requires modifications outside the boundary, list them as a dependency report instead of making the change."

Real Example

I was adding rate limiting to an Express API. Without a firewall, the AI rewrote my middleware chain, changed the error handler signature, and updated three route files.

With the firewall:

Boundary: src/middleware/rate-limit.ts (new file)
Untouchable: src/middleware/auth.ts, src/middleware/error.ts, src/routes/*

Add a rate limiting middleware that exports a configurable
limiter factory. Do NOT wire it into routes — just create the
middleware. I'll integrate it separately.
Enter fullscreen mode Exit fullscreen mode

Result: one clean file, zero side effects, easy to review.

The Takeaway

Treat AI code changes like database migrations: scope them tightly, make them reversible, and never let them cascade without your explicit approval.

Your build will thank you.


What's your strategy for limiting AI blast radius? I'd love to hear other approaches in the comments.

Top comments (0)