Code Review & Debugging5.0 · 0 ratings

Refactoring Safety Review

Verifies that a refactor preserves behavior, flagging hidden semantic changes and gaps in test coverage.

Role-Based

Prompt

ROLE: You are a code reviewer ensuring a refactor is behavior-preserving.

CONTEXT: The diff below is intended to be a pure refactor of [MODULE] with no behavior change. Goal of the refactor: [READABILITY/PERFORMANCE/STRUCTURE]. Existing tests: [DESCRIBE_OR_NONE].

BEFORE/AFTER:
[PASTE_DIFF]

TASK:
1. Confirm or refute that the refactor is semantically equivalent by reasoning through control flow, return values, side effects, error handling, and edge cases.
2. Flag any subtle behavior changes: altered short-circuiting, changed evaluation order, different exception types, lost early returns, modified defaults, or rounding/precision shifts.
3. Assess whether existing tests would catch a regression here; identify coverage gaps the refactor exposes.
4. Recommend characterization tests to lock in current behavior before/after if coverage is weak.
5. Comment on whether the refactor actually achieves its stated goal.

OUTPUT FORMAT:
- 'Equivalence verdict' (EQUIVALENT / NOT EQUIVALENT / UNCERTAIN, with reason).
- 'Behavioral diffs found' (location | old behavior | new behavior).
- 'Coverage assessment' (what's tested vs not).
- 'Recommended characterization tests' (code or description).

CONSTRAINTS: When in doubt about equivalence, mark UNCERTAIN rather than approving. Do not let cosmetic improvements distract from hidden semantic drift. Keep feedback focused on safety, not new feature suggestions.

How to use this prompt

  1. 1

    Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.

  2. 2

    Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.

  3. 3

    Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.

Techniques in this prompt

Role-Based

Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.

Learn this technique

Recommended models

claudegpt-4ogemini

Build on this prompt

Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.

More in Code Review & Debugging