Skip to main content

pr-sentinel

CI Python License: MIT

AI-powered pull request review bot — as a GitHub Action and a CLI.

pr-sentinel reviews a pull request's diff with an AI model (via a Responses-compatible API) and deterministic static checks. It finds bugs, security issues and performance problems, posts a summary comment, adds line-level review comments, and can also run fully locally on a patch file.

pr-sentinel inline review comment on an experimental PR

Live review on an experimental PR: the AI reviewer caught an off-by-one bug on line 16 that the deterministic static checks could not see.

See it in action

The same review as a summary comment on the pull request — one high-severity finding, in a table:

pr-sentinel summary comment on an experimental PR

Both screenshots come from a real review of an experimental PR that intentionally contained two logic bugs; the reviewer caught one of them (the off-by-one above) and missed the other (an unbounded in-memory cache).

Why pr-sentinel?

Code review is the bottleneck of open-source maintenance. Maintainers drown in pull requests: every PR needs a careful read, but reviewers are few and their time is the scarcest resource in the ecosystem. Small projects wait days for a first review; large ones merge risky code because nobody had time to look closely.

pr-sentinel gives every pull request a first review within seconds — catching leaked secrets, dangerous calls and obvious bugs before a human spends time on the diff, so maintainers can focus their review on design and correctness instead of hunting for mistakes. It never merges, closes or changes code; it only comments, and the human always decides.

  • Two layers: fast static checks (leaked secrets, eval/exec, shell=True, pickle, huge files) plus an AI reviewer for the things regexes cannot see.
  • Zero-dependency core: the package uses only the Python standard library. No extra packages to install, audit or keep up to date.
  • Works anywhere: GitHub Action for automatic reviews, CLI for local use and CI systems other than GitHub Actions.
  • Safe by default: API keys come from environment variables only, never from config files or the command line. Secret values are never echoed in findings or logs.

Quick start — GitHub Action

# .github/workflows/pr-review.yml
name: PR review
on:
  pull_request:
    types: [opened, synchronize]

permissions:
  pull-requests: write
  contents: read

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: vadofespanili-cyber/pr-sentinel@v0.2.3
        with:
          api_key: ${{ secrets.PR_SENTINEL_API_KEY }}

PR_SENTINEL_API_KEY must be a key for a Responses-compatible model provider. The action posts one summary comment and line-level comments on the pull request. It never merges, closes or changes code — it only comments. The summary comment is updated in place when new commits are pushed (it carries a hidden marker), so re-pushes do not spam the PR with a new summary each time.

A full example is in examples/github-workflow.yml.

Quick start — CLI

pip install pr-sentinel-ai
export PR_SENTINEL_API_KEY="sk-..."
export GITHUB_TOKEN="ghp_..."

# Review a pull request and post the review on GitHub
pr-sentinel review --repo octocat/hello-world --pr 42

# Review a local patch file without touching GitHub
pr-sentinel review-diff --file changes.patch

# Preview without posting anything
pr-sentinel review --repo octocat/hello-world --pr 42 --dry-run

# Validate a config file
pr-sentinel check-config --config .pr-sentinel.yaml

The CLI exits 0 on success, 2 on config or usage errors and 3 on API errors. By default, findings never change the exit code: a PR with findings still exits 0, so the review never fails your build. Set fail_on_severity (or --fail-on-severity) to make findings at or above a severity fail the run with exit 1 — see CI gate and SARIF below.

Configuration

Optional file .pr-sentinel.yaml (or .pr-sentinel.yml) in the working directory, or --config PATH. An example is in examples/pr-sentinel.example.yaml.

model: gpt-5                 # model name sent to the Responses API
severity_threshold: medium   # lowest severity to report: critical|high|medium|low
fail_on_severity: high       # optional CI gate: exit 1 if a reported finding is this severe or worse (default: no gate; "none" also disables it)
ignore_paths:                # fnmatch globs, e.g. "vendor/**", "*.min.js"
  - "docs/**"
max_files: 50                # review at most this many files per PR
max_diff_chars: 100000       # truncate larger diffs with a warning
mode: inline                 # inline = summary + line comments, summary = summary only
max_inline_comments: 20      # cap on line-level comments
api_base_url: https://api.openai.com/v1
Setting Default
model gpt-5
severity_threshold medium
fail_on_severity None (no gate)
ignore_paths []
max_files 50
max_diff_chars 100000
mode inline
max_inline_comments 20
api_base_url https://api.openai.com/v1

Environment variables:

Variable Purpose
PR_SENTINEL_API_KEY API key for the model provider (required for AI review; without it only static checks run)
GITHUB_TOKEN GitHub token with pull-request read/write access (required for review)

CI gate and SARIF output

Failing the build on severe findings

Set fail_on_severity in the config file, or pass --fail-on-severity to review / review-diff (the flag wins over the config file), or set the fail_on_severity Action input. Valid values: critical, high, medium, low; none (or leaving it unset) disables the gate. When the gate is on, the run exits 1 if any reported finding — after severity_threshold and ignore_paths filtering — meets or exceeds the threshold; otherwise it exits 0. The review is always posted and --json-out / --sarif-out are always written before the gate exits 1, so CI still has the full report.

Note the interaction with severity_threshold: the gate only sees findings that were reported, so with the default threshold medium a fail_on_severity: low gate can never fire on low findings — lower severity_threshold too if you want low findings to fail the build.

SARIF output

--sarif-out PATH (on both review and review-diff, or the sarif_out Action input) writes the findings as SARIF 2.1.0, so they show up in GitHub code scanning. Upload it in a later step:

      - uses: vadofespanili-cyber/pr-sentinel@v0.2.3
        with:
          api_key: ${{ secrets.PR_SENTINEL_API_KEY }}
          sarif_out: pr-sentinel.sarif
      - uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: pr-sentinel.sarif

The upload step needs the security-events: write permission. The SARIF file is written relative to the workspace, so the upload step can read it. Rule ids are the finding's stable rule slug (for example leaked-openai-key, or ai-review for AI findings); severities map to SARIF levels error (critical/high), warning (medium) and note (low). Finding messages never contain raw secret values.

The summary comment

The summary is posted as a single issue comment carrying a hidden <!-- pr-sentinel:summary --> marker. When new commits are pushed, pr-sentinel finds that comment and updates it in place instead of posting another one. In inline mode the line comments are posted as a review only when there is at least one inline comment to post, with a brief body pointing at the summary comment. A review with no findings updates the summary comment to "No findings" instead of leaving a stale findings table behind. When the Action runs, the summary also shows the reviewed commit (Reviewed commit: <short-sha>) at the bottom, so readers can see at a glance which commit the review covers.

Example output

Reviewing the sample patch in examples/sample-pr.diff produces this summary (the full JSON is in examples/sample-findings.json):

# pr-sentinel review

Found 4 findings: 1 critical, 1 high, 1 medium, 1 low.

| Severity | File | Line | Message |
| --- | --- | --- | --- |
| critical | app.py | 3 | Possible OpenAI API key in added code. |
| high | app.py | 4 | Use of eval() on added code. |
| medium | app.py | 6 | Nested loops run 1,000,000 iterations to build a list. |
| low | app.py | 6 | Magic number 1000 is used without explanation. |

> **Note:** These findings are AI-generated suggestions. Please verify them before acting on them.

---
Reviewed by pr-sentinel

Each finding also becomes a line-level comment at the exact diff position, for example **critical · security** — Possible OpenAI API key in added code. with a suggested fix.

How it works

  1. Fetch the diff — from the GitHub API (review) or a local patch file (review-diff).
  2. Parse — the unified diff is parsed into files, hunks and numbered lines; each added line is mapped to its GitHub diff position so inline comments land on the right line.
  3. Static checks — deterministic, no-AI checks over added lines only: leaked secrets, dangerous calls, oversized files.
  4. AI review — the diff is split into chunks that fit the model's context and each chunk is reviewed through the Responses API. The model must return a JSON array of findings; anything unparseable is rejected.
  5. Filter and report — findings below the severity threshold or in ignored paths are dropped, then a Markdown summary and inline comments are posted (or printed in --dry-run / review-diff mode).

See docs/architecture.md for the module map and design decisions.

Limitations (honest)

  • Findings are suggestions, not verdicts. The AI reviewer can miss real bugs and can flag code that is fine. Always verify before acting.
  • No code is executed. pr-sentinel reads diffs only; it cannot run tests, reproduce a bug or prove a finding.
  • Function-level scope. The reviewer sees one diff chunk at a time, so it cannot reliably reason about cross-file architecture or whole-repo invariants.
  • Static checks are single-line regexes. Multi-line patterns (for example yaml.load( split across lines) are not detected, and the generic credential pattern can fire on harmless test values. A full AST-based analysis was deliberately not added: the reviewer only sees the diff, not full file contents, so AST on partial content would still miss cases.
  • Model-dependent. Review quality depends on the model and on the diff fitting into context; very large PRs are limited at max_diff_chars: whole trailing files/hunks are dropped (never cut mid-hunk), with a warning.
  • Retries. Transient failures (HTTP 429/5xx, network errors) are retried up to 3 attempts with exponential backoff, honoring a Retry-After header; a persistent failure falls back to static checks only, with a warning.
  • English prompts. Review prompts and messages are in English in v0.1.0.

Releases

Versioned releases live on the Releases page. The current release is v0.2.3 — see the Changelog and the release notes for what it includes. v0.1.2 was driven by an independent external review (Google Gemini 4 Neon); the full review is in docs/reviews/gemini-2026-11-22.md.

Development

python -m venv .venv && .venv/bin/pip install -e ".[dev]"
.venv/bin/python -m pytest -q
.venv/bin/ruff check src tests
.venv/bin/ruff format --check src tests

Python 3.10+; the package itself has no runtime dependencies. See CONTRIBUTING.md.

Security

Report vulnerabilities as described in SECURITY.md. Never put real API keys or tokens in issues, pull requests or test files.

License

MIT — see LICENSE.

Metadata

Release files for pr-sentinel-ai 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pr-sentinel-ai 0.2.3
File Size Uploaded Provenance Actions
pr_sentinel_ai-0.2.3.tar.gz 35.6 kB With provenance Details for pr_sentinel_ai-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pr-sentinel-ai 0.2.3
File Interpreter ABI Platform Actions
pr_sentinel_ai-0.2.3-py3-none-any.whl Python 3 none any Details for pr_sentinel_ai-0.2.3-py3-none-any.whl

Total release size: 71.0 kB

Release files / pr_sentinel_ai-0.2.3.tar.gz

Download URL pr_sentinel_ai-0.2.3.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5a6203a896b1abc18efd7ba772289e6be5f7aae422038906288cde2ccf6798a8
BLAKE2b-256 checksum
How to use checksums
cddca3f74dbab93b4406a8d9f09576b94abcb99ab8bf877fdf86b8fd23d71bf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / pr_sentinel_ai-0.2.3-py3-none-any.whl

Download URL pr_sentinel_ai-0.2.3-py3-none-any.whl
Size 35.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ddf39a3e132c4df66ce494178242b5a21a9d95cf5ca5e650f109f051e47fbd23
BLAKE2b-256 checksum
How to use checksums
310ae06f9b349fc97ff3cfa4f87a563109ecb08b2432d76d10b3f3d15a7ba631
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for pr-sentinel-ai 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pr_sentinel_ai-0.2.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page