Prisma
GuidesHow-to Guides

Policy Compliance in CI/CD

Gate merges on AI quality — validate a golden dataset on every pull request and block compliance regressions before they ship.

Treat compliance like a test suite. Keep a small golden dataset of representative interactions in your repo, validate it on every pull request, and block the merge when the pass rate drops below your bar. A prompt tweak that quietly breaks identity verification fails the build instead of reaching production.

Before you start

  • A Prisma API key sent as X-API-Key: pq_prisma_sk_…, plus your workspace ID and project ID.
  • A golden dataset — 10–20 representative interactions with known-good outcomes, committed to your repo (e.g. tests/eval/golden_dataset.json). Each record needs a query and a response; add a reference (the ground-truth answer) so correctness has something to compare against.
  • A decision on what gates the PR — the built-in quality evaluators (covered here) or your own policy metric (see Gate on a policy metric).

Validate the golden set

The synchronous evaluation endpoint scores a batch of records and returns per-record results in one call — no polling — which is exactly what a blocking CI step needs. It runs the built-in correctness and hallucination evaluators.

import os, httpx

resp = httpx.post(
    f"{os.environ['PALQEE_PRISMA_BASE_URL']}/api/v1/evaluations/evaluate",
    headers={"X-API-Key": os.environ["PALQEE_PRISMA_API_KEY"]},
    json={
        "workspace_id": os.environ["PALQEE_PRISMA_WORKSPACE_ID"],
        "project_id": os.environ["PALQEE_PRISMA_PROJECT_ID"],
        "evaluators": [{"name": "correctness"}, {"name": "hallucination"}],
        "data": [
            {
                "query": "Why was I charged twice for my subscription this month?",
                "response": (
                    "That was a billing error. I've refunded the duplicate "
                    "$29.99 charge — it will appear in 3–5 business days."
                ),
                "reference": "Acknowledge the duplicate charge, confirm a refund, and give the 3–5 business day timeline.",
            },
            {
                "query": "What's your APY on a 12-month CD?",
                "response": "Our 12-month CD is 4.75% APY, with a 90-day interest penalty for early withdrawal.",
                "reference": "State the current 12-month CD APY and disclose the early-withdrawal penalty.",
            },
        ],
    },
    timeout=180.0,
)
resp.raise_for_status()
results = resp.json()["results"]

The request body carries workspace_id, project_id, the evaluators to run (by name), and the data to score (1–100 records). Each data item is {query, response, reference?}. You don't pass an LLM config — the deployment uses its configured model.

The response is a flat results array, one item per record. Each item's evaluations maps the evaluator name to the label it returned:

results[0]["evaluations"]
# {"correctness": "correct", "hallucination": "factual"}
EvaluatorLabels
correctnesscorrect · incorrect · ambiguous
hallucinationfactual · hallucinated · ambiguous

There's no server-side summary — you compute the pass rate from the per-record labels, which keeps the threshold logic in your repo where you can version it.

Turn results into a gate

Count the clean records, compare against your threshold, and exit non-zero to fail the build. Save this as tests/eval/gate.py:

"""Policy compliance gate for CI/CD."""

import json, os, sys, httpx

PASS_THRESHOLD = 0.90  # at least 90% of the golden set must be clean


def evaluate(records: list[dict]) -> list[dict]:
    resp = httpx.post(
        f"{os.environ['PALQEE_PRISMA_BASE_URL']}/api/v1/evaluations/evaluate",
        headers={"X-API-Key": os.environ["PALQEE_PRISMA_API_KEY"]},
        json={
            "workspace_id": os.environ["PALQEE_PRISMA_WORKSPACE_ID"],
            "project_id": os.environ["PALQEE_PRISMA_PROJECT_ID"],
            "evaluators": [{"name": "correctness"}, {"name": "hallucination"}],
            "data": records,
        },
        timeout=180.0,
    )
    resp.raise_for_status()
    return resp.json()["results"]


def is_clean(result: dict) -> bool:
    e = result["evaluations"]
    return e.get("correctness") == "correct" and e.get("hallucination") == "factual"


def main() -> int:
    with open(os.environ.get("GOLDEN_DATASET_PATH", "tests/eval/golden_dataset.json")) as f:
        records = json.load(f)

    results = evaluate(records)
    clean = [r for r in results if is_clean(r)]
    rate = len(clean) / len(results) if results else 0.0

    for r in results:
        flag = "PASS" if is_clean(r) else "FAIL"
        e = r["evaluations"]
        print(f"  [{flag}] {r['query'][:55]:55}  correctness={e.get('correctness')} hallucination={e.get('hallucination')}")

    print(f"\n{len(clean)}/{len(results)} clean — {rate:.0%} (threshold {PASS_THRESHOLD:.0%})")
    return 0 if rate >= PASS_THRESHOLD else 1


if __name__ == "__main__":
    sys.exit(main())

Run it in GitHub Actions

Gate only the PRs that can change agent behavior — prompts, tools, and the golden set itself. Store credentials as repository secrets.

name: Policy Compliance Gate

on:
  pull_request:
    paths:
      - "prompts/**"
      - "tools/**"
      - "tests/eval/**"

jobs:
  policy-gate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install httpx
      - name: Run policy compliance gate
        env:
          PALQEE_PRISMA_BASE_URL: ${{ secrets.PALQEE_PRISMA_BASE_URL }}
          PALQEE_PRISMA_API_KEY: ${{ secrets.PALQEE_PRISMA_API_KEY }}
          PALQEE_PRISMA_WORKSPACE_ID: ${{ secrets.PALQEE_PRISMA_WORKSPACE_ID }}
          PALQEE_PRISMA_PROJECT_ID: ${{ vars.PALQEE_PRISMA_PROJECT_ID }}
        run: python tests/eval/gate.py

The script exits 1 when the pass rate falls short, which fails the step and blocks the merge.

Run it as a pytest check

To see the gate alongside your unit tests, wrap the same call as an assertion:

import json, os, httpx


def test_policy_compliance_gate():
    with open("tests/eval/golden_dataset.json") as f:
        records = json.load(f)

    resp = httpx.post(
        f"{os.environ['PALQEE_PRISMA_BASE_URL']}/api/v1/evaluations/evaluate",
        headers={"X-API-Key": os.environ["PALQEE_PRISMA_API_KEY"]},
        json={
            "workspace_id": os.environ["PALQEE_PRISMA_WORKSPACE_ID"],
            "project_id": os.environ["PALQEE_PRISMA_PROJECT_ID"],
            "evaluators": [{"name": "correctness"}, {"name": "hallucination"}],
            "data": records,
        },
        timeout=180.0,
    )
    resp.raise_for_status()
    results = resp.json()["results"]

    clean = [
        r for r in results
        if r["evaluations"].get("correctness") == "correct"
        and r["evaluations"].get("hallucination") == "factual"
    ]
    rate = len(clean) / len(results)
    assert rate >= 0.90, f"pass rate {rate:.0%} below 90% ({len(clean)}/{len(results)} clean)"

Gate on a policy metric

The synchronous endpoint runs the built-in correctness and hallucination evaluators only — any other evaluator name is skipped. To gate on a custom policy metric you authored with Evaluators.custom(), run the golden set through the batch job path instead: upload it as a dataset and create a job against a run that has your metric attached, then read the results back. The end-to-end build — golden dataset, custom metric, batch job, and threshold gate — is the CI/CD Quality Gates cookbook.

Troubleshooting

SymptomCause
An evaluator is missing from evaluationsThe synchronous endpoint supports correctness and hallucination only — other names (including custom metrics) are skipped. Use the batch path for policy metrics.
400 No valid evaluators configuredNone of the names in evaluators matched a built-in. Check spelling — names are case-insensitive.
401 / 403Missing or invalid X-API-Key, or the key isn't scoped to this workspace/project.
Lots of ambiguous labelsThe model couldn't decide. Tighten the reference answers in your golden set, or route ambiguous cases to human review.
422 on the requestA data item is missing query or response, or the batch exceeds 100 records.

Next steps

On this page