fix: use last-match in generic LLM judge postprocess (verdict-injection defense)#2534
Open
AUTHENSOR wants to merge 1 commit into
Open
fix: use last-match in generic LLM judge postprocess (verdict-injection defense)#2534AUTHENSOR wants to merge 1 commit into
AUTHENSOR wants to merge 1 commit into
Conversation
…on defense) _generic_llmjudge_postprocess used re.search (first-match) to extract the A/B verdict from the judge response. The model-under-test's output is interpolated verbatim into the judge prompt, so an early injected verdict tag echoed in the judge's response wins over the judge's actual final verdict. Switch to re.findall + take the last match. Same pattern fixed across deepeval, ragas, guardrails-ai, promptfoo, instructor, CrewAI, LlamaIndex, AutoGPT, lighteval, HumanEval, and EvalPlus. This shared helper is used by 13+ datasets (MedXpertQA, Medbullets, medmcqa, supergpqa, livereasonbench, simpleqa, matbench, mtbench101, writingbench, clbench, fofo, etc).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_generic_llmjudge_postprocessingeneric.pyusedre.search(first-match, unanchored) to extract the A/B verdict from the judge's response. The model-under-test's output is interpolated verbatim into the judge prompt (via{prediction}in configs), so an early injected verdict tag (e.g. starting the answer with "A. ") that gets echoed in the judge's response wins over the judge's actual final verdict.This is the verdict-injection class — the same pattern fixed across deepeval, ragas, guardrails-ai, promptfoo, instructor, CrewAI, LlamaIndex, AutoGPT, lighteval, HumanEval, and EvalPlus.
Impact
This shared helper (
_generic_llmjudge_postprocess) is used by 13+ datasets across OpenCompass, including:A model that prepends its answer with the correct verdict tag ("A. ") can flip a binary correct/incorrect judgment on any of these benchmarks.
Fix
Switch from
re.search(first-match) tore.findall+ take the last match. The judge's rubric instructs it to end with the verdict, so the last match is the authoritative one.Verified
Checklist