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>
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 } from "vitest-evals";
type RefundOutput = { status: "approved" | "denied" };
export const RefundStatusJudge = createJudge< string, RefundOutput, { expectedStatus: RefundOutput["status"] }>( "RefundStatusJudge", async ({ output, expectedStatus }) => ({ score: output.status === expectedStatus ? 1 : 0, metadata: { rationale: `Expected ${expectedStatus}, 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>
Parameters
Section titled “Parameters”config
Section titled “config”CreateJudgeConfig<TOptions>
Returns
Section titled “Returns”Judge<TOptions>
Example
Section titled “Example”import { createJudge } from "vitest-evals";
type RefundOutput = { status: "approved" | "denied" };
export const RefundStatusJudge = createJudge< string, RefundOutput, { expectedStatus: RefundOutput["status"] }>( "RefundStatusJudge", async ({ output, expectedStatus }) => ({ score: output.status === expectedStatus ? 1 : 0, metadata: { rationale: `Expected ${expectedStatus}, 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<
TInput,TOutput,TOptions,THarness>(name,assess):Judge<CreateJudgeContext<TInput,TOutput,TOptions,THarness>>
Creates a named judge object from an assessment function.
Type Parameters
Section titled “Type Parameters”TInput
Section titled “TInput”TInput
TOutput
Section titled “TOutput”TOutput extends JsonValue | undefined
TOptions
Section titled “TOptions”TOptions extends object = Record<never, never>
THarness
Section titled “THarness”THarness extends Harness<TInput, TOutput> | undefined = Harness<TInput, TOutput> | undefined
Parameters
Section titled “Parameters”string
Stable judge name shown in assertion messages and reports.
assess
Section titled “assess”JudgeAssessFn<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>
Function that scores one normalized judge context.
Returns
Section titled “Returns”Judge<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>
Example
Section titled “Example”import { createJudge } from "vitest-evals";
type RefundOutput = { status: "approved" | "denied" };
export const RefundStatusJudge = createJudge< string, RefundOutput, { expectedStatus: RefundOutput["status"] }>( "RefundStatusJudge", async ({ output, expectedStatus }) => ({ score: output.status === expectedStatus ? 1 : 0, metadata: { rationale: `Expected ${expectedStatus}, 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<
TInput,TOutput,TOptions,THarness>(config):Judge<CreateJudgeContext<TInput,TOutput,TOptions,THarness>>
Creates a named judge object from an assessment function.
Type Parameters
Section titled “Type Parameters”TInput
Section titled “TInput”TInput
TOutput
Section titled “TOutput”TOutput extends JsonValue | undefined
TOptions
Section titled “TOptions”TOptions extends object = Record<never, never>
THarness
Section titled “THarness”THarness extends Harness<TInput, TOutput> | undefined = Harness<TInput, TOutput> | undefined
Parameters
Section titled “Parameters”config
Section titled “config”CreateJudgeConfig<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>
Returns
Section titled “Returns”Judge<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>
Example
Section titled “Example”import { createJudge } from "vitest-evals";
type RefundOutput = { status: "approved" | "denied" };
export const RefundStatusJudge = createJudge< string, RefundOutput, { expectedStatus: RefundOutput["status"] }>( "RefundStatusJudge", async ({ output, expectedStatus }) => ({ score: output.status === expectedStatus ? 1 : 0, metadata: { rationale: `Expected ${expectedStatus}, 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>
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>