Repository navigation
FIX: Report adversarial chat refusals inside the JSON reply as refusals - #4827
Open
Behnam (behnam-o) wants to merge 1 commit into
Open
Behnam (behnam-o) wants to merge 1 commit into
Behnam (behnam-o) wants to merge 1 commit into
Conversation
An adversarial chat that declines an objective can return valid JSON with a blank next_message and its reason in rationale. The shared parser treated that as invalid JSON, so the turn was retried up to RETRY_MAX_NUM_ATTEMPTS times and the objective ended in an InvalidJsonException error. - Raise AdversarialChatRefusedException for a blank or null next_message with a rationale; a blank reply without one is still invalid JSON. - Retry refusals in pyrit_json_retry only within the first three attempts, and record refusal rollbacks with their own ConversationRetryReason. - End Crescendo UNDETERMINED / adversarial_chat_refused like Red Teaming, and let TAP and PAIR prune refused branches instead of reporting a JSON or execution error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Active issues can cause Red Teaming to mark an untested objective complete and Crescendo to return a response mismatched with its score and trimmed conversation.
2 open issues
What changed in this PR
This PR distinguishes adversarial-chat refusals from malformed JSON, preserving refusal outcomes across PyRIT’s attack workflows.
Changes:
- Recognizes blank or null replies with a rationale as refusals.
- Limits refusal retries and records their rollback reason.
- Updates attack outcomes, regression coverage, and resiliency documentation.
| File | Description |
|---|---|
| tests/unit/prompt_normalizer/test_json_retry.py | Tests refusal retries and rollback reasons. |
| tests/unit/executor/attack/multi_turn/test_tree_of_attacks.py | Tests refused branches and outcome precedence. |
| tests/unit/executor/attack/multi_turn/test_crescendo_resilience.py | Tests truncation and preparation failures. |
| tests/unit/executor/attack/multi_turn/test_adversarial_chat_refusal.py | Adds cross-attack refusal regressions. |
| tests/unit/executor/attack/component/test_adversarial_conversation_manager.py | Tests refusal parsing and retry behavior. |
| tests/unit/exceptions/test_exceptions.py | Tests refusal retry limits. |
| pyrit/prompt_normalizer/json_retry.py | Tracks refusal-specific rollback reasons. |
| pyrit/models/messages/conversation_retry.py | Adds the refusal retry reason. |
| pyrit/executor/attack/multi_turn/tree_of_attacks.py | Prunes refused branches and classifies outcomes. |
| pyrit/executor/attack/multi_turn/simulated_conversation.py | Clarifies refusal retries in documentation. |
| pyrit/executor/attack/multi_turn/crescendo.py | Handles refusals as preparation failures or truncation. |
| pyrit/executor/attack/component/adversarial_conversation_manager.py | Recognizes refusals inside JSON replies. |
| pyrit/exceptions/exception_classes.py | Adds bounded refusal retries. |
| doc/code/setup/2_resiliency.py | Documents refusal retry behavior. |
| doc/code/setup/2_resiliency.ipynb | Mirrors the resiliency documentation update. |
Review effort: Balanced
Comment on lines
+372
to
+373
| if isinstance(rationale, str) and rationale.strip(): | ||
| raise AdversarialChatRefusedException(message=rationale) |
Comment on lines
+528
to
+529
| if context.last_response is not None: | ||
| return self._create_attack_result( |
Behnam (behnam-o)
marked this pull request as ready for review
December 4, 2026 00:07
This branch has not been deployed
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
An adversarial chat that declines an objective can reply with valid JSON whose
next_messageis empty and whoserationaleexplains the refusal. The shared adversarial-reply parser treated that as malformed JSON: it retried the turn up toRETRY_MAX_NUM_ATTEMPTStimes and then errored the objective withInvalidJsonException, instead of recording an adversarial-chat refusal the way it already does for provider-flagged refusals (#2443, #2551, #2918)._parse_adversarial_replyis shared by Red Teaming, Crescendo, TAP, PAIR, and simulated conversations. It now raisesAdversarialChatRefusedExceptionwith the rationale whennext_messageis blank or null andrationaleis set. A blank reply with no explanation is stillInvalidJsonException, as introduced in MAINT: Improving JSON parsing logic to raise JSONException on empty required strings #2567.pyrit_json_retryretries a refusal on a clean history only within the first three attempts, because a model sometimes complies on a fresh attempt. Provider-flagged refusals, which previously got a single attempt, follow the same rule. Rolled-back turns are recorded withConversationRetryReason.REFUSAL.adversarial_chat_refused, like Red Teaming. If the objective target was already reached, it ends as a truncated run instead. TAP and PAIR prune a refused branch instead of logging a JSON or execution error, and end UNDETERMINED withadversarial_chat_refusedwhen no branch reached the objective target.InvalidJsonException's status 500, so they stop showing up as server errors in the GUI's overload summary.Before / after. The adversarial chat always replies
{"next_message": "", "rationale": "I won't write an attack prompt for this objective.", "last_response_summary": ""}, withRETRY_MAX_NUM_ATTEMPTSat its default of 10. The objective target is never called in any of these runs.InvalidJsonException, 10 retry events with status 500adversarial_chat_refusedwith the rationale, 3 retry events with status 400adversarial_chat_refused, 6 retry events with status 400🤖 Generated with Claude Code