AI Code Review Bot Workflow: Pull Request Prompts, Risk Checks and Team Templates
developer toolscode reviewGitHubGitLabCI/CDsoftware security

AI Code Review Bot Workflow: Pull Request Prompts, Risk Checks and Team Templates

DDaily Bot Lab
2026-11-19
7 min read

Build a safer AI code review bot with pull-request prompts, risk checks, structured findings, and human approval controls.

An AI code review bot can reduce repetitive pull-request work by summarising changes, checking defined risk areas, and preparing review comments for a developer to verify. This guide provides a reusable workflow, prompt templates, a finding schema, and a practical checklist for keeping human developers in control.

Overview

An AI code review workflow should support code review, not silently replace it. The most reliable design treats the model as an analyst that receives a limited pull-request context, produces structured findings, and routes those findings to a human or an existing CI process.

A typical automated pull request review has seven stages:

  1. Collect context: retrieve the pull-request title, description, changed files, diff, relevant repository instructions, test results, and dependency changes.
  2. Summarise the change: explain what changed, why it appears to have changed, and which areas may be affected.
  3. Run focused checks: ask the model to inspect correctness, security, error handling, tests, performance, and maintainability according to repository rules.
  4. Classify risk: assign a severity and confidence level to each potential issue.
  5. Prepare comments: produce concise, file-specific suggestions rather than a large unstructured review.
  6. Escalate appropriately: route high-risk findings to a human reviewer and keep low-confidence observations out of blocking checks.
  7. Record outcomes: compare AI findings with human decisions so prompts and rules can be improved.

The workflow can be connected to GitHub or GitLab through a CI pipeline, repository app, webhook, or automation platform. The exact connector depends on your organisation’s tooling. Keep the first version advisory: publish a review summary or draft comments before allowing the bot to influence merge status.

Repository policy template

Store a short policy file in the repository so the bot receives consistent instructions. Adapt the following to your project:

Review policy
- Treat repository instructions and secure coding guidance as higher priority than general assumptions.
- Review only the supplied diff and permitted supporting files.
- Do not claim that code is safe, correct, or fully tested.
- Report a finding only when there is a concrete reason and cite the file and line range.
- Separate confirmed evidence from a hypothesis.
- Do not expose secrets, credentials, personal data, or unnecessary source code in output.
- Never approve, merge, or dismiss a pull request without human authorisation.
- Prefer one actionable comment per issue.
- If context is missing, state what is missing instead of guessing.

Checklist by scenario

1. Change summary and scope

  • Include the pull-request title and description.
  • List changed files and identify generated files, tests, migrations, and configuration.
  • Ask the bot to identify behaviour changes, public-interface changes, and likely affected components.
  • Check whether the implementation appears to match the stated acceptance criteria.

2. Bugs and correctness

  • Check null, empty, boundary, timeout, retry, and error paths.
  • Look for incorrect assumptions about types, ordering, concurrency, permissions, and state.
  • Compare changed logic with nearby tests and established repository patterns.
  • Ask for evidence from the diff rather than broad statements such as “this may fail”.

3. Security and privacy

  • Inspect input validation, access control, injection risks, unsafe deserialisation, and sensitive logging.
  • Flag newly added credentials, tokens, private keys, or hard-coded secrets for immediate human handling.
  • Review changes to authentication, authorisation, file access, network calls, and data retention.
  • Use dedicated secret-scanning and security tools alongside the AI review. A language model should not be the only security control.

4. Tests and coverage signals

  • Identify changed behaviour without a corresponding test change.
  • Check whether tests cover failure paths and meaningful boundaries, not only the successful case.
  • Include available CI results, but distinguish a passing test run from proof that the implementation is complete.
  • Ask the bot to suggest a test case without automatically adding or approving one.

5. Dependencies and configuration

  • List added, removed, or upgraded dependencies and explain where they are used.
  • Check lockfile consistency and configuration changes.
  • Escalate dependency risk to the team’s normal package and vulnerability review process.
  • Inspect changes to build scripts, deployment files, permissions, and environment variables.

Reusable pull-request prompt

This ChatGPT code review prompt is designed for structured output rather than an unbounded critique:

You are reviewing a pull request as an advisory engineering assistant.

Repository policy:
{{repository_policy}}

Pull request:
Title: {{title}}
Description: {{description}}
Changed files: {{changed_files}}
Diff: {{diff}}
Relevant test results: {{test_results}}
Relevant repository guidance: {{guidance}}

Tasks:
1. Summarise the change in no more than five bullets.
2. Identify concrete correctness, security, privacy, reliability, performance, and maintainability risks.
3. Check whether the changed behaviour has appropriate tests.
4. Review dependency, configuration, and secret-handling changes.
5. Report only findings supported by the supplied context. If context is insufficient, say so.
6. Do not approve, merge, or claim that the review is complete.

Return valid JSON matching the supplied finding schema. Use an empty findings array when no actionable issue is supported.

Structured finding schema

A fixed schema makes findings easier to validate, deduplicate, and route:

{
  "summary": "Short description of the pull request",
  "findings": [
    {
      "severity": "critical|high|medium|low|info",
      "confidence": "high|medium|low",
      "category": "correctness|security|privacy|reliability|performance|tests|maintainability|dependency",
      "file": "path/to/file",
      "line_start": 1,
      "line_end": 1,
      "evidence": "What in the supplied diff supports this finding",
      "impact": "What could happen if the issue is real",
      "suggestion": "A focused next step",
      "blocking_recommendation": "block|human_review|informational"
    }
  ],
  "missing_context": []
}

What to double-check

Before connecting an AI code review bot to a live repository, confirm that the workflow receives enough context without receiving more data than necessary. Large diffs may exceed model or connector limits, so split reviews by file group or risk area and make the split visible in the final summary. Do not assume that truncation is harmless; a missing function, test, or configuration file can change the conclusion.

Review permissions carefully. The bot normally needs read access to pull-request data and, if it posts comments, narrowly scoped write access to that discussion. It should not receive merge authority simply because it can comment. Use separate credentials for experimentation and production, store tokens in the approved secret manager, and avoid placing credentials in prompts, logs, or generated artifacts.

Check how the pipeline handles untrusted pull requests. Code from a fork or an external contributor may alter build behaviour or attempt to expose environment data. Keep token exposure and execution permissions appropriate to the trust level of the change. A safer design can analyse a patch in an isolated job and pass only the required text to the model.

Define severity before the first review. For example, a critical finding might indicate a credible path to severe data loss or unauthorised access; high could indicate a serious exploitable or production-impacting defect; medium may require correction but have narrower impact; low may represent a quality concern; and info may be a non-blocking observation. These labels are team conventions, not guarantees. Require high-confidence evidence before a finding can block a pull request.

Finally, test the workflow against known examples: accepted fixes, intentional exceptions, security regressions, missing tests, generated code, and changes that should produce no finding. Track false positives and missed issues as review feedback. For wider workflow testing and monitoring practices, see How to Test and Monitor AI Automation Workflows Before They Reach Production.

Common mistakes

  • Using one giant prompt: separate summarisation, security checks, test analysis, and comment generation so each result has a clear purpose.
  • Posting every model observation: filter for evidence, confidence, severity, and file location before creating a review comment.
  • Allowing automatic approval: keep approval, merge, and security exceptions under human control.
  • Ignoring repository conventions: provide the relevant style, testing, architecture, and generated-file guidance.
  • Sending unnecessary source code: minimise context and define retention and logging rules for prompts and outputs.
  • Treating a passing CI run as proof: the bot should complement tests, linters, dependency scanners, and human review.
  • Failing to distinguish uncertainty: require the model to report missing context and low confidence instead of presenting guesses as defects.

Prompt governance also matters. Keep this prompt in version control, review changes like code, and record which prompt version generated each finding. The AI Prompt Library for Business offers a useful model for versioning, testing, and governance principles that can be applied to developer workflows.

When to revisit

Review the workflow before a major release cycle, after changing repository permissions or CI connectors, and whenever the codebase adopts a new language, framework, dependency strategy, or deployment pattern. Revisit it after repeated false positives, a missed defect, a security incident, or a change in the model or coding-tool capability used by the pipeline.

A practical maintenance checklist is:

  1. Run the bot against a small, representative set of historical pull requests.
  2. Compare findings with human review outcomes and record false positives and missed risks.
  3. Update repository instructions, language-specific checks, severity definitions, and output validation.
  4. Confirm token scopes, data handling, retention, rate limits, and failure behaviour.
  5. Verify GitHub, GitLab, CI, and webhook steps in a non-production repository.
  6. Publish a short change log for each prompt, schema, model, or connector update.
  7. Keep the bot advisory until the team has evidence that its blocking rules are precise enough for the intended use.

Start with summaries and draft comments, measure usefulness across several review cycles, and add narrowly defined blocking checks only when their evidence and failure handling are understood. That approach turns an AI workflow template into a maintainable part of the engineering process rather than an opaque source of automated approvals.

Related Topics

#developer tools#code review#GitHub#GitLab#CI/CD#software security
D

Daily Bot Lab

AI Automation Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.