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.
| Field | Type | Description |
|---|---|---|
id | string | Judge identifier. |
criteria | string | What to evaluate. |
scale | { min: number; max: number } | Score range. |
rubric | Record<number, string>? | Optional score descriptions. |
context | string? | Extra evaluator context. |
chainOfThought | boolean? | Whether to request a concise explanation before scoring. Default: true. |
fewShot | JudgeFewShot[]? | Calibration examples. |
generate | GenerateObjectFn? | Structured generation function. |
model | unknown? | Judge model. |
detailSchema | z.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:
| Field | Type | Description |
|---|---|---|
score | number | Clamped to the configured scale. |
reasoning | string | Concise explanation for the score. |
metricId | string | Judge id. |
detail | TDetail? | Structured details when detailSchema is configured. |
_meta | OperationResultMeta | Exact 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.
| Metric | Criteria | Scale |
|---|---|---|
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";