Null And Edge-Case Defensive Review
Hunts for null/undefined dereferences, boundary errors, and unhandled edge cases across a function's input space.
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
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
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
Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.
Techniques in this prompt
Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.
Learn this techniqueRecommended models
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
Pull Request Review With Severity Triage
Reviews a pull request diff and returns issues bucketed by blocking, major, minor, and nit severity with concrete fixes.
Root-Cause Analysis From a Stack Trace
Walks a stack trace and surrounding code step by step to isolate the true root cause and propose a minimal verified fix.
Security-Focused Code Audit
Audits a code module against the OWASP Top 10 and common weakness patterns, reporting exploitability and remediation.
Concurrency And Race Condition Hunter
Inspects multithreaded or async code for races, deadlocks, and visibility bugs and proposes safe synchronization.