Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pyrit/memory/azure_sql_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ def _get_attack_result_converter_classes_condition(self, *, converter_classes: S
return text(
"""("AttackResultEntries".atomic_attack_identifier IS NULL
OR JSON_QUERY("AttackResultEntries".atomic_attack_identifier,
'$.children.attack.request_converter_identifiers') IS NULL
'$.children.attack.children.request_converters') IS NULL
OR JSON_QUERY("AttackResultEntries".atomic_attack_identifier,
'$.children.attack.request_converter_identifiers') = '[]')"""
'$.children.attack.children.request_converters') = '[]')"""
)

conditions = []
Expand All @@ -439,7 +439,7 @@ def _get_attack_result_converter_classes_condition(self, *, converter_classes: S
param_name = f"conv_cls_{i}"
conditions.append(
f"""EXISTS(SELECT 1 FROM OPENJSON(JSON_QUERY("AttackResultEntries".atomic_attack_identifier,
'$.children.attack.request_converter_identifiers'))
'$.children.attack.children.request_converters'))
WHERE LOWER(JSON_VALUE(value, '$.class_name')) = :{param_name})"""
)
bindparams_dict[param_name] = cls.lower()
Expand Down Expand Up @@ -473,8 +473,8 @@ def get_unique_attack_class_names(self) -> list[str]:
def get_unique_converter_class_names(self) -> list[str]:
"""
Azure SQL implementation: extract unique converter class_name values
from the request_converter_identifiers array in the atomic_attack_identifier
JSON column.
from the children.attack.children.request_converters array
in the atomic_attack_identifier JSON column.

Returns:
Sorted list of unique converter class name strings.
Expand All @@ -485,7 +485,7 @@ def get_unique_converter_class_names(self) -> list[str]:
"""SELECT DISTINCT JSON_VALUE(c.value, '$.class_name') AS cls
FROM "AttackResultEntries"
CROSS APPLY OPENJSON(JSON_QUERY(atomic_attack_identifier,
'$.children.attack.request_converter_identifiers')) AS c
'$.children.attack.children.request_converters')) AS c
WHERE ISJSON(atomic_attack_identifier) = 1
AND JSON_VALUE(c.value, '$.class_name') IS NOT NULL"""
)
Expand Down
12 changes: 6 additions & 6 deletions pyrit/memory/sqlite_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def _get_attack_result_converter_classes_condition(self, *, converter_classes: S
Uses json_extract() on the atomic_attack_identifier JSON column.

When converter_classes is empty, matches attacks with no converters
(request_converter_identifiers is absent or null in the JSON).
(children.attack.children.request_converters is absent or null in the JSON).
When non-empty, uses json_each() to check all specified classes are present
(AND logic, case-insensitive).

Expand All @@ -540,7 +540,7 @@ def _get_attack_result_converter_classes_condition(self, *, converter_classes: S
# is absent, null, or empty in the stored JSON.
converter_json = func.json_extract(
AttackResultEntry.atomic_attack_identifier,
"$.children.attack.request_converter_identifiers",
"$.children.attack.children.request_converters",
)
return or_(
AttackResultEntry.atomic_attack_identifier.is_(None),
Expand All @@ -555,7 +555,7 @@ def _get_attack_result_converter_classes_condition(self, *, converter_classes: S
text(
f"""EXISTS(SELECT 1 FROM json_each(
json_extract("AttackResultEntries".atomic_attack_identifier,
'$.children.attack.request_converter_identifiers'))
'$.children.attack.children.request_converters'))
WHERE LOWER(json_extract(value, '$.class_name')) = :{param_name})"""
).bindparams(**{param_name: cls.lower()})
)
Expand All @@ -579,8 +579,8 @@ def get_unique_attack_class_names(self) -> list[str]:
def get_unique_converter_class_names(self) -> list[str]:
"""
SQLite implementation: extract unique converter class_name values
from the request_converter_identifiers array in the atomic_attack_identifier
JSON column.
from the children.attack.children.request_converters array in the
atomic_attack_identifier JSON column.

Returns:
Sorted list of unique converter class name strings.
Expand All @@ -592,7 +592,7 @@ def get_unique_converter_class_names(self) -> list[str]:
FROM "AttackResultEntries",
json_each(
json_extract("AttackResultEntries".atomic_attack_identifier,
'$.children.attack.request_converter_identifiers')
'$.children.attack.children.request_converters')
) AS j
WHERE cls IS NOT NULL"""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1131,13 +1131,13 @@ def _make_attack_result_with_identifier(
converter_class_names: Optional[list[str]] = None,
) -> AttackResult:
"""Helper to create an AttackResult with a ComponentIdentifier containing converters."""
params = {}
children: dict = {}
if converter_class_names is not None:
params["request_converter_identifiers"] = [
children["request_converters"] = [
ComponentIdentifier(
class_name=name,
class_module="pyrit.converters",
).to_dict()
class_module="pyrit.prompt_converter",
)
for name in converter_class_names
]

Expand All @@ -1148,7 +1148,7 @@ def _make_attack_result_with_identifier(
attack_identifier=ComponentIdentifier(
class_name=class_name,
class_module="pyrit.attacks",
params=params,
children=children,
),
),
)
Expand Down
Loading