-
Notifications
You must be signed in to change notification settings - Fork 745
MAINT: Add labels to attack results #1624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
behnam-o
wants to merge
11
commits into
microsoft:main
Choose a base branch
from
behnam-o:users/behnam/attack-result-labels
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b63361c
Add labels to attack results
e8164aa
Merge branch 'main' into users/behnam/attack-result-labels
4ec494a
format
5e04ca7
label queries OR'ed with old way
fa5a0d7
review feedback
aafefc1
format
fca41cb
cc
5f179e6
fix doc dot
behnam-o 21e9744
merge main
451d06d
fix condition
8e6ed56
OR query for PME labels
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
35 changes: 35 additions & 0 deletions
35
pyrit/memory/alembic/versions/108a72344872_add_labels_to_attack_results.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT license. | ||
|
|
||
| """ | ||
| add labels to Attack Results. | ||
|
|
||
| Revision ID: 108a72344872 | ||
| Revises: e373726d391b | ||
| Create Date: 2026-04-27 13:47:20.711347 | ||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "108a72344872" | ||
| down_revision: str | None = "e373726d391b" | ||
| branch_labels: str | Sequence[str] | None = None | ||
| depends_on: str | Sequence[str] | None = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Apply this schema upgrade.""" | ||
| # ### commands auto generated by Alembic and reviewed by author ### | ||
| op.add_column("AttackResultEntries", sa.Column("labels", sa.JSON(), nullable=True)) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| """Revert this schema upgrade.""" | ||
| # ### commands auto generated by Alembic and reviewed by author ### | ||
| op.drop_column("AttackResultEntries", "labels") | ||
| # ### end Alembic commands ### |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -697,6 +697,7 @@ class AttackResultEntry(Base): | |
| outcome (AttackOutcome): The outcome of the attack, indicating success, failure, or undetermined. | ||
| outcome_reason (str): Optional reason for the outcome, providing additional context. | ||
| attack_metadata (dict[str, Any]): Metadata can be included as key-value pairs to provide extra context. | ||
| labels (dict[str, str]): Optional labels associated with the attack result entry. | ||
| pruned_conversation_ids (List[str]): List of conversation IDs that were pruned from the attack. | ||
| adversarial_chat_conversation_ids (List[str]): List of conversation IDs used for adversarial chat. | ||
| timestamp (DateTime): The timestamp of the attack result entry. | ||
|
|
@@ -728,6 +729,7 @@ class AttackResultEntry(Base): | |
| ) | ||
| outcome_reason = mapped_column(String, nullable=True) | ||
| attack_metadata: Mapped[dict[str, Union[str, int, float, bool]]] = mapped_column(JSON, nullable=True) | ||
| labels: Mapped[dict[str, str]] = mapped_column(JSON, nullable=True) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for adding on AR and NOT removing them from MP? |
||
| pruned_conversation_ids: Mapped[Optional[list[str]]] = mapped_column(JSON, nullable=True) | ||
| adversarial_chat_conversation_ids: Mapped[Optional[list[str]]] = mapped_column(JSON, nullable=True) | ||
| timestamp = mapped_column(DateTime, nullable=False) | ||
|
|
@@ -783,6 +785,7 @@ def __init__(self, *, entry: AttackResult): | |
| self.outcome = entry.outcome.value | ||
| self.outcome_reason = entry.outcome_reason | ||
| self.attack_metadata = self.filter_json_serializable_metadata(entry.metadata) | ||
| self.labels = entry.labels or {} | ||
|
|
||
| # Persist conversation references by type | ||
| self.pruned_conversation_ids = [ | ||
|
|
@@ -894,6 +897,7 @@ def get_attack_result(self) -> AttackResult: | |
| outcome_reason=self.outcome_reason, | ||
| related_conversations=related_conversations, | ||
| metadata=self.attack_metadata or {}, | ||
| labels=self.labels or {}, | ||
| ) | ||
|
|
||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confused about this comment. Aren't attack-result labels conversation-level?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
today, the lables on "attack summary" (a GUI-related concept) come from "conversation stats" (another GUI-related concept) ... conversation stats are an aggregation of message pieces, along with their labels, which in turn end up on the attack summary.
This change here is saying "attack summary's labels must come not only from conversation stats (i.e. message pieces) but also from attack resutls" ...
Once we remove labels from message_piece , this will also be removed and the only kind of label that ends up on attack summary will be the attack result ones.
this is making me think, also related to the other comment, maybe it's just a good idea to do both at the same time, instead of having an overlap period where both objects ,attack results and message pieces, have labels) - it will avoid confusions like this - I think I'll do this, after introducing a DB migration solution in #1631