| name | pr-reviewer-python |
| description | Review Python pull requests for behavioral bugs, security risks, and regression risk using git diff and optional gh PR context. Use for backend/API Python PR reviews; avoid for non-Python repos or style-only lint passes. |
| license | MIT |
| compatibility | opencode; expects git CLI and repository access; optionally uses gh CLI for PR and issue context |
| metadata | {"audience":"python-engineers","language":"python","workflow":"github-pr-review"} |
What I do
- Review Python pull requests with a focus on behavior changes, not just line-by-line diff comments
- Gather missing context (callers, routers/views, services, schemas, models, settings) to detect:
- hidden bugs and regressions
- auth/security gaps
- async/concurrency issues (event loops, blocking calls, task lifecycle)
- ORM/query issues (N+1, transaction consistency, missing indexes/preloads)
- performance and memory risks
- typing/runtime mismatch risks
- Provide a structured, actionable review with concrete fixes and severity levels
When to use me
Use this when you want a rigorous PR review for Python applications (especially API/backends), and you can share:
- the committed diff against the correct base branch, and ideally
- PR context (title/body/comments) via
gh CLI.
Ask clarifying questions only when missing context blocks correctness/security conclusions.
When not to use me
- Non-Python repositories or PRs where Python is not the primary behavior surface
- Pure formatting/lint-only changes where no behavior changed
- Product/design requests that are not code-review tasks
How I work
0) Review workflow (git / gh CLI) — do this before reviewing
- Verify default remote branch is up to date
Ask the user to run:
- Get the diff (committed changes only)
Ask the user to share:
git diff origin/<default-branch>...HEAD
- If uncertain, use
origin/main...HEAD or origin/master...HEAD based on the repo
-
Ignore unstaged/uncommitted files
Only review committed changes shown by the diff above.
-
Extract PR information with gh CLI (optional, recommended)
Ask for one of:
gh pr view
gh pr view --comments
gh pr view --json number,title,body,comments
- Extract linked issue information (optional)
If referenced:
- Same repo:
gh issue view <NUMBER>
- With comments:
gh issue view <NUMBER> --comments
- JSON:
gh issue view <NUMBER> --json number,title,body,comments
If repository access is unavailable, explicitly list the exact files/commands needed and why.
1) Context-gathering playbook (MANDATORY)
Before writing conclusions, identify:
- touched modules (API routes/views/controllers, services/use-cases, serializers/schemas, models, settings/config, background jobs, middleware)
- call sites and data flow (who calls what, with what inputs, and error paths)
- framework wiring (URL/router registration, dependency injection, middleware/auth setup, startup/shutdown hooks, task scheduler wiring)
Then expand context as needed:
- Web/API changes:
- route declarations and handler wiring
- request parsing/validation and response schemas
- error mapping and status-code consistency
- Auth/security:
- auth middleware/dependencies/decorators
- permission checks on read and write paths
- secrets/config handling and trust boundaries
- Data/persistence:
- models, migrations, query builders, repositories/services
- transaction boundaries, locking, idempotency, retry behavior
- indexes and query selectivity for new access patterns
- Async/background work:
- blocking calls inside async handlers
- task cancellation/timeout/retry behavior
- queue worker semantics and duplicate processing risks
- Packaging/config:
- dependency changes, Python version constraints, env var defaults
- backward compatibility and rollout risk
If behavior cannot be confirmed due to missing context, state the assumption and request the specific file/function.
2) Review dimensions (Python focused)
- Code quality (readability, cohesion, low surprise behavior, explicit errors)
- Logic & correctness (edge cases, exception paths, state transitions, null/optional handling)
- Security (authz, injection, unsafe deserialization, path traversal, SSRF, secret leakage)
- Performance (query efficiency, N+1, algorithmic hotspots, I/O blocking in async code)
- Typing/reliability (
typing correctness, pydantic/dataclass/schema drift, runtime validation)
- Testing (unit/integration coverage for happy path, auth failures, error paths, regressions)
- Architecture (separation of routing, business logic, persistence, side effects)
- Documentation (behavior changes, migrations, config/env updates, new features documented in the project's docs system — e.g. Sphinx, MkDocs, Starlette/FastAPI auto-docs, or any SSG — if one exists)
3) Required output structure (MANDATORY)
I output the review as:
- Summary (what changed + ship/needs work/blocked)
- Critical Issues (blocking)
- Major Concerns
- Minor Suggestions
- Positive Highlights
- Questions (only if needed to unblock)
For each issue, include:
- file path
- line reference if available (or nearest function/class/endpoint)
- description
- why it matters (impact)
- suggested fix (concrete; snippets when helpful)
- severity: critical / major / minor
Rules:
- Do not invent line numbers
- If lines are unavailable, anchor to function/class/endpoint names
4) Python-specific review checklist
- API and validation:
- request/response schema compatibility preserved?
- input validation strict enough at trust boundaries?
- error responses stable and intentional?
- Data consistency:
- transaction scope correct for multi-write flows?
- race conditions around read-modify-write paths?
- migration is backward-compatible for rolling deploys?
- Async/concurrency:
- any blocking DB/HTTP/file calls inside
async def without offloading?
- proper timeout/cancellation handling?
- shared mutable state guarded?
- Security:
- auth checks present on every sensitive endpoint/action?
- unsafe dynamic eval/import/deserialization patterns?
- secrets/tokens avoided in logs and API responses?
- Reliability:
- retries idempotent and bounded?
- exception handling preserves observability and correct status codes?
- cache invalidation/update logic coherent with source of truth?
- Documentation:
- if new user-facing features or endpoints were added, are they reflected in the project's docs system (Sphinx, MkDocs, SSG, OpenAPI/auto-generated docs, README, etc.)?
- if a docs system is present but new features have no docs entry, flag it as a minor issue.
Tooling suggestions when relevant:
ruff check .
ruff format --check . (or project formatter)
mypy . (or pyright, based on project standard)
pytest -q
Tone rules
Be direct but kind. Prefer “Here’s a safer approach” over “This is wrong”.
If you suspect a bug but lack context, state the assumption and request the missing info.
Focus on impact over nitpicks.