site/docs/code-scanning/github-action.md
Automatically scan pull requests for LLM security vulnerabilities with promptfoo's code scanning GitHub action.
The scanner analyzes code changes for prompt injection, PII exposure, excessive agency, and other LLM-specific risks. After scanning, findings are posted with severity levels and suggested fixes as PR review comments.
The easiest way to get started is by installing the Promptfoo Scanner GitHub App:
.github/workflows/promptfoo-code-scan.ymlOnce merged, the scanner will automatically run on future pull requests, posting review comments for any security issues found.
:::info When using the GitHub App:
Most CLI options from promptfoo code-scans run can be used as action inputs:
| Input | Description | Default |
|---|---|---|
api-host | Promptfoo API host URL | https://api.promptfoo.dev |
min-severity | Minimum severity to report (low, medium, high, critical) | medium |
minimum-severity | Alias for min-severity | medium |
config-path | Path to .promptfoo-code-scan.yaml config file | Auto-detected |
guidance | Custom guidance to tailor the scan (see [CLI docs][1]) | None |
guidance-file | Path to file containing custom guidance (see [CLI docs][1]) | None |
enable-fork-prs | Enable scanning PRs from forked repositories | false |
If you made changes to your PR and want to run another scan, you can trigger a new scan by commenting on the PR with @promptfoo-scanner.
By default, code scanning is disabled for fork PRs. This is because any GitHub user can open a fork PR on public repositories.
To trigger a scan on a fork PR, a maintainer with write permissions on the repository can comment on the PR with @promptfoo-scanner.
To enable scanning of fork PRs by default, add enable-fork-prs: true to your workflow file (.github/workflows/promptfoo-code-scan.yml in the main branch):
- name: Run Promptfoo Code Scan
uses: promptfoo/code-scan-action@v1
with:
enable-fork-prs: true
Scan with custom severity threshold:
- name: Run Promptfoo Code Scan
uses: promptfoo/code-scan-action@v1
with:
min-severity: medium # Report medium, high and critical severity issues only (if omitted, all severity levels are reported)
Use custom guidance:
- name: Run Promptfoo Code Scan
uses: promptfoo/code-scan-action@v1
with:
guidance: |
Focus on the document ingestion flow.
Treat any potential PII exposure as critical severity.
Load custom guidance from a file:
- name: Run Promptfoo Code Scan
uses: promptfoo/code-scan-action@v1
with:
guidance-file: ./promptfoo-scan-guidance.md
Use config file:
- name: Run Promptfoo Code Scan
uses: promptfoo/code-scan-action@v1
with:
config-path: .promptfoo-code-scan.yaml
Create a .promptfoo-code-scan.yaml in your repository root. See the CLI documentation for all available options.
# Minimum severity level to report
minSeverity: medium
# Scan only PR diffs without filesystem exploration (default: false)
diffsOnly: false
# Custom guidance to tailor the scan
guidance: |
Focus on authentication and authorization vulnerabilities.
Treat any PII exposure as high severity.
You can also install the action manually without the GitHub App. When using manual installation:
github-actions[bot] instead of the official Promptfoo Scanner bot with the Promptfoo logoAdd this workflow to your repository at .github/workflows/promptfoo-code-scan.yml:
name: Promptfoo Code Scan
on:
pull_request:
types: [opened]
jobs:
security-scan:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run Promptfoo Code Scan
uses: promptfoo/code-scan-action@v1
env:
PROMPTFOO_API_KEY: ${{ secrets.PROMPTFOO_API_KEY }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
min-severity: medium # or any other severity threshold: low, medium, high, critical
# ... other configuration options...