BUG: LLMGenericTextConverter identifier changes between processes for set-valued template parameters

Open Beginner friendly
#3,841 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
ai

Research direction

Start in _describe_template_value in llm_generic_text_converter.py, around line 67, where set and frozenset values are handled like lists. Run the reproduction script twice with PYTHONHASHSEED set to 1 and to 2 and compare the identifier output. Done when the identifier matches across seeds and template rendering is unchanged, as the issue asks.

Written by the indexing model from the issue text.

Description

Bug: triage
Describe the bug

_describe_template_value handles set and frozenset like a list (llm_generic_text_converter.py:67), so the identifier follows set iteration order. That order depends on PYTHONHASHSEED, so the same configuration gets a different hash in each process.

Steps/Code to Reproduce

Run on main at 5fb4fb977, once with PYTHONHASHSEED=1 and once with PYTHONHASHSEED=2.

import asyncio

from pyrit.converter import LLMGenericTextConverter
from pyrit.models import SeedPrompt
from pyrit.prompt_target import OpenAIChatTarget
from pyrit.setup import IN_MEMORY, initialize_pyrit_async


async def main() -> None:
    await initialize_pyrit_async(memory_db_type=IN_MEMORY, silent=True)
    target = OpenAIChatTarget(endpoint="https://example.invalid/v1", api_key="unused", model_name="model-a")
    converter = LLMGenericTextConverter(
        converter_target=target,
        system_prompt_template=SeedPrompt(value="Use one of these tones: {{ tone }}", parameters=["tone"]),
        tone={"alpha", "beta", "gamma", "delta", "epsilon", "zeta"},
    )
    print(converter.get_identifier().unique_name)


asyncio.run(main())
Expected Results

The same identifier in both runs.

Actual Results
PYTHONHASHSEED=1  LLMGenericTextConverter::34b80fa1
PYTHONHASHSEED=2  LLMGenericTextConverter::9136bd54
Versions
  • OS: Windows 11
  • Python version: 3.12.0
  • PyRIT version: source checkout of main at 5fb4fb977
System:
    python: 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)]
executable: C:\dev\pyr-main\Scripts\python.exe
   machine: Windows-11-10.0.26300-SP0

Python dependencies:
        pyrit: 1.2.0.dev0
       Cython: None
        numpy: 2.4.6
       openai: 2.54.0
    packaging: 26.3
          pip: 23.2.1
        scipy: 1.17.1
   setuptools: 84.2.1
      sqlite3: None
        torch: None
 transformers: 5.20.2

The rendered prompt moves too when a template prints the set: {{ tone }} gives a different order under each seed. Sorting inside _describe_template_value fixes the identifier. Rendering is a separate call: leave it, or reject sets as template parameters.

Dominant language
Python
Stars
4.7k
Forks
1k
Avg merge
2d 3h
Merged PRs (30d)
450

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/PyRIT

All issues in microsoft/PyRIT

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.