createJudge
Call Signature
Section titled “Call Signature”createJudge<
TOptions>(name,assess):Judge<TOptions>
Creates a named judge object from an assessment function.
Type Parameters
Section titled “Type Parameters”TOptions
Section titled “TOptions”TOptions extends JudgeContext<any, any, any, any>
Parameters
Section titled “Parameters”string
Stable judge name shown in assertion messages and reports.
assess
Section titled “assess”JudgeAssessFn<TOptions>
Function that scores one normalized judge context.
Returns
Section titled “Returns”Judge<TOptions>
Example
Section titled “Example”import { createJudge, type JudgeContext } from "vitest-evals";
type RefundOutput = { status: "approved" | "denied" };type RefundMetadata = { expected: { status: RefundOutput["status"] } };
export const RefundStatusJudge = createJudge( "RefundStatusJudge", async ({ output, metadata }: JudgeContext<string, RefundOutput, RefundMetadata>) => ({ score: output.status === metadata.expected.status ? 1 : 0, metadata: { rationale: `Expected ${metadata.expected.status}, got ${output.status}`, }, }),);For LLM-backed judges, prefer the object form with ctx.runJudge(...) so
provider-specific model configuration stays in the judge harness.
Call Signature
Section titled “Call Signature”createJudge<
TOptions>(config):Judge<TOptions>
Creates a named judge object from an assessment function.
Type Parameters
Section titled “Type Parameters”TOptions
Section titled “TOptions”TOptions extends JudgeContext<any, any, any, any>
Parameters
Section titled “Parameters”config
Section titled “config”CreateJudgeConfig<TOptions>
Returns
Section titled “Returns”Judge<TOptions>
Example
Section titled “Example”import { createJudge, type JudgeContext } from "vitest-evals";
type RefundOutput = { status: "approved" | "denied" };type RefundMetadata = { expected: { status: RefundOutput["status"] } };
export const RefundStatusJudge = createJudge( "RefundStatusJudge", async ({ output, metadata }: JudgeContext<string, RefundOutput, RefundMetadata>) => ({ score: output.status === metadata.expected.status ? 1 : 0, metadata: { rationale: `Expected ${metadata.expected.status}, got ${output.status}`, }, }),);For LLM-backed judges, prefer the object form with ctx.runJudge(...) so
provider-specific model configuration stays in the judge harness.
Call Signature
Section titled “Call Signature”createJudge<
TOptions,TInput,TOutput>(name,assessor,assess):Judge<TOptions>
Type Parameters
Section titled “Type Parameters”TOptions
Section titled “TOptions”TOptions extends JudgeContext<any, any, any, any>
TInput
Section titled “TInput”TInput
TOutput
Section titled “TOutput”TOutput
Parameters
Section titled “Parameters”string
assessor
Section titled “assessor”JudgeAssessor<TInput, TOutput>
assess
Section titled “assess”JudgeAssessWithAssessorFn<TOptions, TInput, TOutput>
Returns
Section titled “Returns”Judge<TOptions>