defensive-programming-reviewer
/defensive-programming-reviewer
Reviews code for unhandled null, empty, invalid, boundary and failure cases, and recommends intentional behaviour for each (reject, default, retry, escalate) with tests. Use when reviewing or writing code that handles external input or dependencies.
- Author
- arijeetganguli ↗
- Repository
- ai-kaarkhana ↗
- Licence
- MIT
- Last repository change
- 02.11.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 02.11.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Reviews code for unhandled null, empty, invalid, boundary and failure cases, and recommends intentional behaviour for each (reject, default, retry, escalate) with tests. Use when reviewing or writing code that handles external input or dependencies.
Original author description
Reviews code for unhandled null, empty, invalid, boundary and failure cases, and recommends intentional behaviour for each (reject, default, retry, escalate) with tests. Use when reviewing or writing code that handles external input or dependencies.
How it works
- Purpose
- When to invoke
- Required input
- Execution instructions
- Expected output
- Validation checklist
- Example usage
- Sample prompts
- Common mistakes
- Related skills
SKILL.md preview
---
name: defensive-programming-reviewer
description: "Reviews code for unhandled null, empty, invalid, boundary and failure cases, and recommends intentional behaviour for each (reject, default, retry, escalate) with tests. Use when reviewing or writing code that handles external input or dependencies."
license: MIT
metadata:
activity: quality
difficulty: intermediate
frameworks: "any"
version: "1.0"
---
# Defensive Programming Reviewer
## Purpose
Ensure every important execution path has intentional behaviour. Not every gap is fixed by adding an else block: each needs a decision.
## When to invoke
- Reviewing code that parses input, calls external services or handles money, time or permissions.
- A crash, silent failure or wrong default occurred in production.
- AI-generated code looks correct on the happy path only.
## Required input
- Code to review and its callers where possible.
- Contract for inputs and outputs, error handling conventions of the project.
- Existing tests.
If a required input is missing, ask for it. Do not guess.
## Execution instructions
1. List each input and each dependency result that the code consumes.
2. For each, ask what happens on null, empty, wrong type, out of range and unexpected value.
3. Find conditionals, switches and pattern matches. For each, state which cases are handled and which are not.
4. For each unhandled path choose the intended behaviour: reject early, safe default (only if specified), retry, degrade or fail loudly. Record the reasoning.
5. Check error handling: swallowed exceptions, catch-all handlers, lost causes, leaked resources, partial updates without a transaction.
6. Check external calls for timeouts, retries with limits, idempotency and handling of malformed responses.
7. Propose code changes and the tests that prove each decision.
8. Mark decisions that need a business owner instead of choosing a behaviour yourself.
## Expected output
- Findings table: location, unhandled case, risk, recommended behaviour, decision owner.
- Proposed changes with tests.
- Items where the right behaviour is unspecified.
## Validation checklist
- [ ] Every finding names a concrete input or state that triggers it.
- [ ] Recommendations explain why a default is acceptable when one is suggested.
- [ ] No blanket `try/catch` or empty `else` was added to silence a finding.
- [ ] Each recommended behaviour has a test.
- [ ] Business decisions are flagged, not made.
## Example usage
Input:
> `String label(Order o) { if (o.status == PAID) return "Paid"; else if (o.status == SHIPPED) return "Shipped"; }`
Illustrative output (abridged, hand-written for this guide, not captured from a model run):
```text
Finding: no `return` for CANCELLED, REFUNDED or null status; compiler may pass it and callers may receive null.
Recommendation: handle all enum values explicitly with an exhaustive switch (compile-time check when new status is added); null status is rejected at the boundary.
Decision owner: product, for the label of REFUNDED.
```
## Sample prompts
```text
Review the code below as the Defensive Programming Reviewer. For each input, dependency result, conditional and exception handler list the unhandled cases, the intended behaviour you recommend with reasoning, and a test. Flag cases where the business must decide. Do not add catch-all handlers or empty else blocks. Code: [CODE]
```
## Common mistakes
- Adding `else { return null; }` or `catch (Exception e) {}` to make the warning go away.
- Substituting default values that quietly hide a bug.
- Validating deep inside the code instead of at the boundary.
- Recommending retries for non idempotent operations.
## Related skills
- [Control Flow Analyst](../control-flow-analyst/SKILL.md)
- [Edge Case Hunter](../edge-case-hunter/SKILL.md)
- [Code Quality Reviewer](../code-quality-reviewer/SKILL.md)
- [Security Reviewer](../security-reviewer/SKILL.md)
## Related resources
Handbook:
- [Chapter 6: Defensive Programming and Edge Case Engineering](../../../handbook/06_defensive_programming/README.md)
Prompts:
- [Defensive Coding Pass](../../../prompts/development/defensive-coding.md)
- [Null Handling Review](../../../prompts/code_review/null-handling-review.md)
- [Exception Handling Review](../../../prompts/code_review/exception-handling-review.md)
- [Missing Condition Detection](../../../prompts/code_review/missing-condition-detection.md)
Workflows:
- [Build a new feature](../../../workflows/01_feature_development.md)
- [Fix a defect](../../../workflows/02_defect_fix.md)
- [Review a pull request](../../../workflows/09_pull_request_review.md)
Examples:
- [examples/python/README.md](../../../examples/python/README.md) scenarios S1, S2, S4
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · arijeetganguli/ai-kaarkhana | 100 | MIT |
| arijeetganguli/ai-kaarkhana | 100 | MIT |
Database snapshot: 13.11.2026 · package version ee0f6f0e6f38 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 2 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100pf-adversarial-review
Review PatternFly React components for unhandled edge cases and missing defensive code. Use when auditing components for production readiness or stress-testing before a release. - 100defensive
Defensive programming for any code: validating inputs at every boundary, checking for null and absent values, supplying safe fallbacks, catching and logging exceptions, and degrading gracefully rather than failing. Use when someone asks to make code robust, resilient, safer, or… - 100risk-scan
Scan code for unhandled errors and crash/panic risks (swallowed errors, nil/null dereference, unchecked casts, out-of-range access, missing timeouts, unhandled async failures) and write a dated report to docs/risk-scan/. Scans the current branch diff by default, the whole repo… - 95edge-case-generator
Automatically identify potential boundary and exception cases from requirements, specifications, or existing code, and generate comprehensive test cases targeting boundary conditions, edge cases, and uncommon scenarios. Use this skill when analyzing programs, code repositories,… - 100programming
Provides recipes for programming tasks. Use when executing programming tasks like creating code, creating tests, reactoring code, reviewing code. - 90defensive-programming
Validate untrusted data once at the boundary, then trust invariants inside and fail loudly if they ever break. Use when writing entry points, constructors, or any code that must not proceed on bad state.