NeuronLens
Browse the documentation
Guides

Gate a build on Integrity Lens

Scan the model on every push and fail the build when it is tampered or no longer the approved version.


One CI step starts a scan, waits for it, and fails the build when:

  • the verdict is tampered, or
  • the scanned commit is no longer the version you approved (against_approved is not matches_approved).

Before you start

  1. Approve a version of the model, in the app under Scanned models or with POST /v1/integrity/models/{id}/approve.
  2. Create an API key under Profile → API keys for your organization, and store it as the CI secret NEURONLENS_API_KEY.
  3. For a private repository, make sure an admin has connected a Hugging Face read token (Connect).

GitHub Actions

# .github/workflows/integrity.yml
name: Integrity Lens
on: [push]
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - name: Scan the model and fail on tampering
        env:
          KEY: ${{ secrets.NEURONLENS_API_KEY }}
          MODEL: hf://acme/kyc-assistant-v3
        run: |
          API=https://api.neuronlens.com/v1/integrity
          ID=$(curl -sf $API/scans -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
               -d "{\"model\": \"$MODEL\", \"compare\": \"approved\"}" | jq -r .scan_id)
          for i in $(seq 1 120); do
            R=$(curl -sf $API/scans/$ID -H "Authorization: Bearer $KEY")
            S=$(echo "$R" | jq -r .status)
            [ "$S" = done ] || [ "$S" = failed ] && break
            sleep 10
          done
          echo "$R" | jq '{status, verdict, against_approved, report_url}'
          [ "$(echo "$R" | jq -r .status)" = done ] || exit 1
          [ "$(echo "$R" | jq -r .verdict)" != tampered ] || exit 1
          [ "$(echo "$R" | jq -r .against_approved)" = matches_approved ] || exit 1

Change MODEL to your model. To check the exact commit you are shipping, pin it: hf://acme/kyc-assistant-v3@<sha>.

What you will see:

ModelResultBuild
the approved versionno_issue, matches_approvedpasses
a new commit, nothing foundno_issue, changedfails until someone reviews and approves it
a stripped modeltamperedfails
a scan that could not finish (for example needs_token)failedfails

The job log prints the report_url of the signed report.

GitLab CI and other systems

The step is plain curl and jq, so the same lines work anywhere. In GitLab CI, put them under script: in a job with an image that has both (for example alpine with apk add curl jq), and the key in a masked CI/CD variable.

To avoid polling, pass "webhook": "https://ci.example.com/hooks/neuronlens" and we call it when the scan finishes (see Webhooks).

Cost

Each started scan counts as one run against your daily allowance; polling does not.