Skip to content

Guardrails / claude

Claude answers CI in a format a program can read ​

claude/cli-structured-output@v1

Every headless Claude CLI invocation the build ran asked for structured output.

Idclaude/cli-structured-output
Versionv1
Categoryclaude
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectscommands

Collectors ​

This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.

CollectorGathersInputs it is given
commandsEvery command the build executed, read from the session a running buildnote monitor records on the runner. This is what the job actually ran, not what a pipeline file says it would run.none

The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.

Configuration ​

json
{
  "guardrails": {
      "failOn": "error",
      "checks": [
          {
              "use": "claude/cli-structured-output@v1",
              "severity": "warning",
              "with": {
                  "formats": "json,stream-json"
              },
              "exemptions": []
          }
      ]
  }
}

Inputs ​

InputDescriptionDefaultEnvironment variable
formatsComma separated --output-format values that count as structured.json,stream-jsonGUARDRAIL_INPUT_FORMATS

How to fix ​

Add --output-format json to the invocation:

bash
claude -p --output-format json 'summarise what changed' > review.json

A headless run is read by a program, not a person, and reading prose means guessing: a step that greps the answer for FAIL passes the day the model words it differently. JSON returns the result, the cost and the session id as fields, so your job can branch on a value instead of on a phrasing.

More in claude ​

All 3 claude guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412