Repository navigation
[BREAKING] MAINT Move in-repo scorers onto the expectation-aware piece hook (phase 12, part 2) - #3312
Merged
Richard Lundeen (richlundeen) merged 11 commits intoNov 3, 2026
Conversation
Add ScorerCapabilities, exposed as the final Scorer.capabilities property. It reports the declared condition with the evidence a scorer accepts (data types, roles, required metadata), so configuration and preflight code can check a scorer before acquiring evidence. Message scorers derive the evidence fields from their validator; behaviour flags stay on the validator. Add LegacyScorerHookError (a TypeError). A leaf that declares a typed CONDITION_TYPE other than MatchesObjective, but whose only reachable hook is an objective-only legacy hook, now fails at construction (or at class definition for a direct Scorer subclass) instead of at score time. Objective-based and constructor-configured legacy hooks keep working. Objective scorers declare MatchesObjective at class level instead of setting is_objective_required on their default validators, and the audio and video preflight read capabilities instead of the private validator fields. Remove the unused ambient expectation context.
Every in-repo message leaf now implements _score_piece_with_expectation_async instead of the objective-only _score_piece_async. Each one reads the objective from the expectation, so scoring behaviour is unchanged. The legacy hook stays on MessageScorer for external scorers until 2.0. Calling _score_piece_async on a scorer that only implements the typed hook now names the hook to call instead of reporting that no hook exists. Tests that called or patched the legacy hook on built-in scorers use the typed hook, and the legacy adapter tests use a test-local legacy scorer so that path stays covered. A guard test fails if an in-repo scorer adds the legacy hook again.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Derive condition and scorable coverage, keep message filters local, and preserve legacy evidence declarations. Centralize objective validation, retain configurable general float rubrics, and propagate legacy hook errors consistently. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Defer ScorerCapabilities to the scorer requirements design. Keep legacy hook errors, objective validation, MatchesObjective declarations, removal of ambient expectations, and scorable type declarations. Restore media helper validation from main. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Require every concrete in-repo leaf scorer to declare message evidence. Scorer requirements can then rely on derived scorable support without a separate evidence requirement. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> # Conflicts: # pyrit/score/true_false/gandalf_scorer.py # tests/unit/score/test_scorer_capabilities.py
Richard Lundeen (richlundeen)
left a comment
Contributor
There was a problem hiding this comment.
AI-assisted review by Copilot (trial run of a persona-based review automation). Two findings are inline. This review does not approve the PR or request changes.
Reject a legacy piece override when a migrated scorer subclass defines both hooks. Assert that typed conditions reach the dispatched scoring hook. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Both inline findings are already addressed in the selected PR head. No source changes are required by the checked plan. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Richard Lundeen (richlundeen)
enabled auto-merge
October 30, 2026 05:58
Richard Lundeen (richlundeen)
approved these changes
Oct 30, 2026
This was referenced Oct 31, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Nov 3, 2026
Keep LDAP and Markdown leaves compatible with the expectation-aware scorer contract. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the expectation-aware scorer-hook migration.
No open issues 🎉
What changed in this PR
This PR continues #3311 by moving PyRIT’s remaining in-repository message scorers to the expectation-aware piece hook while preserving scoring behavior. External subclasses of migrated scorers must also migrate their legacy overrides.
Changes:
- Replace objective-only piece hooks with expectation-aware hooks and forward expectations through superclass calls.
- Strengthen legacy-hook rejection and provide clearer guidance for unsupported direct calls.
- Update tests and scorer guidance, including guards against reintroducing legacy hooks.
| File | Description |
|---|---|
tests/unit/score/test_system_prompt_extraction_scorer.py |
Update extraction tests to call the typed hook. |
tests/unit/score/test_scorer_condition_contracts.py |
Add migration guards and objective-preservation checks. |
tests/unit/score/test_question_answer_scorer.py |
Preserve legacy-adapter coverage using a test-local scorer. |
tests/unit/score/test_package_hallucination_scorer.py |
Update package-detection tests to call the typed hook. |
tests/unit/score/test_local_violence_classifier_scorer.py |
Patch the typed hook in fallback tests. |
tests/unit/score/test_decoding_scorer.py |
Update decoding tests to call the typed hook. |
tests/unit/score/test_concurrent_scoring_lifetime.py |
Adapt concurrency mocks to forward expectations. |
tests/unit/score/test_azure_content_filter.py |
Update content-filter tests to call the typed hook. |
tests/unit/score/regex/test_regex_scorer.py |
Check LDAP and Markdown hook behavior and objective preservation. |
tests/unit/score/regex/test_credential_leak_scorer.py |
Compare credential and base regex behavior through typed hooks. |
tests/unit/scenario/core/test_group_adversarial_prompts.py |
Migrate the test policy scorer’s override and superclass call. |
tests/unit/executor/attack/test_unscored_response_outcome.py |
Patch the typed hook for empty scoring results. |
pyrit/score/true_false/wildguard_scorer.py |
Update a comment to name the typed hook; no behavior change. |
pyrit/score/true_false/substring_scorer.py |
Migrate substring scoring and extract the expectation’s objective. |
pyrit/score/true_false/regex/sql_injection_output_scorer.py |
Migrate SQL scoring and forward expectations for custom patterns. |
pyrit/score/true_false/regex/regex_scorer.py |
Migrate the shared regex scoring hook. |
pyrit/score/true_false/regex/package_hallucination_scorer.py |
Migrate package scoring while retaining objective metadata. |
pyrit/score/true_false/regex/markdown_injection.py |
Migrate Markdown injection scoring to the typed hook. |
pyrit/score/true_false/regex/ldap_injection_output_scorer.py |
Migrate LDAP scoring and superclass delegation. |
pyrit/score/true_false/regex/credential_leak_scorer.py |
Migrate credential scoring and forward complete expectations. |
pyrit/score/true_false/regex/agent_threat_rules_scorer.py |
Migrate threat-rule scoring to the typed hook. |
pyrit/score/true_false/prompt_shield_scorer.py |
Migrate Prompt Shield scoring to the typed hook. |
pyrit/score/true_false/local_refusal_classifier_scorer.py |
Migrate refusal scoring while preserving objective handling. |
pyrit/score/true_false/garak_exploitation_scorer.py |
Migrate exploitation detection to the typed hook. |
pyrit/score/true_false/decoding_scorer.py |
Migrate decoding scoring while preserving objective handling. |
pyrit/score/message_scorer.py |
Reject conflicting legacy overrides and clarify direct-call errors. |
pyrit/score/float_scale/system_prompt_extraction_scorer.py |
Migrate system-prompt extraction scoring. |
pyrit/score/float_scale/roblox_pii_scorer.py |
Migrate PII scoring and extract the expectation’s objective. |
pyrit/score/float_scale/plagiarism_scorer.py |
Adopt the typed hook while continuing to ignore scoring criteria. |
pyrit/score/float_scale/local_violence_classifier_scorer.py |
Migrate violence scoring while preserving objective handling. |
pyrit/score/float_scale/azure_content_filter_scorer.py |
Migrate Azure content-filter scoring. |
pyrit/score/conversation_scorer.py |
Rename the unused piece-hook stub to the typed hook. |
.github/instructions/scorers.instructions.md |
Document typed-hook requirements and legacy override rejection. |
Review effort: Balanced
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.
Description
Second part of phase 12 of the scorer roadmap, stacked on #3311. Every in-repo message leaf now implements the expectation-aware
_score_piece_with_expectation_asynchook instead of the objective-only_score_piece_asynchook.This branch merges the updated #3311, so it no longer contains
ScorerCapabilities. The changes specific to this PR are inb672c9d4eand the follow-up merge7800693c3. The earlier commits belong to #3311.Migrated scorers (16):
SubStringScorer,RegexScorer,CredentialLeakScorer,SQLInjectionOutputScorer,AgentThreatRulesScorer,PackageHallucinationScorer,DecodingScorer,GarakExploitationScorer,PromptShieldScorer,LocalRefusalClassifierScorer,AzureContentFilterScorer,LocalViolenceClassifierScorer,RobloxPiiScorer,PlagiarismScorer,SystemPromptExtractionScorer, and theConversationScorerstub. Scorers built on these classes, such as the keyword and regex families, inherit the change.GandalfScorerwas removed frommain, so this PR no longer migrates it.Each migrated hook reads the objective from the expectation, so scores do not change. The two regex subclasses that delegate to
RegexScorernow pass the complete expectation tosuper().The objective-only hook stays on
MessageScorerfor external scorers until 2.0. If code calls_score_piece_asyncon a scorer that implements only the typed hook, the call raisesNotImplementedErrorand names the hook to call.Breaking change
An external subclass of a migrated scorer that overrides
_score_piece_asyncnow raisesLegacyScorerHookErrorat construction, with the message "Move the custom policy to _score_piece_with_expectation_async". Before this PR, the override worked because its base scorer used the legacy hook.PyRIT does not call the old override silently or combine both hooks, because either choice can skip or repeat custom policy. To migrate, move the override and its
super()call to_score_piece_with_expectation_async, and forward the expectation. Direct calls to_score_piece_asyncon a migrated scorer also fail; call_score_piece_with_expectation_asyncinstead.Tests and Documentation
_score_piece_asyncon built-in scorers now use the typed hook with the same assertions. This includes tests thatmainadded after this PR was opened: the JavaScript, Perl, and Raku package-hallucination tests, and_PolicyScorerintest_group_adversarial_prompts.py.test_question_answer_scorer.pyuse a test-local legacy scorer, so the legacy runtime paths stay covered.tests/unit/score/test_scorer_condition_contracts.py, because FEAT Legacy scorer hook errors and explicit objective conditions (phase 12, part 1) #3311 removedtest_scorer_capabilities.py:pyrit/requiresMessageScorerto be the only class that defines_score_piece_async. The scan does not import modules, so a missing optional dependency cannot hide a scorer..github/instructions/scorers.instructions.mdsays that in-repo leaves use the typed hook. No notebook changed, so I did not run JupyText.Validation on
7800693c3:uv run --no-sync pre-commit run --all-files: all hooks passed.uv run --no-sync pytest -q -n 4 tests\unit\score tests\unit\executor\attack\test_unscored_response_outcome.py --disable-warnings: before the test fixes, 4951 passed, 7 skipped, and 10 failed. All 10 failures were package-hallucination tests frommainthat called_score_piece_async.uv run --no-sync pytest -q tests\unit\score\test_package_hallucination_scorer.py tests\unit\score\test_scorer_condition_contracts.py tests\unit\scenario\core\test_group_adversarial_prompts.py --disable-warnings: 266 passed after the test fixes.uv run --no-sync pytest -q tests\unit\score\test_scorer_condition_contracts.py --disable-warnings: 26 passed after the final lint change.uv run --no-sync pytest -q -n 4 tests\unit\executor tests\unit\scenario tests\unit\registry tests\unit\backend\test_scorer_service.py tests\unit\backend\test_chat_scoring.py tests\partner_integration\azure_ai_evaluation\test_scorer_contract.py --disable-warnings: 5210 passed and 11 failed. The failures were intest_target_objective_generator.py,test_scenario_crescendo_resume.py, andtest_crescendo_resilience.py.uv run --no-sync pytest -q tests\unit\executor\promptgen\test_target_objective_generator.py tests\unit\scenario\core\test_scenario_crescendo_resume.py --disable-warnings -p no:randomly: 56 passed on this branch and on the FEAT Legacy scorer hook errors and explicit objective conditions (phase 12, part 1) #3311 head5a94265c3.uv run --no-sync pytest -q tests\unit\executor\attack\multi_turn\test_crescendo_resilience.py --disable-warnings -p no:randomly: 9 passed on this branch and on5a94265c3.Description updated with GitHub Copilot after this branch merged the capability-free #3311.