Skip to content

createJudge

createJudge<TOptions>(name, assess): Judge<TOptions>

Creates a named judge object from an assessment function.

TOptions extends JudgeContext<any, any, any>

string

Stable judge name shown in assertion messages and reports.

JudgeAssessFn<TOptions>

Function that scores one normalized judge context.

Judge<TOptions>

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.

createJudge<TOptions>(config): Judge<TOptions>

Creates a named judge object from an assessment function.

TOptions extends JudgeContext<any, any, any>

CreateJudgeConfig<TOptions>

Judge<TOptions>

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.

createJudge<TInput, TOutput, TOptions, THarness>(name, assess): Judge<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>

Creates a named judge object from an assessment function.

TInput

TOutput extends JsonValue | undefined

TOptions extends object = Record<never, never>

THarness extends Harness<TInput, TOutput> | undefined = Harness<TInput, TOutput> | undefined

string

Stable judge name shown in assertion messages and reports.

JudgeAssessFn<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>

Function that scores one normalized judge context.

Judge<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>

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.

createJudge<TInput, TOutput, TOptions, THarness>(config): Judge<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>

Creates a named judge object from an assessment function.

TInput

TOutput extends JsonValue | undefined

TOptions extends object = Record<never, never>

THarness extends Harness<TInput, TOutput> | undefined = Harness<TInput, TOutput> | undefined

CreateJudgeConfig<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>

Judge<CreateJudgeContext<TInput, TOutput, TOptions, THarness>>

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.

createJudge<TOptions, TInput, TOutput>(name, assessor, assess): Judge<TOptions>

TOptions extends JudgeContext<any, any, any>

TInput

TOutput

string

JudgeAssessor<TInput, TOutput>

JudgeAssessWithAssessorFn<TOptions, TInput, TOutput>

Judge<TOptions>