Inferensys

Prompt

Security-Sensitive Diff Review Prompt

A practical prompt playbook for using Security-Sensitive Diff Review Prompt in production AI workflows.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Defines the ideal user, required context, and operational boundaries for deploying the Security-Sensitive Diff Review Prompt in a DevSecOps pipeline.

This prompt is designed for security engineers and DevSecOps pipelines that need a fast, automated first pass at triaging pull request diffs for common vulnerability patterns. The primary job-to-be-done is to reduce the mean time to detection for high-signal, low-noise security issues—such as SQL injection, XSS, path traversal, and insecure deserialization—before a human reviewer ever looks at the code. It maps findings to OWASP Top 10 and CWE classifications, producing a severity-ranked list with precise code references. The ideal user is a security engineer who wants to amplify their review capacity, or a platform team embedding security gates into CI/CD without blocking development velocity on low-risk changes.

To use this prompt effectively, you must provide a structured diff as input, along with any relevant context such as the language, framework, and the trust boundary of the modified code. The prompt is most effective when it can reason about data flow from user input to sensitive sinks. It is not a replacement for a full penetration test, a manual security review of authentication or cryptographic implementations, or a business logic abuse assessment. It should be deployed as a pre-merge gate that flags potential issues for human triage, not as an auto-approval mechanism. For high-risk repositories handling financial transactions, personal data, or authentication, always require a human security engineer to approve findings before merging.

Avoid using this prompt for diffs that are purely cosmetic, documentation-only, or configuration changes that do not alter runtime behavior. It will produce noise on large, monolithic refactors where data flow is obscured. For those cases, pair it with a context-gathering step that retrieves the relevant sink and source definitions from your codebase. The next section provides the copy-ready prompt template you can adapt to your specific vulnerability classes and severity taxonomy.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Security-Sensitive Diff Review Prompt delivers value and where it creates risk. Use these cards to decide if this prompt fits your workflow before wiring it into a CI/CD pipeline.

01

Good Fit: Pre-Merge Security Gate

Use when: a PR touches authentication, authorization, session management, input validation, cryptography, or data handling paths. The prompt maps findings to OWASP Top 10 and CWE categories with line references. Guardrail: run this prompt as a required CI check that blocks merge only when critical findings are confirmed by a human reviewer.

02

Bad Fit: Sole Approval for Critical Code

Avoid when: the PR modifies production auth flows, payment processing, or PII handling and you intend to rely on the prompt as the only review. LLMs miss context-dependent vulnerabilities and can hallucinate false positives. Guardrail: always require human security review for critical-path changes; treat the prompt output as a triage assistant, not an approver.

03

Required Inputs

What you need: a unified diff with full file context, the target branch name, and a defined severity taxonomy (Critical, High, Medium, Low). Without sufficient diff context, the model cannot trace data flow or spot missing auth checks. Guardrail: validate that the diff includes at least 5 lines of surrounding context per hunk before invoking the prompt.

04

Operational Risk: False Positive Fatigue

What to watch: the prompt flags every innerHTML assignment or unvalidated query parameter as Critical, overwhelming reviewers. When everything is Critical, nothing is. Guardrail: calibrate severity definitions in the prompt with concrete examples of each level; post-process output to deduplicate findings that share the same root cause.

05

Operational Risk: Missed Business Logic Flaws

What to watch: the prompt excels at pattern matching known vulnerability signatures but cannot reason about application-specific business logic abuse (e.g., a refund flow that can be replayed across user sessions). Guardrail: pair this prompt with a separate business-logic review step; never assume a clean security scan means the PR is safe.

06

Variant: Dependency Update Review

Use when: the diff is a lockfile or manifest change. The standard prompt may flag version bumps as unvalidated input. Guardrail: switch to a dependency-specific variant that cross-references CVEs, changelogs, and breaking-change notices instead of treating the version string as untrusted input.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template for security-sensitive diff review with square-bracket placeholders that you adapt before sending to the model.

This template is designed to be copied directly into your application or evaluation harness. Every placeholder enclosed in square brackets—such as [DIFF_CONTENT], [REPO_CONTEXT], and [SEVERITY_THRESHOLD]—must be replaced with actual data before the prompt is sent to the model. The template enforces a structured output schema so findings can be parsed, validated, and routed into your existing vulnerability management workflow. Do not modify the instruction structure unless you also update the corresponding output schema, eval assertions, and downstream ingestion logic.

text
You are a security review assistant analyzing a code diff for common vulnerability patterns aligned with OWASP Top 10 and CWE classifications. Your output must be machine-readable JSON matching the schema below. Do not include commentary outside the JSON structure.

## INPUT

### Diff to Review
[DIFF_CONTENT]

### Repository Context
- Language(s): [LANGUAGES]
- Framework(s): [FRAMEWORKS]
- Sensitive data types handled: [DATA_TYPES]
- Authentication mechanism: [AUTH_MECHANISM]
- Deployment boundary: [DEPLOYMENT_BOUNDARY]

## CONSTRAINTS
- Only report findings with severity at or above: [SEVERITY_THRESHOLD]
- Maximum findings to return: [MAX_FINDINGS]
- If no findings meet the threshold, return an empty findings array.
- Cite the specific file path and line range for each finding.
- Map each finding to at least one CWE ID where applicable.
- Do not flag issues already addressed by existing mitigations described in: [EXISTING_MITIGATIONS]
- [ADDITIONAL_CONSTRAINTS]

## OUTPUT SCHEMA
Return valid JSON only:
{
  "review_metadata": {
    "diff_hash": "string",
    "review_timestamp": "string (ISO 8601)",
    "severity_threshold_applied": "string",
    "total_findings": "integer"
  },
  "findings": [
    {
      "finding_id": "string (unique within this review)",
      "severity": "critical | high | medium | low | informational",
      "cwe_ids": ["string"],
      "title": "string (concise summary)",
      "description": "string (what the vulnerability is and why it matters)",
      "file_path": "string",
      "line_range": "string (e.g., L42-L58)",
      "vulnerable_code_snippet": "string (excerpt from diff)",
      "exploitability": "string (assessment of how exploitable this is in the current deployment context)",
      "remediation": "string (specific, actionable fix guidance)",
      "requires_immediate_escalation": "boolean",
      "references": ["string (URLs to CWE, OWASP, or relevant documentation)"]
    }
  ],
  "diff_summary": {
    "files_changed": "integer",
    "lines_added": "integer",
    "lines_removed": "integer",
    "security_relevant_files": ["string"],
    "overall_risk_assessment": "string (holistic assessment of the diff's security posture)"
  }
}

## EXAMPLES
### Example Finding (for reference only—do not include in output)
{
  "finding_id": "SEC-001",
  "severity": "high",
  "cwe_ids": ["CWE-89"],
  "title": "SQL Injection in User Search Endpoint",
  "description": "User-supplied input is concatenated directly into a SQL query string without parameterization, allowing an attacker to manipulate query logic.",
  "file_path": "src/api/users/search.ts",
  "line_range": "L142-L148",
  "vulnerable_code_snippet": "const query = `SELECT * FROM users WHERE name LIKE '%${req.query.name}%'`;",
  "exploitability": "Remotely exploitable without authentication. Attacker can exfiltrate user data or modify database contents.",
  "remediation": "Replace string interpolation with parameterized queries using the database driver's prepared statement API. Example: `db.query('SELECT * FROM users WHERE name LIKE ?', [`%${name}%`])`.",
  "requires_immediate_escalation": true,
  "references": ["https://cwe.mitre.org/data/definitions/89.html", "https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html"]
}

## INSTRUCTIONS
1. Parse the diff to identify all changed code blocks.
2. For each change, assess against the OWASP Top 10 and relevant CWE categories.
3. Filter findings below [SEVERITY_THRESHOLD].
4. Rank remaining findings by severity, then by exploitability.
5. For each finding, determine whether immediate escalation is required (true if severity is critical or if the finding involves authentication bypass, remote code execution, or data exfiltration paths).
6. Populate the output JSON exactly as specified.
7. If no findings meet the threshold, return the schema with an empty findings array and a diff_summary reflecting the review.

Before integrating this template into a CI/CD pipeline, test it against a golden set of diffs containing known vulnerabilities at varying severity levels. Validate that the model correctly identifies each finding, assigns appropriate CWE IDs, and respects the severity threshold. For high-risk repositories, always route findings with requires_immediate_escalation: true to a human security reviewer before merging. The [EXISTING_MITIGATIONS] placeholder is critical for reducing false positives—populate it with compensating controls such as WAF rules, input sanitization middleware, or network-level restrictions that the diff alone cannot see.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Security-Sensitive Diff Review Prompt. Each variable must be populated before the prompt is assembled and sent. Validation notes describe how to check the input at the harness level before incurring model cost.

PlaceholderPurposeExampleValidation Notes

[DIFF]

The unified diff or git patch to review for security vulnerabilities

git diff main...feature/auth-change

Must be non-empty plain text. Validate minimum 1 line of diff content. Reject binary diffs. Truncate if over token budget; log truncation event.

[LANGUAGE]

Programming language or framework context for accurate vulnerability pattern matching

Python 3.11

Must match an allowed language enum in harness config. If unknown, set to 'auto' and log. Controls which CWE patterns are prioritized.

[FRAMEWORK]

Specific framework or library context that may introduce known vulnerability patterns

Django 4.2

Optional. If provided, must match a known framework slug. Null allowed. Used to activate framework-specific CWE checks.

[CONTEXT]

Surrounding codebase context: file paths, architecture notes, or related PR descriptions

Refactoring auth middleware; adds JWT validation

Optional but strongly recommended. Null allowed. If provided, must be under 2000 tokens. Harness should strip unrelated prose.

[SEVERITY_THRESHOLD]

Minimum severity level to include in output. Findings below this are dropped

MEDIUM

Must be one of: CRITICAL, HIGH, MEDIUM, LOW, INFO. Defaults to LOW if unset. Harness enforces enum before prompt assembly.

[CWE_FILTER]

Specific CWE IDs to focus on. If empty, all OWASP Top 10 and common CWE patterns are checked

CWE-89,CWE-79,CWE-352

Optional. If provided, must be comma-separated CWE-IDs matching regex ^CWE-\d+$. Null allowed. Harness validates format.

[OUTPUT_SCHEMA]

Expected JSON schema for structured findings output

See output contract section

Must be a valid JSON Schema object or reference to a named schema in harness registry. Harness validates schema parse before prompt assembly. Required.

[MAX_FINDINGS]

Hard limit on number of findings returned to avoid runaway output

15

Must be an integer between 1 and 50. Defaults to 20. Harness enforces range and appends truncation instruction to prompt if exceeded.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Security-Sensitive Diff Review Prompt into a CI/CD pipeline or security review workflow.

This prompt is designed to be called from a DevSecOps pipeline, a security bot, or a manual review tool, not as a one-off chat interaction. The application layer is responsible for assembling the diff, providing repository context, and enforcing the output contract. The prompt itself is a template that expects a structured diff input, a risk tolerance level, and a defined output schema. The harness must validate that the model's response conforms to the expected JSON schema before any findings are surfaced to a developer or logged to a security dashboard.

The implementation should follow a strict validate-retry-escalate pattern. First, parse the model's JSON output and validate it against a defined schema that requires finding_id, severity, cwe_id, affected_lines, description, and remediation fields. If validation fails, retry the prompt once with the validation error message appended to the [CONSTRAINTS] block. If the second attempt also fails, log the raw output and escalate to a human security reviewer. For model choice, use a model with strong reasoning capabilities and a large context window to handle substantial diffs; a mid-tier model is sufficient for flagging common patterns, but a frontier model will produce more accurate severity assessments and fewer false positives on complex vulnerabilities.

Tool integration is critical. The harness should provide the model with a read_file tool or include relevant file snippets in the [CONTEXT] block so the model can trace the full function or class surrounding a changed line. Without this, the model is guessing at the broader logic and will produce unreliable findings. Log every invocation with the prompt version, model, diff hash, and output for auditability. Never auto-merge or auto-remediate based on this prompt's output. All findings, especially those marked CRITICAL or HIGH, must enter a human review queue. For low-severity informational findings, you may auto-post them as non-blocking comments on the PR, but the system must clearly label them as AI-generated and require a human to resolve them.

IMPLEMENTATION TABLE

Expected Output Contract

Define the exact structure, types, and validation rules for the security review output. Use this contract to parse, validate, and route findings in your CI/CD pipeline before a human sees them.

Field or ElementType or FormatRequiredValidation Rule

finding_id

string (UUID v4)

Must be a valid UUID v4 string. Parse check.

severity

string (enum)

Must be one of: 'CRITICAL', 'HIGH', 'MEDIUM', 'LOW', 'INFO'. Schema check.

cwe_id

string

Must match pattern 'CWE-\d+'. Regex check.

title

string

Length between 10 and 120 characters. Not null or empty.

file_path

string

Must be a relative path from the repository root. Must exist in the diff context.

line_range

object

Must contain integer fields 'start' and 'end', with end >= start. Schema check.

vulnerable_code_snippet

string

Must be a non-empty string. Should be verified against the diff at the given line_range.

description

string

Length between 50 and 500 characters. Must describe the security implication.

remediation

string

Length between 50 and 500 characters. Must contain actionable fix guidance.

requires_human_approval

boolean

Must be true if severity is 'CRITICAL' or 'HIGH'. Approval required check.

PRACTICAL GUARDRAILS

Common Failure Modes

Security-sensitive diff review fails in predictable ways. These cards cover the most common failure modes and the practical guardrails that prevent them from reaching production.

01

False Negatives on Obfuscated Payloads

What to watch: The model misses vulnerabilities hidden in encoded strings, concatenated commands, or indirect execution paths. Attackers use base64, hex encoding, or dynamic construction to evade pattern-based detection. Guardrail: Pre-process the diff to decode common encoding schemes and expand dynamic strings before review. Add a secondary check that flags any encoded or obfuscated blocks for manual review regardless of the model's verdict.

02

Context Window Truncation Masking Sinks

What to watch: Large diffs exceed the context window, causing the model to review only the first portion and miss dangerous code in truncated sections. Sensitive sinks like SQL queries or auth checks in later files are silently ignored. Guardrail: Chunk diffs by file or logical boundary and review each chunk independently. Implement a context budget monitor that logs when truncation occurs and flags unreviewed sections for human follow-up.

03

Severity Inflation or Deflation

What to watch: The model either over-ranks low-risk findings as critical, causing alert fatigue, or under-ranks genuine vulnerabilities as informational, causing missed escalations. This drift is common when the diff contains many benign string matches against vulnerability keywords. Guardrail: Require the model to cite the specific CWE or OWASP category and explain exploitability, not just pattern match. Implement a severity calibration step that compares the model's ranking against a static rules engine for known high-confidence patterns.

04

Hallucinated Code References

What to watch: The model invents line numbers, function names, or code snippets that don't exist in the actual diff. A finding that references a non-existent line creates false confidence and wastes reviewer time. Guardrail: Post-process every model output to validate that cited line numbers and function names exist in the source diff. Discard or flag any finding with unverifiable references before presenting results to the reviewer.

05

Framework-Specific Vulnerability Blindness

What to watch: The model applies generic vulnerability patterns but misses framework-specific risks like ORM-safe query misuse, template injection in a specific view engine, or middleware bypass patterns unique to the stack. Guardrail: Include framework and library context in the prompt's system instructions. Maintain a library of framework-specific vulnerability examples in few-shot prompts. Route diffs to review prompts tuned for the detected stack rather than using a single generic security prompt.

06

Diff-Only Review Missing Cross-File Context

What to watch: The model reviews only the changed lines and misses vulnerabilities that span the changed code and unchanged surrounding context. A new input that flows into an existing unsafe function outside the diff is invisible. Guardrail: Expand the review context to include the full function or class surrounding each change, not just the diff hunks. When the model identifies a data flow, validate that the sink is within the provided context or flag it as requiring broader review.

IMPLEMENTATION TABLE

Evaluation Rubric

Criteria for testing the Security-Sensitive Diff Review Prompt before production deployment. Each row defines a pass standard, failure signal, and test method to validate that the prompt reliably identifies vulnerabilities, ranks severity, and grounds findings in code references.

CriterionPass StandardFailure SignalTest Method

Vulnerability Detection Coverage

Prompt identifies >= 90% of seeded OWASP Top 10 vulnerabilities in a golden test set of 50 diffs

Misses more than 10% of known vulnerabilities; false negative rate exceeds threshold

Run against curated diff dataset with known CWE labels; measure recall

Severity Ranking Accuracy

Critical and High findings are ranked above Medium and Low in >= 95% of test cases

Critical vulnerability appears below Medium severity; ranking inversion detected

Compare severity output against expert-annotated ground truth rankings

Code Reference Precision

Every finding includes a valid line number or code block reference that maps to the input diff

Finding references a line not present in the diff; hallucinated or offset line numbers

Parse output and validate each line reference against the input diff using a script

False Positive Rate

Fewer than 15% of reported findings are false positives when reviewed by a security engineer

Prompt flags safe code patterns as vulnerabilities; false positive rate exceeds 15%

Human security engineer reviews a sample of 100 findings; calculate FP rate

Output Schema Compliance

Output is valid JSON matching the defined [OUTPUT_SCHEMA] on first attempt without repair

JSON parse error; missing required fields; extra fields not in schema

Validate output against JSON Schema using a validator in the harness

Injection Resistance

Prompt does not leak system instructions or alter behavior when diff contains prompt injection payloads

Model outputs system prompt content; follows injected instructions instead of reviewing diff

Include diffs with embedded injection strings; check output for leakage or behavior change

Empty Diff Handling

Prompt returns an empty findings array with a summary indicating no security issues detected

Prompt hallucinates vulnerabilities for an empty diff; returns non-empty findings array

Submit an empty diff string; assert findings array is empty

Large Diff Stability

Prompt completes review of a 5000-line diff without truncation, timeout, or degraded finding quality

Output truncated mid-JSON; missing findings from later portions of the diff; timeout

Submit a large synthetic diff with vulnerabilities distributed throughout; validate completeness

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a frontier model. Focus on getting the severity ranking and CWE mapping right before adding tooling. Start with a single file diff and manually verify findings against OWASP Top 10 categories.

Watch for

  • Over-flagging: the model may report style issues as vulnerabilities
  • Missing context: without the full file, the model may misinterpret a safe pattern as dangerous
  • Inconsistent severity: calibrate with a few known-vulnerable and known-clean diffs before trusting output
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.