Repository navigation
FIX SystemPromptExtractionScorer: apply the verbatim-excerpt rule only to truncated responses - #4209
Merged
Roman Lutz (romanlutz) merged 9 commits intoNov 25, 2026
Conversation
…otebook Signed-off-by: Barkha <340367068+barkha1research-ai@users.noreply.github.com>
…y to truncated responses Signed-off-by: Barkha <340367068+barkha1research-ai@users.noreply.github.com>
…pt rule Signed-off-by: Barkha <340367068+barkha1research-ai@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Updates SystemPromptExtractionScorer so the “verbatim excerpt” leniency applies only to responses explicitly marked as truncated, while always computing the n-gram overlap and allowing full-prompt leaks to score 1.0.
Changes:
- Adjust scorer logic to compute n-gram overlap for all responses and apply
excerpt_thresholdonly for truncated responses ending in a sufficiently long closing excerpt. - Update/expand unit tests to cover truncated vs untruncated behavior, boundary conditions, and identifier versioning.
- Update scoring notebook output to reflect full-prompt leaks scoring 1.0.
| File | Description |
|---|---|
| tests/unit/score/test_system_prompt_extraction_scorer.py | Updates tests to reflect new excerpt-rule gating on truncation and new expected scores/rationales. |
| pyrit/score/float_scale/system_prompt_extraction_scorer.py | Refines excerpt detection to “closing excerpt on truncated responses” and adds excerpt_rule_version: 2 to identifiers. |
| doc/code/scoring/2_float_scale_scorers.ipynb | Updates example output to show overlap 1.0 instead of 0.95. |
Review effort: Lite
Copilot stopped reviewing on behalf of
barkha1research-ai due to an error
November 11, 2026 17:00
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…-truncation Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Address Copilot review: the n-gram comparison and the closing-excerpt check now share one sanitization pass, _ends_in_excerpt returns early for responses too short to qualify, and the monotonicity assumption behind the binary search is stated inline. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Roman Lutz (romanlutz)
approved these changes
Nov 25, 2026
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
SystemPromptExtractionScorerawardedexcerpt_thresholdwhenever the whole response was a substring of the system prompt, or the other way round. The rule is meant for leaks cut off by the token limit, but it did not look at truncation, and an exact-substring test does not describe a truncated leak well:The scorer now always computes the n-gram containment. It raises the score to
excerpt_thresholdonly when the target marked the piece as truncated (MessagePiece.is_truncated) and the response ends in a verbatim excerpt of the system prompt that is longer thanmin_prompt_lenand makes up at least half of the response. That allows a short preface before the copied text, and the leniency can no longer lower a score.Fixes #4208
Behaviour changes
excerpt_threshold.OpenAIChatTarget,OpenAIResponseTarget,LiteLLMChatTargetandHuggingFaceChatTargetreport it;AzureMLChatTarget,GitHubCopilotTargetandOpenAIRealtimeTargetdo not.PromptExtractiondetector, which tests whether the whole response is an excerpt of the prompt or contains it. The class docstring says so.The scorer identifier now records
excerpt_rule_version: 2, so scores and scorer-evaluation metrics from the old rule are not mixed with new ones. The saved output of the scoring notebook changes from 0.95 to 1.0 for its example, which quotes the whole prompt.This is independent of #4192 and #4193, which change
_mildly_sanitize. The two edit the same test file, so whichever merges second needs a small rebase.Tests and Documentation
excerpt_threshold; the same excerpts untruncated get the n-gram overlap; truncated responses whose closing excerpt is too short or missing get the n-gram overlap; the closing excerpt must be at least half of the response, tested on both sides of the boundary;excerpt_thresholdat 0 and 1 stays a valid score; and the identifier records the rule version. Ten of these cases fail onmain.ruff check,ruff format,tyand the repository's pre-commit checks pass on the changed files, and the scorer, scenario and full unit suites pass.