From AI Findings to SARIF: Keep Alerts Stable Across Runs
An AI code review can identify a plausible issue today and describe it differently tomorrow. If every wording change creates a new alert, a team gets duplicate noise instead of a useful history. Exporting these findings
An AI code review can identify a plausible issue today and describe it differently tomorrow. If every wording change creates a new alert, a team gets duplicate noise instead of a useful history. Exporting these findings to SARIF requires a definition of which observations represent the same issue across scans, plus enough evidence for a human to verify each one.
GitHub Code Scanning uses stable rule IDs and consistent file paths to help match alerts across analyses. Its current guidance describes partial fingerprints as a way to identify logically identical results, and warns that inconsistent paths can create duplicates. An arbitrary hash is not automatically a correct fingerprint. See GitHubโs SARIF support guidance and the OASIS SARIF 2.1.0 specification.
Start with a finding contract
Before creating SARIF, require each proposed finding to carry structured fields: a stable rule identifier owned by your analyzer, a repository-relative path, a start line, a concise message, and evidence that points to the relevant code. Treat model text as untrusted input. Validate field types, reject out-of-range line numbers, and ensure file paths resolve inside the checked-out repository. A model must not be allowed to invent a file location that escapes the worktree; clamping a bad line to a valid one would manufacture evidence.
The ruleId should describe the check, such as AI.SECRET_IN_SOURCE, and remain unchanged if you adjust the wording of its title. Do not derive it from the model's title or from a transient model version. The path should be normalized to repository-relative form with consistent separators. A local absolute path such as /tmp/job-481/src/auth.js will differ on every CI runner and can defeat matching.
A small worked result
Assume a validator has accepted one finding in src/config.js on line 18. The following is a minimal SARIF-shaped excerpt to show the identity-bearing fields; a complete SARIF document also needs its version, schema reference, run, and tool metadata. This fragment is illustrative and not a complete upload artifact:
{
"ruleId": "AI.SECRET_IN_SOURCE",
"level": "warning",
"message": { "text": "A credential-like literal appears in source." },
"locations": [{
"physicalLocation": {
"artifactLocation": { "uri": "src/config.js" },
"region": { "startLine": 18 }
}
}]
}
The excerpt omits partialFingerprints. GitHubโs upload action can attempt to populate missing fingerprint data from available source files. Direct API uploads without that data may produce duplicates, so they need a strategy appropriate to the analyzer and ingestion path. Follow SARIF property semantics and version the fingerprint process. A fingerprint based only on a line number can change when unrelated lines are inserted. One based only on a message can drift as model wording changes or collide for separate findings. Check behavior through the same upload route your workflow uses.
Put a human evidence gate in front
Model output is a hypothesis. Before serialization, check that the referenced line exists, the cited snippet is actually present in the file, and the evidence supports the stated rule. Reject findings with impossible locations. Keep confidence language out of SARIF severity unless the mapping is explicit and reviewed; generated numeric scores should not become security severity by arithmetic alone.
For an exercise, run your analyzer twice on the same tiny repository fixture. Compare ruleId, normalized artifactLocation.uri, and your computed identity key for every finding. Then change only the message text and confirm the key stays stable. Insert a line above the location and observe whether your chosen strategy keeps or changes identity as intended. Finally, rename the file and decide whether that should close the prior alert and open a new one in your workflow. Record the expected behavior before connecting code scanning.
Keep nearby findings distinct
Stable identity reduces duplicate alerts, but overly broad fingerprints can merge distinct issues. A fingerprint that includes too much context may split one issue after an innocent refactor. There is no universal hash recipe that resolves those competing goals for every analyzer. Use a versioned strategy and inspect its behavior against representative diffs.
Keep raw model responses and normalized findings separate. Raw responses may help debug the analyzer under a controlled retention policy. The alert should carry enough validated evidence for a reviewer to locate the code, understand the suspected defect, and decide whether to act. Successful ingestion leaves that code review work ahead of you.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.