Skip to main content
Save scan and eval results as build artifacts to prove validation before deployment.
API keys required. Add your LLM provider API key (Gemini, OpenAI, or Anthropic) to your CI system’s secrets/environment variables. Never commit API keys to your repository.
Install OpenGrep in your pipeline. switch-trust scan uses OpenGrep for pattern analysis, and pip install switch-trust-cli doesn’t include it. Without it, the scan writes its results file and then exits 26, naming the missing tool, so the build fails. Each example below installs it and puts it on PATH.
Add switch-trust-cli to your GitHub Actions workflow:
GitHub Actions documentation →

Output formats

Switch Trust CLI writes results as JSON or as SARIF (Static Analysis Results Interchange Format), an open standard for reporting analysis findings. Tools that read SARIF ingest results from any SARIF-producing tool without a custom parser, so your findings land alongside the rest of your security results instead of in a file nobody opens. Switch Trust CLI writes SARIF 2.1.0.

Set the format

switch-trust scan and switch-trust eval run write JSON unless you ask for something else. Pass --format sarif (short form -f) to write SARIF instead. The output filename follows the format you choose:

What SARIF output contains

Findings map to file locations with line numbers, and severity maps to SARIF levels: critical and high findings become error, medium becomes warning, and everything else becomes note.This is the output GitHub code scanning is built to read.Upload to GitHub code scanning:
Findings then appear in the Security tab of your repository and as annotations on the pull request, so reviewers see them without downloading an artifact.

Exit codes

switch-trust scan and switch-trust eval run return the same exit codes, so a pipeline can tell a clean run from one that needs attention. The codes come in ranges a script can branch on: 20–39 need a fix before you rerun, and 60–79 are temporary, so a retry may succeed. For example:
Upgrading from 1.7: these runs used to exit 0, and now fail:
  • A scanner tool, such as OpenGrep, is missing: 26
  • A configured scanner model has no API key, or its key is rejected mid-scan: 20, or another configuration or retry code
  • An evaluation run scored nothing, including when every evaluation errored, or stopped before every evaluation ran: 6
Where a scan ran, it still writes its results first. A path that doesn’t exist now exits 22 instead of 1.

Fail the build on findings or scores

A completed run exits 0 unless you set a gate:
  • switch-trust scan --fail-on <severity>: Exits 5 if any finding is at or above critical, high, medium, low, or info, after triage. A finding whose severity can’t be read also trips it.
  • switch-trust eval run --fail-under <score>: Exits 5 if any evaluation scores below the value, from 0 to 1.
For example:
Both flags are off by default, and an invalid value exits 2 before anything runs. In CI, the CLI prints a warning when no gate is set. The CLI writes the results file before it checks the gate, so you can still save it as an artifact when the build fails. A missing scanner tool exits 26 even if findings would have tripped --fail-on.

Other CI systems

The core pattern works anywhere:
1

Provide Python 3.11 to 3.13

Switch Trust CLI requires Python 3.11 to 3.13 on a Linux or macOS runner. Use a prebuilt image where you can, such as python:3.11.
2

Install Switch Trust CLI

3

Install OpenGrep and put it on PATH

Add $HOME/.opengrep/cli/latest to PATH. This is the part that differs most between systems, because most of them run each step in a fresh shell: GitHub Actions writes the path to $GITHUB_PATH, CircleCI appends an export to $BASH_ENV, and GitLab CI runs the whole job in one shell, so a plain export carries. Find the equivalent on your system for persisting environment changes between steps.
4

Set your LLM API key

Store the key as a secret and expose it to the job as an environment variable: GEMINI_API_KEY, OPENAI_API_KEY, or ANTHROPIC_API_KEY.
5

Run the scan

Add --format sarif to write SARIF instead. See Output formats.
6

Save the results as a build artifact

Use your CI system’s artifact mechanism so the file outlives the job and reviewers can reach it from the pull request.