Recipe catalog / answer-grade
Grade an answer against a rubric
answer-grade is a Jev recipe from the jev-recipes TypeScript package. How well does answer meet rubric as a response to question, on a five-level rubric from no credit to full credit? Use it when you grade free-text answers against a written rubric and want a graded level with a confidence you can route to a human grader when low.
Last updated .
Explore this recipe interactively · Source and implementation guide · Markdown version
How do I use answer-grade in TypeScript?
Install with npm install jev-recipes. Requires Node.js 22.9 or newer and ES modules. Set TYPESAFE_API_KEY in your server environment for live calls, which send input to TypeSafe and use API quota. See the installation guide.
import { answerGrade } from 'jev-recipes/answer-grade';
const result = await answerGrade({
"question": "Explain why the sky appears blue during the day.",
"answer": "Sunlight contains all colors. When it passes through the atmosphere, gas molecules scatter shorter wavelengths like blue much more than longer wavelengths like red, so blue light reaches our eyes from every direction in the sky.",
"rubric": "Full credit requires: (1) sunlight is made of many wavelengths; (2) atmospheric molecules scatter light; (3) shorter wavelengths scatter more strongly (Rayleigh scattering); (4) explains why violet is not the dominant perceived color.",
"minConfidence": 0.8
});
console.log(result);
What input does answer-grade take?
| Field | Type | Needed |
|---|---|---|
| question | string | Required |
| answer | string | Required |
| rubric | string | Required |
| minConfidence | number | Optional |
Full input and result schemas
{
"input": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"question": {
"type": "string"
},
"answer": {
"type": "string"
},
"rubric": {
"type": "string"
},
"minConfidence": {
"type": "number",
"minimum": 0,
"maximum": 1
}
},
"required": [
"question",
"answer",
"rubric"
]
},
"result": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"model": {
"type": "string"
},
"usage": {
"type": "object",
"properties": {
"input_tokens": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"output_tokens": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"required": [
"input_tokens",
"output_tokens"
],
"additionalProperties": false
},
"status": {
"type": "string",
"enum": [
"ready",
"review"
]
},
"score": {
"type": "number",
"minimum": 0
},
"level": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"confidence": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"probabilities": {
"type": "object",
"propertyNames": {
"type": "string"
},
"additionalProperties": {
"type": "number",
"minimum": 0,
"maximum": 1
}
},
"grade": {
"type": "string",
"enum": [
"none",
"minimal",
"partial",
"mostly",
"full"
]
}
},
"required": [
"model",
"usage",
"status",
"score",
"level",
"confidence",
"probabilities",
"grade"
],
"additionalProperties": false
}
}What does a answer-grade result look like?
This hand-authored response demonstrates the contract. It is not a model accuracy measurement. Run it without an API key: npx jev-recipes demo answer-grade.
{
"model": "demo-fixture",
"usage": {
"input_tokens": 0,
"output_tokens": 0
},
"status": "ready",
"score": 2.95,
"level": 3,
"confidence": 0.81,
"probabilities": {
"0": 0,
"1": 0.02,
"2": 0.09,
"3": 0.81,
"4": 0.08
},
"grade": "mostly"
}
Input
See shared options and behavior for client configuration, validation, and errors. Types are inferred from this folder's Zod 4 schemas.
Result
grade is one of none, minimal, partial, mostly, or full, taken from the most likely rubric level. level is that level's index from 0 to 4. score is Jev's expected value across the levels and can fall between them; use it when you need a finer-grained number than five bands, such as converting to points.
A result is ready when confidence meets minConfidence. Otherwise it is review and still carries the graded values for inspection. probabilities is keyed by level index.
Reuse and calls
Uses the shared score helper. This folder owns the grading question, the five-level wording, and the review policy. A live invocation makes one logical Jev request.
Limits
The grade is only as sharp as the supplied rubric. A rubric that lists concrete criteria produces a defensible grade; a rubric that says "good explanation" does not. The recipe does not fact-check beyond what the rubric asks for, so an answer that is fluent but wrong can still score well against a rubric that never names correctness. Length, style, and effort are ignored unless the rubric mentions them. To rank two answers under one rubric use draft-compare.
Example input
demo.json contains editable input and a hand-authored response. After installing jev-recipes, npx jev-recipes demo answer-grade shows an offline illustration, not an accuracy measurement. Use npx jev-recipes describe answer-grade to inspect the input and result schemas.
How accurate is answer-grade?
No verified live accuracy measurement is available. Evaluate representative cases before using this decision in your workflow.
Use the evaluation guide to measure this decision on your own labeled cases.
What are the limits of answer-grade?
- Grades against the supplied rubric only. A vague rubric yields a vague grade.
- Does not check factual accuracy beyond what the rubric states; a confidently wrong answer can meet a weak rubric.
- The score is an expected value over levels. Map it to points or letters in application code.
Which recipes are related to answer-grade?
- draft-compare: Use draft-compare to rank two answers against the same rubric instead of grading one.
- grounding-level: Use grounding-level when the criterion is fidelity to a source passage rather than a rubric.