← All Exercises
Score Prompt Outputs Against a Rubric
basicjavascript
Background
Prompt changes are unverifiable without a rubric. Turning style expectations into checkable criteria stops regressions from shipping as "looks fine".
Problem
Evaluate candidate outputs against a rubric of required substrings and a length ceiling, returning pass/fail plus the failed criteria per output.
Input
JSON object: { outputs: [{ id, text }], rubric: { mustInclude: string[], maxChars: number } }Output
JSON array of { id, passed, failedCriteria: string[] }Sample tests
Sample 1
Input: {"outputs":[{"id":"o1","text":"Answer: 42 because the cache holds it."},{"id":"o2","text":"42"}],"rubric":{"mustInclude":["Answer:","because"],"maxChars":80}}Expected: [{"id":"o1","passed":true,"failedCriteria":[]},{"id":"o2","passed":false,"failedCriteria":["missing:Answer:","missing:because"]}]Sample 2
Input: {"outputs":[{"id":"o3","text":"Answer: 7 because seven"}],"rubric":{"mustInclude":["Answer:"],"maxChars":5}}Expected: [{"id":"o3","passed":false,"failedCriteria":["too-long"]}]Your solution
Learning objective
Make prompt quality a regression-testable property.