CodeRigor

FREE LESSON

Structured outputs & adversarial evaluation cases

Strict choice grading, missing and malformed response accounting, prompt/data separation and held-out attack families.

An evaluation starts with a question, a dataset and a scoring rule. Freeze the rule before inspecting final results. A model reply is untrusted data: parse it as data, never execute it with eval or treat its instructions as evaluator policy. Keep the expected answer separate from prompt text and model output.

Gold labels belong to the evaluator. The completion is parsed as data and cannot redefine the scoring rule.

Separate subject, answer key and scorer
Only the prompt reaches the adapter. The gold answer joins a strictly validated reply at the scorer, never inside the tested input.
Separate subject, answer key and scorer
Only the prompt reaches the adapter. The gold answer joins a strictly validated reply at the scorer, never inside the tested input.
Python
import json

reply = '{"answer":"B"}'
row = json.loads(reply)
print(set(row) == {"answer"}, row["answer"] == "B")

Exact-match grading is reproducible but narrow. It can miss semantic answers, and a model-judge rubric can introduce its own biases. Start with a small schema that has an independently checkable answer, then audit concrete failures. Here valid outputs contain exactly an answer key whose value is A/B/C/D or ABSTAIN. Extra prose, unknown choices and extra fields are errors.

Python
expected = {"case-1": "A", "case-2": "B"}
replies = {"case-1": '{"answer":"A"}'}
for ident in expected:
    print(ident, "present" if ident in replies else "missing")

Include missing, malformed and abstaining responses in the total example count. A retry should not create a new example ID. Report coverage separately from successful-response accuracy so a system cannot improve its headline score simply by failing on difficult inputs.

For robustness studies, separate development attack templates from held-out families and include benign controls. A suspicious phrase is not itself evidence of a harmful output. Document what a case tests and avoid including the gold answer in the tested input. Our offline schema exercise establishes measurement mechanics; it does not measure a real model's safety.

A missing or malformed reply is still an expected example. Keep it in the support count.

One correct answer out of four expected cases
These four outcomes give total-denominator accuracy 1/4. Filtering out invalid, missing or abstaining responses would change the question being measured.
One correct answer out of four expected cases
These four outcomes give total-denominator accuracy 1/4. Filtering out invalid, missing or abstaining responses would change the question being measured.

The build grades every expected ID once and ignores unrelated reply IDs. Status distinguishes missing, invalid, abstain, correct and incorrect. Tests include instruction-like text to ensure it is treated as an invalid reply, rather than influencing the evaluator.

Watch & read

Free lectures, talks and readings that cover this skill from another angle. All resources →

Focus on domain-specific labels, error analysis and test-data overfitting. Translate those choices into the lesson’s structured scorer, gold-answer separation and visible failure outcomes.