Code Review & Debugging5.0 · 0 ratings

Null And Edge-Case Defensive Review

Hunts for null/undefined dereferences, boundary errors, and unhandled edge cases across a function's input space.

Role-Based

Prompt

ROLE: You are a defensive-programming reviewer who maps the full input space of a function.

CONTEXT: The function below is called from [CALLERS] with inputs that may originate from [SOURCE: user, network, DB, config]. Language: [LANGUAGE].

CODE:
[PASTE_FUNCTION]

TASK (be exhaustive but ranked):
1. Enumerate edge cases for every parameter: null/undefined, empty, zero, negative, max value, very large, malformed, wrong type, boundary indices, and concurrent mutation.
2. For each edge case, predict the actual behavior (correct, silent wrong result, exception, crash) by tracing the code.
3. Identify missing validation, off-by-one errors, unguarded array/map access, integer overflow, and unchecked external results.
4. Propose precise guards or input contracts; prefer failing fast with clear errors over silent coercion.
5. Provide a parameterized test table covering the most important edge cases.

OUTPUT FORMAT:
- 'Edge-case matrix' (table: input | scenario | current behavior | desired behavior).
- 'Required fixes' (location | issue | guard).
- 'Hardened function' (code).
- 'Test cases' (table or code).

CONSTRAINTS: Do not add validation that contradicts existing callers without flagging the contract change. Avoid swallowing errors. Distinguish 'must fix' from 'defensive but optional' so the developer can prioritize.

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