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.
Before you start
Section titled “Before you start”- The Prefactor CLI installed.
- A Prefactor account.
prefactor loginopens 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 listand a run withprefactor 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
Section titled “Save a sample refund policy”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.Create the knowledgebase
Section titled “Create the knowledgebase”-
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." -
Add the policy document:
Terminal window prefactor knowledgebase-documents create \--knowledgebase-id <knowledgebase-id> \--path policies/refunds.md \--content @./refund-policy.md
Set up a hosted judge that must read the policy
Section titled “Set up a hosted judge that must read the policy”-
Connect an LLM provider. Pass the key as
@pathso it stays out of your shell history:Terminal window prefactor llm-providers create \--name "Anthropic production" \--provider anthropic \--api-key @./anthropic-key.txt -
Add a model:
Terminal window prefactor llm-provider-models create \--llm-provider-id <provider-id> \--api-name claude-haiku-4-5 -
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 beforedeciding. 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 replycontradicts the policy, skips a required rule, or you could not read thepolicy.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
Link the knowledgebase and the agent
Section titled “Link the knowledgebase and the agent”-
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, andkb_readon runs that start after the link exists. A version saved before knowledgebase tools existed does not offer them; runjudges create-versionagain so the new version can. See Knowledgebase. -
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
Score a run
Section titled “Score a run”-
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.
Verify
Section titled “Verify”Check the scored run for the verdict:
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:
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.
If it didn’t work
Section titled “If it didn’t work”prefactor loginis the only step that needs a browser. If later commands fail with an auth error, runprefactor loginagain.- 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.
Related
Section titled “Related”- Evals — how hosted judges use linked knowledgebases.
- Set up a judge from the CLI — hosted and remote judge setup without a policy example.
- Give agents reference documents — create and link knowledgebases in the web app.
- Knowledgebase —
kb_list,kb_search,kb_read, and revisions.