Skip to content
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

guard against None in leakreplay attempt history management #1081

Merged
merged 2 commits into from
Jan 16, 2025
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
7 changes: 4 additions & 3 deletions garak/probes/leakreplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:

def _postprocess_hook(self, attempt: Attempt) -> Attempt:
for idx, thread in enumerate(attempt.messages):
attempt.messages[idx][-1]["content"] = re.sub(
"</?name>", "", thread[-1]["content"]
)
if thread[-1]["content"] is not None:
attempt.messages[idx][-1]["content"] = re.sub(
"</?name>", "", thread[-1]["content"]
)
return attempt


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ authors = [
{ name = "Shine-afk" },
{ name = "Rafael Sandroni" },
{ name = "Eric Hacker" },
{ name = "Blessed Uyo" },
]
license = { file = "LICENSE" }
description = "LLM vulnerability scanner"
Expand Down
8 changes: 8 additions & 0 deletions tests/probes/test_probes_leakreplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import garak._plugins
import garak.attempt
import garak.cli
import garak.probes.leakreplay


def test_leakreplay_hitlog():
Expand All @@ -29,3 +30,10 @@ def test_leakreplay_output_count():
p.generator = g
results = p._execute_all([a])
assert len(a.all_outputs) == generations


def test_leakreplay_handle_incomplete_attempt():
p = garak.probes.leakreplay.LiteratureCloze80()
a = garak.attempt.Attempt(prompt="IS THIS BROKEN")
a.outputs = ["", None]
p._postprocess_hook(a)
Loading