---
title: Score a run against a policy
description: Record a support run, put a refund policy in a knowledgebase, link
  it to a hosted judge, score the run, and verify the verdict and knowledgebase
  tool spans from the CLI.
editUrl: true
head: []
template: doc
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

When you want to know whether a support agent followed company policy, score a finished run with a hosted judge that can look the policy up. By the end you have a knowledgebase with a refund policy, a hosted judge linked to it, a verdict on one run, and span evidence that the judge called `kb_list`, `kb_search`, or `kb_read`.

After `prefactor login`, the rest of this guide stays in the terminal. Matching OpenAPI operations sit next to the CLI commands where that helps.

## Before you start

- The [Prefactor CLI](/cli/getting-started) installed.
- A Prefactor account. `prefactor login` opens a browser once to sign in and save an account-scoped token; that is the only browser step.
- An API key for Anthropic, OpenAI, Ollama Cloud, Together AI, or an OpenAI-compatible endpoint.
- An agent with at least one finished run. The [Quickstart](/quickstart) registers a support chatbot and records spans you can score. Find the agent with `prefactor agents list` and a run with `prefactor agent-instances list --agent-id <agent-id>`.

Every command prints JSON. The IDs you need for the next step are in `details.id`.

## Save a sample refund policy

Create `refund-policy.md` with something short the judge must look up, not guess:

```markdown
## Refund policy

- Refunds are allowed within 30 days of purchase.
- Digital goods are refundable only if the customer has not downloaded them.
- Store credit is offered when a refund is refused under the rules above.
- Agents must quote the matching rule when they refuse or approve a refund.
```

## Create the knowledgebase

1. Create a knowledgebase. Write the description for the judge: it becomes part of the tool descriptions Prefactor shows the model.

   ```bash
   prefactor knowledgebases create \
     --name "Support policies" \
     --description "Company refund and support policies. Use when scoring whether an agent followed refund rules."
   ```

   API: [POST /api/v1/knowledgebase](/api/platform/operations/actionknowledgebasecreate).

2. Add the policy document:

   ```bash
   prefactor knowledgebase-documents create \
     --knowledgebase-id <knowledgebase-id> \
     --path policies/refunds.md \
     --content @./refund-policy.md
   ```

   API: [POST /api/v1/knowledgebase_document](/api/platform/operations/actionknowledgebasedocumentcreate).

## Set up a hosted judge that must read the policy

3. Connect an LLM provider. Pass the key as `@path` so it stays out of your shell history:

   ```bash
   prefactor llm-providers create \
     --name "Anthropic production" \
     --provider anthropic \
     --api-key @./anthropic-key.txt
   ```

4. Add a model:

   ```bash
   prefactor llm-provider-models create \
     --llm-provider-id <provider-id> \
     --api-name claude-haiku-4-5
   ```

5. Register the judge and save a criterion that forces a knowledgebase lookup. Create `criterion.md`:

   ```markdown
   Score whether the support agent followed the company refund policy.

   You must look up the refund policy in your linked knowledgebases before
   deciding. Use kb_list, kb_search, or kb_read. Quote the rule you used.

   Pass only if the agent's reply matches that policy. Fail if the reply
   contradicts the policy, skips a required rule, or you could not read the
   policy.
   ```

   Then:

   ```bash
   prefactor judges create --name "Refund policy judge"
   prefactor judges create-version \
     --agent-id <judge-id> \
     --hosted-llm-provider-model-id <model-id> \
     --criterion @./criterion.md
   ```

   API: [POST /api/v1/agent_version/hosted_judge](/api/platform/operations/actionagentversioncreatehostedjudge).

## Link the knowledgebase and the agent

6. Link the knowledgebase to the judge:

   ```bash
   prefactor agent-knowledgebase-links create \
     --agent-id <judge-id> \
     --knowledgebase-id <knowledgebase-id>
   ```

   API: [POST /api/v1/agent_knowledgebase_link](/api/platform/operations/actionagentknowledgebaselinkcreate).

   Hosted judges get `kb_list`, `kb_search`, and `kb_read` on runs that start after the link exists. A version saved before knowledgebase tools existed does not offer them; run `judges create-version` again so the new version can. See [Knowledgebase](/platform/concepts/knowledgebase).

7. Attach the judge to the support agent:

   ```bash
   prefactor agent-associations create \
     --from-agent-id <judge-id> \
     --to-agent-id <agent-id> \
     --association-type judge \
     --trigger on_demand
   ```

## Score a run

8. Ask the judge to score a finished support run:

   ```bash
   prefactor judges score <agent-instance-id> --judge-agent-id <judge-id>
   ```

   The response is the new judge run, in Preparing. Prefactor writes the run record and starts the hosted judge in the background. API: [POST /api/v1/agent_instance/{agent_instance_id}/judge](/api/platform/operations/actionagentinstancejudge).

## Verify

Check the scored run for the verdict:

```bash
prefactor agent-instances retrieve <agent-instance-id>
```

When the judge run finishes, `details.quality_payloads` has an entry named `$judge:<judge-id>` with a `verdict` and an `explanation`. The explanation should quote the policy rule the judge used.

Find the judge run, then list its spans for knowledgebase tool calls:

```bash
prefactor agent-instances list --agent-id <judge-id>
prefactor agent-spans list --agent-instance-id <judge-run-id>
```

Look for activity spans whose tools or schema names include `kb_list`, `kb_search`, or `kb_read`. Those spans are the evidence that the judge looked up the policy. The same judge run is on the [Judge page › History tab](/web-app/judge); the verdict is on the scored run's [Quality tab](/web-app/agent-instance/quality).

## If it didn't work

- **`prefactor login` is the only step that needs a browser.** If later commands fail with an auth error, run `prefactor login` again.
- **No finished run to score.** Complete the [Quickstart](/quickstart) chat, then list instances again.
- **`api-name` "is not a known model for this provider".** For a named provider, use a models.dev name for that provider, or a custom OpenAI-compatible provider.
- **"This agent does not judge that agent instance".** Attach the judge with `agent-associations create` (step 7).
- **Verdict with no `kb_*` spans.** The judge was not linked when the run started, or its version predates knowledgebase tools. Link the knowledgebase, create a new judge version, score again, and inspect the new judge run.
- **Judge run stuck in Preparing or failed.** Check the provider key with `prefactor llm-providers update <provider-id> --api-key @./key.txt`. Prefactor does not test the key when you save it.

## Related

- [Evals](/platform/evals) — how hosted judges use linked knowledgebases.
- [Set up a judge from the CLI](/cli/judges) — hosted and remote judge setup without a policy example.
- [Give agents reference documents](/guides/give-agents-reference-documents) — create and link knowledgebases in the web app.
- [Knowledgebase](/platform/concepts/knowledgebase) — `kb_list`, `kb_search`, `kb_read`, and revisions.
