$ fssg build --deterministic --validate |

How to Add a FACET Contract Gate to CI

FACET

A FACET contract should fail a pull request before it can fail an AI workflow.

That sounds obvious, but many teams still treat prompts and tool schemas as runtime configuration. They review the text, merge it, and discover structural mistakes only after a model call. By then the defect is mixed with provider behavior, retrieved context, tool state, and retries. A compiler error has become an incident investigation.

I prefer a smaller boundary: compile the contract in CI, run its deterministic tests, and keep the compiler views as review artifacts. The model does not belong in this gate. The gate answers a narrower question: is this change a valid FACET program, and did it preserve the structural behavior we can prove before inference?

The minimum useful gate

The reference compiler exposes exactly the primitives needed for this job:

facet-fct build --input contracts/support-agent.facet
facet-fct test --input contracts/support-agent.facet --output summary --pure

build parses, resolves, and validates the document. test executes its @test blocks; --pure keeps the run inside the deterministic boundary. A non-zero exit stops the pipeline.

This is intentionally less ambitious than an LLM evaluation. It catches language, type, import, policy, dependency, layout, and contract-local test failures without paying for inference or pretending that a stochastic judge is a compiler.

FACET's broader language model is explained in FACET vs YAML vs JSON. The practical difference in CI is simple: a .facet file is not opaque configuration. It has compilation semantics.

A GitHub Actions job

The smallest useful workflow can live in .github/workflows/facet.yml:

name: facet-contracts

on:
  pull_request:
    paths:
      - "contracts/**"
      - ".github/workflows/facet.yml"
  push:
    branches: [main]
    paths:
      - "contracts/**"

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@stable

      - name: Install FACET compiler
        run: |
          cargo install \
            --git https://github.com/rokoss21/facet-compiler \
            --rev 9b61d0659e18cc2b9df3fb8e08d069a81a7cb6c3 \
            --bin facet-fct
          facet-fct --version

      - name: Compile and test contracts
        shell: bash
        run: |
          set -euo pipefail
          for contract in contracts/*.facet; do
            facet-fct build --input "$contract"
            facet-fct test --input "$contract" --output summary --pure
          done

The commit pin matters. Installing from a moving branch makes compiler behavior an undeclared input. Upgrade the revision in a separate pull request, inspect the resulting changes, and then accept the new compiler identity deliberately.

For a real repository I would also pin third-party Actions to commit SHAs. I have left version tags above to keep the example readable; that is a supply-chain limitation of the snippet, not a FACET limitation.

Preserve the evidence reviewers need

A green check says that the commands exited successfully. It does not show what changed inside the contract. FACET can export four pre-inference views:

mkdir -p artifacts/facet
facet-fct inspect \
  --input contracts/support-agent.facet \
  --ast artifacts/facet/ast.json \
  --dag artifacts/facet/dag.json \
  --layout artifacts/facet/layout.json \
  --policy artifacts/facet/policy.json

Upload that directory as a CI artifact even when the job fails. The AST exposes resolved structure; the DAG exposes evaluation dependencies; layout exposes context allocation; policy exposes effective authorization structure. I described these views in detail in Debug AI Contracts Before They Run.

The useful review question is not “did JSON change?” It is “did the intended semantic surface change?” A policy diff deserves different scrutiny from a layout diff. A new DAG edge can alter evaluation order without changing the prose a reviewer notices first.

Add one negative test before the first positive test

A contract gate becomes valuable when it proves refusal, not only acceptance. For a tool with a consequential effect, add an @test case for the denied or invalid path before testing the happy path. Keep tool mocks at the effect boundary and assert deterministic structure first.

That does not prove model quality. It proves that malformed inputs, forbidden operations, or violated contract conditions remain failures inside the compiled boundary. How FACET Turns AI Tests into Executable Contracts explains why these tests are different from an evaluation dataset.

A practical merge rule is:

  1. every changed .facet file compiles;
  2. every contract-local test passes in Pure Mode;
  3. inspection artifacts are retained for review;
  4. generated host boundaries are regenerated when @interface changes;
  5. model evaluations run separately, only where semantic quality actually needs inference.

The fourth rule closes a common gap. If the AI-facing interface changes while the host SDK remains stale, both files may look valid independently. FACET code generation turns that drift into an ordinary generated-code diff.

What this gate does not prove

It does not prove that a model will answer correctly. It does not benchmark providers, guarantee external side effects, validate credentials, or make GitHub Actions hermetic. build covers parse/resolve/validation; a full run has a different purpose. Runtime authorization and provider execution still belong to the host.

This boundary is useful precisely because it is narrow. CI should reject every failure that does not require a model before spending model uncertainty on the failures that do.

Once contracts compile like code, changing AI behavior stops being an invisible configuration edit. It becomes a reviewable program change with a deterministic red line: invalid structure does not merge.

Sources

FACET AI CLI Terminal
facet@ai:~$