Agent Wranglers

AIF-27Recommended

Grade with code before a grading model

Grade every quality that code can check with exact code checks. Use a grading model only for qualities code cannot check. It must first agree with people on at least 80% of good answers and 80% of bad ones.

How to do it

Check the schema, enum values, required facts, forbidden phrases, citations and length in code. They are fast, free and never vary. For tone or helpfulness, write a grading prompt with a fixed rubric and a yes or no answer, not a score from 1 to 10. Have two people label 100 answers, with at least 30 bad ones among them. Then measure the grading model's agreement on the good and the bad answers apart. A grader that calls everything good can agree on 90% of a set where 90% is good. Use a different model, or at least a different prompt, from the one being graded. The testing playbook covers the eval set in grade AI features against fixed examples.

Examples

TypeScript example

export function gradeReturnAnswer(answer: ReturnAnswer, expect: Expectation): string[] {
  const failures: string[] = [];
  if (answer.eligible !== expect.eligible) failures.push(`eligible was ${answer.eligible}, expected ${expect.eligible}`);
  for (const fact of expect.mustMention ?? []) if (!answer.reason.toLowerCase().includes(fact)) failures.push(`missing "${fact}"`);
  if (/\bguarantee(d)?\b/i.test(answer.reason)) failures.push('promises a guarantee');
  return failures;
}

Python example

def grade_return_answer(answer: ReturnAnswer, expect: dict) -> list[str]:
    failures = []
    if answer.eligible != expect["eligible"]:
        failures.append(f"eligible was {answer.eligible}, expected {expect['eligible']}")
    failures += [f'missing "{fact}"' for fact in expect.get("must_mention", []) if fact not in answer.reason.lower()]
    if re.search(r"\bguarantee(d)?\b", answer.reason, re.I):
        failures.append("promises a guarantee")
    return failures

How to check

Each eval case has at least one code check. The grading model's agreement with the human labels is stored for good and bad answers apart, and each is at least 0.8.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/evals-and-quality/code-graders-first">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.