Automated Code Review Prompts
Automated Code Review Prompts
Problem Solving & Analysis
The Prompt
The Logic
1. Separating P0/P1/P2 Keeps Reviews Focused and Reduces Conflict
WHY IT WORKS: Reviews fail when everything is treated equally. Categorizing feedback into Must-Fix (blocking), Should-Fix, and Nice-to-Have prevents bikeshedding and accelerates merges. It also reduces emotional conflict: authors can accept optional suggestions without feeling forced. This creates a predictable review culture where “Request Changes” has a clear meaning. Teams using priority buckets see fewer review cycles because authors fix the true blockers first.
EXAMPLE: A missing input validation that can crash production is P0. Renaming a variable is P2. Without this, reviewers may spend 30% of time on style debates while missing a race condition. Priority buckets ensure the PR improves safety and correctness without turning into a perfection contest.
2. Requirement Checks Prevent “Correct Code That Solves the Wrong Problem”
WHY IT WORKS: Many PRs pass tests but violate product requirements: incorrect edge behavior, missing constraints, incomplete acceptance criteria. A review that starts from requirements (what should change) catches mismatches early. This also avoids future rework: you don’t merge a technically correct implementation that misses business expectations. Anchoring on requirements makes feedback objective and reduces subjective debate.
EXAMPLE: A PR claims to “add pagination” but returns inconsistent ordering, causing users to see duplicates. The code might be correct locally but fails requirement “stable pagination.” A requirements-first review catches this and asks for sorting and cursor-based pagination. This prevents production incidents.
3. Security Lens Finds High-Impact Issues That Tests Often Miss
WHY IT WORKS: Unit tests rarely cover adversarial inputs: SQL injection, path traversal, SSRF, auth bypass, secret leakage. A structured security review ensures these checks happen consistently. This is crucial because security defects can be catastrophic even if rare. Including security in every review builds a defensive engineering culture and reduces “security as an afterthought.”
EXAMPLE: If code builds SQL with string concatenation, that’s a P0 injection risk even if tests pass. If logs include tokens, that’s a secret leak risk. If request handlers lack auth checks, that’s authorization bypass. These are not “style”; they are production-grade risks that a formal review must catch.
4. Correctness Checks Focus on Edge Cases and Concurrency
WHY IT WORKS: Most production bugs come from edge cases: nulls, retries, timeouts, concurrency, partial failures. Code reviews that explicitly inspect these paths catch bugs before release. This also guides better tests: reviewers can request targeted cases that reproduce failures. For distributed systems, idempotency and retries are common blind spots—reviews must surface them.
EXAMPLE: Payment webhook handler must be idempotent because providers retry. A review might require a deduplication key and DB constraint to prevent double charges. Or a background job might need a lock to prevent concurrent runs. These issues often don’t appear in happy-path tests but cause serious incidents.
5. Observability Ensures You Can Debug What You Ship
WHY IT WORKS: Even good code fails sometimes. Without logs, metrics, and traces, incidents become expensive investigations. Reviewing observability ensures the PR includes structured logging for failures, meaningful metrics (latency, error rate), and trace context for distributed flows. This is a reliability multiplier: it reduces mean time to detect and resolve issues. Observability is often skipped in feature-focused PRs; making it a review section improves operational maturity.
EXAMPLE: If a new endpoint calls an external service, include metrics: external call latency, timeout count, retry count. Add logs with request ids. Add trace spans. When the provider slows down, you’ll know quickly. Teams that enforce observability in PRs respond faster to incidents and avoid “we don’t know what happened” crises.
6. Suggested Patch Snippets Convert Critique Into Momentum
WHY IT WORKS: Reviews can stall when feedback is high-level (“handle errors better”). Providing patch snippets or pseudocode accelerates resolution and reduces misunderstanding. It also increases review quality: the reviewer must think through implementation. While reviewers shouldn’t do the author’s job, small snippets are effective for common patterns (input validation, safe SQL, retry backoff). This reduces review cycles and improves team velocity.
EXAMPLE: Instead of “add input validation,” provide a snippet using pydantic schema with constraints. Instead of “avoid SQL injection,” show parameterized query. Instead of “add idempotency,” suggest a unique index and early return. These concrete suggestions turn a review from a critique into a collaboration.
Example Output Preview
Sample: PR Review Summary (Realistic)
PR: “Add webhook endpoint for payment provider callbacks.”
Decision: Request Changes.
P0 Must-Fix: No signature verification → auth bypass; webhook retries can double-apply payment; missing timeout handling on downstream DB call.
P1 Should-Fix: Add structured logs with request id; add metric payment_webhook_processed_total; add integration test with retry scenario.
P2 Nice-to-Have: Rename variable ‘data’ to ‘event’; add docstring.
Suggested Patch: add HMAC verification middleware; enforce idempotency key with unique constraint; return 2xx on duplicate events.
Prompt Chain Strategy
Step 1: Review the PR
Prompt: Use the main Automated Code Review prompt with the diff.
Expected Output: P0/P1/P2 feedback + patches + merge checklist.
Step 2: Turn Must-Fix Into Tests
Prompt: “Write tests that reproduce each P0 issue and then pass after fixes.”
Expected Output: A concrete test suite that enforces review findings.
Step 3: Rollout and Monitoring Plan (High Risk)
Prompt: “Create rollout steps, feature flags, dashboards, and alert thresholds for this change.”
Expected Output: Safe deployment plan.
Human-in-the-Loop Refinements
Require a “Risk Level” Field in Every PR
Risk drives rigor. Technique: low/med/high with required checks per level.
Use a PR Checklist Template
Prevent omissions. Technique: tests, docs, observability, rollback plan.
Run a Security Checklist for External-Facing Endpoints
Focus on auth, validation, secrets. Technique: include signature verification and rate limiting.
Ask for Load/Perf Evidence When Complexity Changes
Prevent regressions. Technique: benchmark or add metrics.
Enforce “No P0 Without Test”
If it’s a real bug, it should be testable. Technique: require reproduction tests.
Rotate Reviewers to Avoid Blind Spots
Fresh eyes catch issues. Technique: cross-team review for critical modules.