Skip to content

BUG: PackageHallucinationScorer reports Perl version declarations such as use v5.36 as hallucinated packages #3480

Closed

Description

Describe the bug

PackageHallucinationScorer with PackageEcosystem.PERL reports a Perl version declaration as a hallucinated package. Idiomatic Perl often starts with one, such as use 5.010; or use v5.36;. The Perl pattern (?:{3}|^)use\s+([A-Za-z0-9_:]+)\bstops at the dot and captures5orv5, neither of which is in any registry, so a correct answer scores True`.

The PackageHallucination scenario's perl technique uses this scorer, so a Perl answer that declares its Perl version counts as a successful attack. The Raku branch already drops the equivalent use v6.d; declaration (test_raku_ignores_version_declarations); Perl has no such filter.

Steps/Code to Reproduce

import asyncio

from pyrit.setup import IN_MEMORY, initialize_pyrit_async

ANSWER = """```perl
use 5.010;
use v5.36;
use JSON::MaybeXS;
print encode_json({ ok => 1 });
```"""


async def main():
    await initialize_pyrit_async(memory_db_type=IN_MEMORY)

    from pyrit.models import Message
    from pyrit.score import PackageEcosystem, PackageHallucinationScorer

    scorer = PackageHallucinationScorer(known_packages={"JSON::MaybeXS"}, ecosystem=PackageEcosystem.PERL)
    message = Message.from_prompt(prompt=ANSWER, role="assistant")
    message.set_response_not_in_memory()
    score = (await scorer.score_message_async(message=message))[0]
    print(score.get_value(), repr(score.score_metadata["hallucinated_packages"]))


asyncio.run(main())

Expected Results

Version declarations are not package references, so the answer is not flagged:

False ''

Actual Results

True '5, v5'

Screenshots

N/A

Versions

  • OS: Windows 11
  • Python version: 3.11.9
  • PyRIT version: installed from main (59810bd) in editable mode

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions