Inferensys

Prompt

PR Risk Assessment and Reviewer Recommendation Prompt

A practical prompt playbook for using PR Risk Assessment and Reviewer Recommendation Prompt in production AI workflows.
Risk analyst performing AI risk assessment on laptop, risk matrices visible, casual office risk session.
PROMPT PLAYBOOK

When to Use This Prompt

Defines the job, ideal user, and constraints for the PR Risk Assessment and Reviewer Recommendation Prompt.

This prompt is designed for platform engineering teams building automated code review assignment systems. Its primary job is to analyze a pull request's diff to produce a structured risk assessment and a list of recommended reviewers. The ideal user is a CI/CD pipeline, a code review bot, or a developer tool that needs to programmatically route PRs to the right people based on objective signals rather than manual assignment. The required context includes the full PR diff, a CODEOWNERS file, and ideally a historical contribution graph or expertise map for the repository.

Use this prompt when you need a consistent, auditable method for triaging incoming pull requests before human review begins. It is appropriate for repositories where code ownership is well-defined and where change complexity correlates with review effort. Do not use this prompt for repositories without a CODEOWNERS file or where the team structure is too fluid for ownership to be meaningful. It is also not a substitute for a security-focused static analysis pipeline; this prompt assesses process risk and reviewer fit, not vulnerability detection. The output is a machine-readable risk score with rationale and a suggested reviewer list, designed to be consumed by an assignment system rather than displayed directly to end users.

Before implementing this prompt, ensure you have a reliable method for extracting the PR diff and the CODEOWNERS file. The prompt's effectiveness depends entirely on the quality of these inputs. For high-risk repositories, always pair this automated assessment with a human-in-the-loop approval step for the final reviewer assignment, especially when the model recommends reviewers who have not recently contributed to the affected code paths. The next step after reading this section is to review the prompt template and understand the required input schema.

PRACTICAL GUARDRAILS

Use Case Fit

This prompt is designed for automated code review pipelines that need to triage risk and route PRs to the right reviewers. It works best when integrated into a deterministic system with clear ownership data. It is not a replacement for security architecture review or human judgment on sensitive logic changes.

01

Good Fit: Automated Triage in Mature Repos

Use when: you have a CODEOWNERS file, consistent directory structures, and a history of PR reviews. Guardrail: The prompt maps changed paths to ownership rules and past reviewer activity, making it reliable for routing standard feature and bugfix PRs.

02

Bad Fit: First-Time or Unstructured Repos

Avoid when: the repository lacks ownership metadata, has no review history, or is a monorepo with ambiguous boundaries. Guardrail: Without clear signals, the model will guess. Fall back to a round-robin assignment or a default team mention instead of using this prompt.

03

Required Inputs

What you need: a unified diff, the CODEOWNERS file content, and a list of recent reviewers per directory. Guardrail: If any input is missing, the prompt should be aborted. Do not run it with partial context, as it will hallucinate ownership or risk scores.

04

Operational Risk: Over-Reliance on Automation

Risk: Teams may skip human verification if the model sounds confident. Guardrail: The output must be treated as a suggestion. Always require a human to confirm the reviewer list, especially for PRs flagged as high-risk or touching security-sensitive paths.

05

Latency Sensitivity

Risk: This prompt requires multiple data sources and a large diff, which can be slow for large PRs. Guardrail: Truncate the diff to changed file paths and chunk hunks if the input exceeds the context window. Use a fast model for triage and reserve deep analysis for high-risk flags.

06

Eval Drift Over Time

Risk: Reviewer expertise and team structures change, making historical data stale. Guardrail: Re-evaluate the prompt's accuracy monthly by comparing its suggestions against actual reviewer assignments. Retire or retrain the ownership mapping if precision drops below a defined threshold.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template for assessing PR risk and recommending reviewers based on diff analysis.

This section provides the core prompt template for the PR Risk Assessment and Reviewer Recommendation system. The template is designed to be copied directly into your prompt management tool, IDE, or orchestration layer. It accepts a structured diff, repository context, and team configuration to produce a risk score, rationale, and a ranked list of recommended reviewers. Every placeholder is enclosed in square brackets and must be replaced with real data at runtime by your application harness. The prompt is self-contained enough to be tested in a playground before integration, but it assumes the caller has already assembled the necessary inputs.

text
You are a code review risk analyst. Your task is to analyze a pull request diff and produce a structured risk assessment with reviewer recommendations.

## INPUTS

### Pull Request Diff
```diff
[PR_DIFF]

Repository Context

  • Repository: [REPOSITORY_NAME]
  • Base branch: [BASE_BRANCH]
  • Target branch: [TARGET_BRANCH]
  • Changed files: [CHANGED_FILE_LIST]

Team Configuration

  • CODEOWNERS file:
text
[CODEOWNERS_CONTENT]
  • Historical reviewer expertise (file path -> reviewer mapping):
json
[HISTORICAL_EXPERTISE_JSON]
  • Available reviewers with current workload:
json
[AVAILABLE_REVIEWERS_JSON]

Risk Thresholds

  • High risk: changes to [HIGH_RISK_PATHS], files > [HIGH_RISK_FILE_SIZE] lines changed, or [HIGH_RISK_PATTERNS]
  • Medium risk: changes to [MEDIUM_RISK_PATHS] or files > [MEDIUM_RISK_FILE_SIZE] lines changed
  • Low risk: everything else

OUTPUT SCHEMA

Return a single JSON object with this exact structure:

json
{
  "risk_assessment": {
    "risk_level": "high|medium|low",
    "risk_score": 0-100,
    "rationale": "string explaining the risk factors identified",
    "risk_factors": [
      {
        "factor": "string describing the risk factor",
        "severity": "high|medium|low",
        "evidence": "specific file paths, line counts, or patterns observed"
      }
    ]
  },
  "reviewer_recommendations": {
    "primary_reviewers": [
      {
        "reviewer": "string username or team name",
        "reason": "string explaining why this reviewer is recommended",
        "expertise_match": ["file paths or patterns they own"],
        "workload_note": "string describing current workload if relevant"
      }
    ],
    "optional_reviewers": [
      {
        "reviewer": "string username or team name",
        "reason": "string explaining secondary relevance"
      }
    ],
    "required_approvals": 1-3
  },
  "warnings": [
    "string describing any concerns that don't fit the risk factors above"
  ]
}

CONSTRAINTS

  1. Every risk factor must cite specific evidence from the diff or changed file list. Do not speculate.
  2. Primary reviewers must be drawn from CODEOWNERS or historical expertise data. Do not recommend reviewers without evidence of ownership or past contributions to the changed files.
  3. If a changed file has no clear owner, flag it in warnings and recommend a reviewer based on adjacent file ownership or team lead.
  4. The risk_score must be derived from the risk thresholds provided, not from general intuition.
  5. If the diff exceeds [MAX_DIFF_SIZE] lines, note in warnings that the analysis may be incomplete and recommend human triage.
  6. Do not include reviewers who are the PR author. Check [PR_AUTHOR] against all recommendations.
  7. If the PR touches files in [REQUIRED_REVIEWER_PATHS], ensure at least one primary reviewer is from the required reviewer list.

EXAMPLES

Example 1: Low-risk documentation change

Input: 3 files changed, all in /docs/, 45 total lines added Output risk_level: low, risk_score: 10, primary_reviewers: [docs-team]

Example 2: High-risk auth change

Input: 12 files changed, includes /auth/, /middleware/, /config/secrets, 340 lines changed Output risk_level: high, risk_score: 85, primary_reviewers: [auth-team-lead, security-oncall]

Example 3: Medium-risk API change with unclear ownership

Input: 5 files changed, includes /api/v2/handlers/ with no CODEOWNERS entry Output risk_level: medium, risk_score: 55, warnings: ["No CODEOWNERS entry for /api/v2/handlers/"]

INSTRUCTIONS

Analyze the PR diff against the provided context and thresholds. Return only the JSON object. Do not include explanations outside the JSON.

To adapt this template for your team, replace the risk threshold patterns with your actual high-risk paths, file size limits, and pattern definitions. The historical expertise JSON should be populated from your git history analysis pipeline — map file paths to reviewers who have previously authored or reviewed changes in those paths. The available reviewers JSON should include current workload signals from your project management or code review queue system. If your team uses a different risk taxonomy, adjust the risk_level enum and risk_score range accordingly. Always test the prompt with known PRs where you already know the correct risk level and reviewer assignments before deploying to production.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the PR Risk Assessment and Reviewer Recommendation Prompt. Each placeholder must be populated before the prompt is sent. Validation notes describe how to verify the input quality before execution.

PlaceholderPurposeExampleValidation Notes

[PR_DIFF]

The full unified diff of the pull request to analyze

git diff origin/main...feature/refactor-auth

Must be non-empty and parseable as a valid diff. Reject if only whitespace changes or binary files without context. Minimum 10 lines of meaningful code changes for reliable risk scoring.

[PR_TITLE]

The PR title as it appears in the pull request system

Refactor authentication middleware for session handling

Must be a non-empty string under 200 characters. Used for context alignment with the diff. Reject if title contains only ticket numbers without description.

[PR_BODY]

The full PR description including linked issues and context

Closes #4521. This refactor extracts session logic...

Can be empty string if no description exists. If present, parse for linked issue references (e.g., #1234, JIRA-567) to cross-reference with changed files. Null allowed.

[CODEOWNERS_FILE]

The full contents of the repository CODEOWNERS file

src/auth/ @team-security docs/ @tech-writers

Must be a valid CODEOWNERS format string. Parse to extract ownership patterns. If file is missing or empty, set to empty string and note that reviewer recommendations will rely solely on git history heuristics.

[GIT_BLAME_HISTORY]

Recent git blame output for files changed in the PR

git blame -L 1,100 src/auth/session.ts --since=6.months

Must contain author names and commit hashes. Used to identify historical contributors for reviewer recommendation. If empty or unavailable, set to null and flag that expertise-based recommendations will be degraded.

[CHANGE_COMPLEXITY_THRESHOLD]

Team-defined thresholds for classifying change complexity

{"low": 50, "medium": 200, "high": 500}

Must be a valid JSON object with numeric thresholds for low, medium, and high. Validate that low < medium < high. Default to {"low": 100, "medium": 300, "high": 600} if not provided. Used to calibrate risk score output.

[TEAM_REVIEWER_POOL]

List of available reviewers with their expertise areas

[{"name": "alice", "areas": ["auth", "api"]}, {"name": "bob", "areas": ["database"]}]

Must be a valid JSON array of objects with name and areas fields. Areas must be non-empty arrays of strings. If empty, reviewer recommendations will be limited to CODEOWNERS and git history matches. Null allowed for open-source repos without defined teams.

[PREVIOUS_INCIDENT_LOG]

Recent incidents or bugs linked to the changed files or areas

[{"file": "src/auth/session.ts", "incident": "INC-342", "severity": "high"}]

Can be null or empty array if no incident history exists. If present, must be valid JSON array with file, incident, and severity fields. Used to escalate risk scoring for historically fragile areas. Validate severity values against allowed enum: low, medium, high, critical.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the PR risk assessment and reviewer recommendation prompt into a CI/CD pipeline or code review assignment system.

This prompt is designed to sit inside a code review automation pipeline, not as a standalone chat interaction. The primary integration point is a webhook handler or CI job that receives a pull request event, extracts the diff and relevant metadata, and passes it to the model. The harness is responsible for assembling the [PR_DIFF], [PR_METADATA], [CODEOWNERS_FILE], and [HISTORICAL_REVIEW_DATA] placeholders before the model call. The model's structured output is then parsed and used to update the PR with a risk label, a reviewer recommendation comment, or an assignment via the platform's API.

Input Assembly and Validation: Before calling the model, validate that the diff is non-empty and under the model's context window. For large PRs, truncate the diff to changed files with the highest risk signals (e.g., files matching **/*.sql, **/auth/**, or **/*.tf) and include a summary of the remaining files. The [CODEOWNERS_FILE] should be the raw content from the repository's CODEOWNERS file at the target branch. [HISTORICAL_REVIEW_DATA] should be a pre-computed mapping of file paths to reviewers who have previously approved changes in those areas, extracted from the platform's API. If this data is unavailable, the prompt will still function but the harness should log a warning that reviewer recommendations are based solely on CODEOWNERS and diff analysis. Output Parsing and Validation: The model returns a JSON object with risk_score, risk_rationale, and recommended_reviewers. The harness must validate that risk_score is an integer between 1 and 5, risk_rationale is a non-empty string, and recommended_reviewers is an array of strings matching valid platform usernames. If validation fails, retry once with a repair prompt that includes the validation errors. If the retry also fails, fall back to a default risk label of 3 and assign reviewers from the CODEOWNERS file only.

Human Review and Escalation Gates: For PRs with a risk score of 4 or 5, the harness should not automatically assign reviewers. Instead, it should post a comment tagging the team's lead or the relevant code owners and request a manual review of the risk assessment. The comment should include the model's rationale and the suggested reviewer list. This human-in-the-loop step prevents high-risk changes from being auto-assigned to reviewers who may not have the bandwidth or context for an urgent review. Logging and Observability: Log the full prompt, model response, validation results, and final action taken (assignment, comment, or escalation) to your observability platform. Include the PR number, repository, and a timestamp. This trace is essential for debugging incorrect risk scores, missed reviewer assignments, and for auditing the system's behavior over time. Model Choice: Use a model with strong structured output capabilities and a context window large enough for your typical PR diffs. For cost-sensitive pipelines, consider routing low-complexity PRs (fewer than 5 files changed) to a smaller, faster model and reserving a more capable model for complex or high-risk changes.

IMPLEMENTATION TABLE

Expected Output Contract

Defines the fields, types, and validation rules for the structured JSON output produced by the PR Risk Assessment and Reviewer Recommendation Prompt. Use this contract to parse and validate the model's response before routing it to downstream systems.

Field or ElementType or FormatRequiredValidation Rule

risk_score

integer (0-100)

Must be an integer between 0 and 100. A higher score indicates greater risk. Validate range and type.

risk_level

string (enum)

Must be one of: 'low', 'medium', 'high', 'critical'. Validate against the allowed enum list.

risk_rationale

string

Must be a non-empty string. Should contain at least one specific reference to a changed file or code pattern. Check length > 20 characters.

recommended_reviewers

array of strings

Each string must be a valid GitHub handle or email address. Validate array is not empty. Cross-reference against CODEOWNERS file if available.

reviewer_rationale

string

Must be a non-empty string explaining why each reviewer was chosen. Validate it contains at least one reference to code ownership or historical expertise.

affected_modules

array of strings

Each string must be a non-empty path or module name. Validate array is not empty. Check that each module appears in the PR diff.

breaking_change_detected

boolean

Must be true or false. If true, the risk_level should be 'high' or 'critical'. Validate consistency between this flag and risk_level.

confidence

number (0.0-1.0)

If present, must be a float between 0.0 and 1.0. Represents the model's confidence in its assessment. Validate range and type.

PRACTICAL GUARDRAILS

Common Failure Modes

What breaks first when using the PR Risk Assessment and Reviewer Recommendation Prompt, and how to guard against it in production.

01

Reviewer Recommendations Ignore CODEOWNERS

What to watch: The model recommends reviewers based on recent git blame or conversational memory, ignoring the authoritative CODEOWNERS file. This causes missing required reviews and CI failures. Guardrail: Always inject the CODEOWNERS file into [CONTEXT] and add a hard constraint: 'Recommended reviewers MUST include required owners from CODEOWNERS for every changed file path.' Validate output against CODEOWNERS before posting.

02

Risk Score Inflation on Boilerplate Changes

What to watch: The model assigns a high risk score to large diffs that are purely mechanical (e.g., renames, linting, dependency bumps) because it confuses diff size with change complexity. Guardrail: Add a pre-processing step that classifies the change type (refactor, lint, dependency, logic). Pass this classification into the prompt as [CHANGE_TYPE] and instruct the model to down-weight size-based risk for mechanical changes.

03

Hallucinated Reviewer Names

What to watch: The model generates plausible-sounding reviewer usernames that don't exist in the organization, especially when the diff touches files with no clear owner. Guardrail: Provide a validated [REVIEWER_POOL] list of active team members with their expertise tags. Add a strict output constraint: 'Only recommend reviewers from the provided [REVIEWER_POOL]. If no suitable reviewer exists, recommend the default fallback team.'

04

Stale Expertise Mapping

What to watch: The model relies on a static expertise map that is months out of date, recommending reviewers who have left the team or changed focus areas. Guardrail: Generate the [REVIEWER_POOL] dynamically at runtime from recent commit history (last 90 days) and team membership APIs. Add a freshness timestamp to the prompt context and instruct the model to flag any recommendation based on contributors inactive for more than 90 days.

05

Risk Rationale Is Vague and Unactionable

What to watch: The model outputs generic risk justifications like 'This change is complex' without citing specific files, functions, or patterns that drive the risk score. Reviewers ignore the assessment. Guardrail: Require a structured [OUTPUT_SCHEMA] where each risk factor must cite at least one specific file path and one concrete reason (e.g., 'modifies auth middleware in src/auth/session.ts'). Add an eval check that rejects rationale without file-level evidence.

06

Context Window Truncation on Large Diffs

What to watch: The PR diff exceeds the model's context window, causing silent truncation. The model assesses risk based on only the first portion of the diff, missing critical changes at the end. Guardrail: Implement a pre-flight diff size check. If the diff exceeds a safe token budget (e.g., 60% of the model's context limit), split the assessment by directory or file group, run parallel assessments, and merge the results with a summary pass. Log a warning when truncation is possible.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to evaluate the quality of the PR Risk Assessment and Reviewer Recommendation output before integrating it into a production code review pipeline. Each criterion targets a specific failure mode observed in automated risk scoring and reviewer assignment.

CriterionPass StandardFailure SignalTest Method

Risk Score Calibration

Risk score (low/medium/high) aligns with at least 3 of: changed file count, lines changed, file criticality, test presence, or config changes

High-risk score assigned to a typo fix; low-risk score assigned to an auth module change without tests

Run against 10 labeled PRs with known risk levels; measure F1 score for high-risk classification

Reviewer Recommendation Relevance

Every recommended reviewer has authored or reviewed the changed files in the last 90 days per git history

Recommending a frontend specialist for a database migration; recommending a departed team member

Cross-reference [RECOMMENDED_REVIEWERS] against git log --format='%an' -- [CHANGED_FILES] for the last 90 days

CODEOWNERS Compliance

All files covered by CODEOWNERS have at least one corresponding owner in the reviewer list

A protected directory change bypasses required CODEOWNERS review

Parse [CODEOWNERS] file; verify every changed file pattern has a matching reviewer in the output

Rationale Grounding

Every risk factor in the rationale cites a specific file path, diff hunk, or metric from [DIFF]

Rationale states 'complex logic changes' without pointing to any specific file or function

Check that each rationale sentence contains at least one file path or line reference present in [DIFF]

Change Complexity Detection

Detects multi-file refactors, API signature changes, and config + code changes as complexity signals

Treats a 50-file find-and-replace as high complexity; misses a single-file API breaking change

Verify complexity flags against a checklist: signature changes, config changes, multi-module edits, missing tests

Reviewer Load Awareness

Does not recommend the same reviewer for more than 3 open PRs unless no alternatives exist

Assigning 5 PRs to the same reviewer when other qualified reviewers are available

Query open PR count per reviewer; flag output if any [RECOMMENDED_REVIEWER] exceeds threshold without justification

Output Schema Validity

Output matches [OUTPUT_SCHEMA] exactly: all required fields present, enums match allowed values, arrays are non-empty where required

Missing 'rationale' field; risk_score value is 'critical' instead of allowed 'high'

Validate output against JSON Schema; reject on missing required fields, wrong types, or invalid enum values

Abstention on Unassessable PRs

Returns a low-confidence flag or empty reviewer list when [DIFF] is empty, binary, or entirely generated code

Confidently assigns high risk and specific reviewers to a lockfile update or generated code change

Test with empty diff, binary file changes, and auto-generated code; expect confidence_score < 0.5 or explicit abstention flag

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Use the base prompt with a simple diff input and a static CODEOWNERS map. Skip historical expertise lookups. Accept a single risk score and a flat reviewer list.

code
Analyze this PR diff and output a risk level (low/medium/high) with a 2-sentence rationale and 1-3 suggested reviewers from [CODEOWNERS_MAP].

Watch for

  • Reviewer suggestions that don't match CODEOWNERS at all
  • Risk scores that default to "medium" on every PR
  • No explanation of why a reviewer was chosen
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.