Some outputs are easy to grade: does this equal that? But most interesting work is fuzzy. Is this summary faithful? Is this answer actually grounded in the retrieved context? Is this reply on-brand? You cannot exact-match your way to those judgments, and you cannot put a human on every one at scale. An LLM-as-judge is the practical middle ground: a model call that scores another model's output against a rubric you write.
Why it matters for context engineering
You cannot improve what you cannot measure. Every context technique in this dictionary, from retrieval to memory, is only worth adding if it moves a number. A judge gives you that number for tasks where "correct" is a matter of degree, which turns tuning your system from guesswork into something you can actually iterate on.
The pattern: force a structured verdict
The key is to make the judge return a structured score, not a paragraph of prose you then have to parse. Give it a schema and it hands back a clean, typed verdict:
import { generateObject } from 'ai'
import { openai } from '@ai-sdk/openai'
import { z } from 'zod'
const { object } = await generateObject({
model: openai('gpt-5-mini'),
schema: z.object({
score: z.number().min(0).max(1),
reason: z.string(),
}),
prompt: 'Rate how well "Paris" answers "capital of France?". Return a score 0-1 and a short reason.',
})The reason field matters as much as the score: it makes the judgment debuggable, so when a grade looks wrong you can see why the judge decided it.
Using it well
- Write a rubric, not a vibe. "Rate 1-10" gets you noise. Spell out what each level means, or break the score into named sub-checks.
- Judge one thing at a time. Faithfulness, relevance, and tone are separate questions; asking for all three in one number hides which one failed.
- Watch for bias. Judges can favour longer answers, their own style, or the first option shown. Check the judge against a few human labels before you trust it.
Related terms
Self-consistency
Self-consistency samples the same prompt several times and takes the majority answer. It trades a few extra calls for a big drop in variance, turning a model that sometimes slips into one that reliably lands on its best answer.
Read definition →ConceptAgents vs. workflows
A workflow follows a path you designed in advance; an agent decides its own path at run time by calling tools in a loop toward a goal. Knowing which one you actually need is the first context-engineering decision.
Read definition →ConceptRubric
A rubric is the explicit set of criteria a judge scores against, with each level spelled out. Without one, asking a model to rate quality from 1 to 10 produces numbers that mean nothing and drift between runs.
Read definition →ConceptEval set
An eval set is a fixed collection of real inputs with known-good outputs that you score your system against. It is what turns "that felt better" into a number you can compare across changes.
Read definition →PatternValidatedPairwise comparison
Pairwise comparison asks which of two outputs is better rather than scoring either in isolation. Relative judgements are far more consistent than absolute ones, which makes it the reliable way to tell whether a change actually helped.
Read definition →AntipatternProvenGoodharting
Goodharting is optimising a system until it satisfies the metric rather than the goal the metric stood for. Your eval score climbs, real quality does not, and the number you trusted is now the thing hiding the problem.
Read definition →PatternValidatedEvaluator-optimizer
Evaluator-optimizer pairs a generator with a separate critic that scores its output and sends it back for revision. It works when quality is easier to judge than to produce, which is more often than you would expect.
Read definition →