Skip to content

Score a run against a policy

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.

  • The Prefactor CLI 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 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.

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

## 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.
  1. Create a knowledgebase. Write the description for the judge: it becomes part of the tool descriptions Prefactor shows the model.

    Terminal window
    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.

  2. Add the policy document:

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

    API: POST /api/v1/knowledgebase_document.

Set up a hosted judge that must read the policy

Section titled “Set up a hosted judge that must read the policy”
  1. Connect an LLM provider. Pass the key as @path so it stays out of your shell history:

    Terminal window
    prefactor llm-providers create \
    --name "Anthropic production" \
    --provider anthropic \
    --api-key @./anthropic-key.txt
  2. Add a model:

    Terminal window
    prefactor llm-provider-models create \
    --llm-provider-id <provider-id> \
    --api-name claude-haiku-4-5
  3. Register the judge and save a criterion that forces a knowledgebase lookup. Create criterion.md:

    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:

    Terminal window
    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.

  1. Link the knowledgebase to the judge:

    Terminal window
    prefactor agent-knowledgebase-links create \
    --agent-id <judge-id> \
    --knowledgebase-id <knowledgebase-id>

    API: POST /api/v1/agent_knowledgebase_link.

    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.

  2. Attach the judge to the support agent:

    Terminal window
    prefactor agent-associations create \
    --from-agent-id <judge-id> \
    --to-agent-id <agent-id> \
    --association-type judge \
    --trigger on_demand
  1. Ask the judge to score a finished support run:

    Terminal window
    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.

Check the scored run for the verdict:

Terminal window
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:

Terminal window
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; the verdict is on the scored run’s Quality tab.

  • 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 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.