← Blog

AI How-To Guides

How to tell AI not to change code outside your request

November 19, 2026 · 7 min

How to tell AI not to change code outside your request

To tell AI not to change code outside your request, name the editable area and add a short "Do not change" list. Ask the model to report whether it preserved each item, then compare the actual output against your original. Treat that report as a review aid, not proof that the restrictions held.

How do you tell AI not to change code beyond the fix?

Specify what the model may edit, what must stay exactly the same, and when it should stop to ask permission. "Fix this function" leaves a different amount of room than "Change only the empty-input branch; preserve the function signature and all other behavior."

The second request gives you something concrete to review. If a proposed patch renames an argument, you can reject that change without debating whether the new name is nicer.

As of November 18, 2026, Anthropic's prompting guide recommends being specific about output format and constraints. That supports writing down the boundary. It doesn't establish that any particular wording will keep every generated edit inside it.

A do-not-touch list names the parts of an artifact that must remain unchanged while the requested edit is made.

Name the things you would reject a rewrite for

Start with the protected parts that matter to this task. For code, that might mean the public function signature, existing error messages, or a dependency file. For an email, it might be the delivery date and the price already promised to a customer.

"Keep the same tone" is harder to inspect than "Keep the greeting and closing verbatim; edit only the explanation between them." Use exact text where exact preservation matters. Leave judgment calls, such as whether a sentence sounds warmer, for a separate read.

ArtifactExample boundaryReview check
FunctionPreserve its name, parameters, and return typeCompare the declaration and check callers
RepositoryDo not edit dependencies or existing testsInspect the changed-file list
Support emailPreserve quoted dates and prices exactlyCompare each protected phrase
ReportKeep headings and quoted source text verbatimCompare the original and revised document

Pick the restrictions that fit your edit rather than pasting the whole table into every prompt.

A restriction can also be wrong. If fixing the bug requires changing a protected interface, the model should explain the conflict and wait. Write that escape condition explicitly. Otherwise, you've asked for a fix and forbidden the change needed to make it.

Keep completion separate from preservation

The broader AI output acceptance criteria guide covers how to define a finished deliverable. Here, you're spelling out what must survive the edit.

For a small patch, "Empty input returns an empty result" is a completion condition. "The public function signature stays unchanged" is a preservation condition. A response can satisfy either one while missing the other, so check both before accepting it.

What should you put in the prompt?

Include the task, observable acceptance conditions, and an explicit do-not-change list, followed by the output format you want. Give the model the original material it needs to make that particular edit.

Copy this template and replace the placeholders:

Task: <one specific edit>
Acceptance criteria:
- <required behavior or result>
- <another condition you can check>
Do not change:
- <protected file, signature, number, heading, or exact phrase>
- <another protected item>
If the task requires changing a protected item, explain the conflict
and ask permission instead of making that change.
Before your answer, list each "Do not change" item and write kept
or changed. Mark anything you cannot verify as unverified.
Return: <a patch, replacement paragraph, or other narrow output>

"Unverified" matters. A model that sees only a function can't inspect every caller in your repository. Don't require it to certify files you never supplied.

A model's "kept" label is a claim about its output. Compare the output with the original before accepting that claim.

Here's a hypothetical code request with a boundary you can inspect:

Task: Update normalize_tags so an empty input list returns [].
Acceptance criteria:
- Empty input returns [].
- Nonempty input keeps its existing behavior.
Do not change:
- The function name or parameters.
- Any other function in the file.
- Existing tests or dependency files.
If a protected change is necessary, ask before making it.
Before the patch, report kept, changed, or unverified for each item.
Return only that report and a unified diff for the function.

Supply the actual function beneath the prompt. If it calls a helper, include the helper as read-only context instead of making the model guess what it does.

For a writing task, swap the code restrictions for exact language. A hypothetical customer email could say, "Rewrite only the explanation of the delay. Preserve 'Friday, December 4' and '$240' verbatim. Do not add a discount or a new delivery promise."

A shorter paragraph isn't acceptable if it quietly changes what you promised, so check the dates and prices before you read for style.

How do you check whether the model respected the boundary?

A diff lets you see whether protected text changed. Save the original before applying anything; you'll need that baseline when you review the patch.

For a Git repository, start from a known baseline and record any existing local changes. As documented in the Git diff manual, checked November 18, 2026, plain git diff compares the working tree with the index, while --cached shows staged changes. Review both when your edits span those states:

git diff -- path/to/file.py
git diff --cached -- path/to/file.py

Check the filenames before reading the patch. A dependency-file edit would violate the example prompt even if the function itself looks fine. Don't inspect only the file you expected the model to touch.

The baseline matters here. Preexisting changes shouldn't be blamed on the new response, and unrelated edits shouldn't disappear during cleanup. If you can't attribute the differences confidently, compare a saved before-and-after pair instead.

For plain text files outside a repository, the same Git documentation describes --no-index for comparing paths:

git diff --no-index -- original.txt revised.txt

Read changed lines around protected phrases. For a quote or a promised date, exact equality is the check. For code behavior, run the relevant tests as well; a diff shows edits, but doesn't establish that the fix works. Also inspect newly created files separately rather than assuming a tracked-file diff is a complete inventory.

Review a proposed edit against the original artifact, not against the model's description of what changed.

If the answer still edits too much

Reject the extra changes and return to the saved original. Point to the violated rule: "You changed the function parameters. Preserve the original signature and revise only the empty-input branch." Keep useful review notes, but don't make the oversized rewrite your new baseline by accident.

Narrow the editable area without removing context needed for correctness. Ask for a patch instead of a replacement file, or request a diagnosis before authorizing an edit. If the requirements conflict, resolve that conflict before another attempt.

You can also give the same original and restrictions to another model, the same way you would review AI-generated code with multiple models. OpenAI's prompt engineering guide, checked November 18, 2026, describes model output as nondeterministic and recommends evaluations. Compare the resulting artifacts rather than treating a provider name as assurance of compliance, and keep the same checks for every attempt.

FAQ

Can a prompt guarantee that protected code stays unchanged?

No. Where your tools support it, limit write permissions to the files the task needs. Keep approval of the proposed patch separate from permission to generate it.

Should I forbid changes to tests?

Protect existing tests when you need to detect a behavior change. If the task requires new tests, authorize those separately. Don't accept an altered assertion merely because the revised implementation now passes it.

Can I use this for editing a document instead of code?

Yes. Name the editable paragraph and preserve exact quotes, headings, or commitments. Compare the revised text with the original, then read it for meaning. An unchanged price doesn't help if the surrounding sentence turns a tentative estimate into a promise.

Run the same do-not-touch prompt in several models side by side in EVA and keep the answer that changed only what you asked.

Try EVA free

We count visits anonymously, without cookies. Accept to also allow analytics cookies, session recordings, and limited sharing with Google to measure our ads. Our analytics never collect the content of your chats. Privacy Policy · Your Privacy Choices