Repository navigation
FIX: Fingerprint target judgment adaptation in the replay contract (#3753) - #4403
Đái Chung Hy (daichunghy) wants to merge 7 commits into
Conversation
|
Đái Chung Hy (@daichunghy) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
🟡 Changes recommended
Blocked acquisitions bypass the adaptation compatibility check, allowing judgments recorded under one template to replay under a different template despite mismatched fingerprints.
1 open issue
What changed in this PR
This PR addresses #3753 by adding target-side normalization settings to PyRIT’s judgment replay fingerprint, so changed schema instructions can invalidate replay while older observations remain supported.
Changes:
- Fingerprints the resolved normalization pipeline during acquisition and replay.
- Passes chat targets into replay parsing across judgment scorers.
- Adds regression tests for changed templates, matching templates, and legacy fingerprints.
| File | Description |
|---|---|
tests/unit/score/test_judgment_observation.py |
Adds template compatibility and legacy replay tests. |
pyrit/score/true_false/shieldgemma_scorer.py |
Supplies the target for ShieldGemma replay validation. |
pyrit/score/true_false/self_ask_true_false_scorer.py |
Supplies the target for true/false replay validation. |
pyrit/score/true_false/self_ask_refusal_scorer.py |
Supplies the target for refusal replay validation. |
pyrit/score/true_false/self_ask_general_true_false_scorer.py |
Supplies the target for general true/false replay validation. |
pyrit/score/true_false/self_ask_category_scorer.py |
Supplies the target for category replay validation. |
pyrit/score/true_false/llamaguard_scorer.py |
Supplies the target for LlamaGuard replay validation. |
pyrit/score/llm_scoring.py |
Adds adaptation fingerprints and legacy compatibility handling. |
pyrit/score/float_scale/self_ask_scale_scorer.py |
Supplies the target for scale replay validation. |
pyrit/score/float_scale/self_ask_likert_scorer.py |
Supplies the target for Likert replay validation. |
pyrit/score/float_scale/self_ask_general_float_scale_scorer.py |
Supplies the target for general float-scale replay validation. |
pyrit/score/float_scale/insecure_code_scorer.py |
Supplies the target for insecure-code replay validation. |
pyrit/score/float_scale/decision_scorer.py |
Supplies the target for decision replay validation. |
pyrit/score/assert_dimension_scorer.py |
Supplies the target for dimension replay validation. |
Review effort: Balanced
| """ | ||
| if not isinstance(observation.payload, ScorerTargetResponsePayload): | ||
| raise NonReplayableObservationError("A judgment scorer requires a judgment observation.") | ||
| target_adaptation = _target_judgment_adaptation(target) |
There was a problem hiding this comment.
Thanks for catching this. You're right: the adaptation check only ran inside _parse_judgment_observation, while MessageScorer._score_observation returned the undetermined score for Acquisition.ERROR before reaching the parser. This meant a blocked judgment stored under one template could be replayed as undetermined under a different template.
I've moved the contract compatibility check into a shared helper, _validate_replay_contract_compatibility, which is now called by the parser. The error branch in _score_observation also goes through the leaf scorer's parser before falling back to undetermined. This ensures the contract is validated first, including the explicit legacy fingerprints. The pre-adaptation form is checked even when no text judgment was retained, so blocked observations stored before this change remain replayable. Only after the contract check does the parser signal that there's nothing to parse.
I've also added test_blocked_judgment_replay_rejects_changed_schema_normalizer_template_async: a blocked acquisition stored under template A still replays as undetermined under template A, but raises NonReplayableObservationError under template B. The full tests/unit/score run reports 7,140 passed. The only 4 failures are dispatch_type_exhaustiveness tests that fail identically on unmodified main.

Description
Fixes #3753.
A stored target-backed judgment could be replayed by a scorer whose judge target differed from the acquiring target only in its schema-normalization instructions, even though replay promises the exact acquisition configuration. The replay contract fingerprint covered the response handler, category, and the scorer's judgment identifier, but not the target-side adaptation that rewrites the judge's prompts before parsing.
TargetConfiguration.as_identifier_params()serialization (the same serializationRoundRobinTargetvalidation already consumes). Descriptive capabilities and policies are not added to the contract; only the pipeline that actually adapts the exchange._parse_judgment_observation, and_run_llm_scoring_asynccomputes the same projection from the acquiring target, so acquisition and replay contracts are directly comparable.Tests
Added to
tests/unit/score/test_judgment_observation.py, using local targets that differ only in theirJsonSchemaNormalizertemplate:test_judgment_replay_rejects_changed_schema_normalizer_template_async: replay under a changed template raisesNonReplayableObservationErrorand never calls the changed target (fails on main before this change).test_judgment_replay_accepts_matching_schema_normalizer_template_async: replay under an identical template succeeds without calling the target.test_judgment_replay_keeps_pre_adaptation_contract_replayable_async: an observation whose stored fingerprint is rewritten to the pre-adaptation form remains replayable.Full
test_judgment_observation.py: 85 passed. The widertests/unit/scoresuite plustest_target_configuration.py: 7,179 passed, with 8dispatch_type_exhaustivenessfailures that fail identically on unmodified main.Limitations
TargetConfiguration(for example test doubles) opt out of adaptation fingerprinting, exactly as handlers without a stable replay identifier opt out today.