FIX: Retry adversarial replies with non-object JSON roots#2247
Open
romanlutz wants to merge 1 commit into
Open
FIX: Retry adversarial replies with non-object JSON roots#2247romanlutz wants to merge 1 commit into
romanlutz wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cf88d9a1-35b5-4edf-8bd3-c9d5fc82c174
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes adversarial-chat JSON parsing/retry behavior by ensuring _parse_adversarial_reply treats non-object JSON roots (array/scalar/null) as InvalidJsonException, so the existing send_json_with_retry_async clean-history retry contract applies instead of aborting on an AttributeError.
Changes:
- Reject non-dict JSON roots in
_parse_adversarial_replyand include the decoded root type in the error message. - Add parser unit coverage for array/null/string/number JSON roots.
- Add a manager-level regression test verifying an array-root response is retried and a subsequent valid object succeeds.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
pyrit/executor/attack/component/adversarial_conversation_manager.py |
Adds an explicit non-object JSON-root check that raises InvalidJsonException, preserving retry semantics. |
tests/unit/executor/attack/component/test_adversarial_conversation_manager.py |
Adds unit + regression coverage to ensure non-object roots trigger InvalidJsonException and are retried successfully. |
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
Adversarial chat models can return valid JSON whose root is an array or scalar.
_parse_adversarial_replypreviously called.items()unconditionally, raisingAttributeErroroutside theInvalidJsonExceptionretry contract and aborting the attack instead of retrying on clean conversation history.This change explicitly rejects non-object JSON roots as
InvalidJsonException, including the decoded root type in the error message. It does not broadly catch exceptions or coerce malformed response shapes.Tests and Documentation
ty: passed.