Crux
API Reference@use-crux/core

Scoring

LLM-as-a-judge scoring and pre-built quality metrics.

import { judge, metrics } from "@use-crux/core/scoring";

judge(config)

Create a reusable LLM-as-a-judge scorer.

FieldTypeDescription
idstringJudge identifier.
criteriastringWhat to evaluate.
scale{ min: number; max: number }Score range.
rubricRecord<number, string>?Optional score descriptions.
contextstring?Extra evaluator context.
chainOfThoughtboolean?Whether to request a concise explanation before scoring. Default: true.
fewShotJudgeFewShot[]?Calibration examples.
generateGenerateObjectFn?Structured generation function.
modelunknown?Judge model.
detailSchemaz.ZodType<TDetail>?Optional structured details beside the score.
const brandVoice = judge({
  id: "brand-voice",
  criteria: "Does the copy match the warm, direct brand voice?",
  scale: { min: 1, max: 10 },
  generate: generateObjectFn,
  model,
});

const result = await brandVoice.score({
  input: "Write onboarding copy",
  output: "Welcome. Let us get you set up.",
});

score() returns:

FieldTypeDescription
scorenumberClamped to the configured scale.
reasoningstringConcise explanation for the score.
metricIdstringJudge id.
detailTDetail?Structured details when detailSchema is configured.
_metaOperationResultMetaExact scoring.judge trace and span owned by Core.

Per-call score(input, options) can override generate, model, and evalId.

The raw structured generate callback is an application/provider port and does not need to supply Crux IDs. See Operation Result Correlation.

metrics

Pre-built judges for common quality dimensions. Each factory takes { generate, model } and returns a JudgeInstance.

MetricCriteriaScale
metrics.relevance()Is the output relevant to the input query?1-5
metrics.faithfulness()Is the output faithful to provided context?1-5
metrics.coherence()Is the output logically coherent and well-structured?1-5
metrics.completeness()Does the output address all aspects of the query?1-5
metrics.toxicity()Is the output free from harmful content?1-5
metrics.conciseness()Is the output appropriately concise?1-5
const relevance = metrics.relevance({ generate: generateObjectFn, model });
const result = await relevance.score({ input: query, output: response });

Safety Integration

Runtime Safety enforcement is authored from the Safety subpath, not from scoring:

import { boundary, constraint } from "@use-crux/core/safety";
import { judge } from "@use-crux/core/scoring";

const brandVoiceJudge = judge({
  id: "brand-voice",
  criteria,
  scale,
  generate,
  model,
});

const brandVoiceGate = constraint({
  id: "brand-voice",
  on: boundary.output.text(),
  run: constraint.judge({ judge: brandVoiceJudge, minScore: 7 }),
});

For Evals, scorers.judge() in @use-crux/core/eval reuses the same judge machinery with rubric and choice-score modes.

Types

import type {
  JudgeConfig,
  JudgeFewShot,
  JudgeInput,
  JudgeInstance,
  JudgeResult,
  JudgeScoreOptions,
  MetricDefaults,
} from "@use-crux/core/scoring";

On this page