Skip to content

FIX: Include ordered parameter names in TemplateSegmentConverter identifier (#3902) - #3907

Closed
Hrushikesh Ramilla (Hrushikesh-ramilla) wants to merge 2 commits into
microsoft:mainfrom
Hrushikesh-ramilla:fix/template-segment-converter-parameter-order-identity-3902
Closed

Hrushikesh Ramilla (Hrushikesh-ramilla) wants to merge 2 commits into
microsoft:mainfrom
Hrushikesh-ramilla:fix/template-segment-converter-parameter-order-identity-3902

Conversation

@Hrushikesh-ramilla

Copy link
Copy Markdown
Contributor

Description

Fixes #3902.

TemplateSegmentConverter binds prompt segments to template parameters using the ordered SeedPrompt.parameters list. When parameters are reordered, the rendered output changes, but _build_identifier() previously only included the template hash, parameter count, and seed. As a result, configurations with different parameter orderings shared the same identifier hash and default registry name, causing automatic registration collisions.

This change:

  • Includes "parameters": list(self.prompt_template.parameters or []) in _build_identifier() so differing parameter orderings produce distinct identifier hashes and registry names.
  • Documents the identifier behavior in TemplateSegmentConverter.
  • Adds unit tests verifying that ordered parameter names are included in the identifier, that reordered parameters produce distinct hashes, and that both instances can coexist in ConverterRegistry.

Tests

  • Added unit tests in tests/unit/converter/test_template_segment_converter.py.
  • Ran unit tests: all 14 tests in test_template_segment_converter.py pass cleanly.
  • Formatted and validated with Ruff.

…tifier (microsoft#3902)

TemplateSegmentConverter assigns prompt segments based on the ordered parameters list in SeedPrompt. Include the ordered parameter names in the converter's identifier params so that differing parameter orderings produce distinct identifier hashes and default registry names, avoiding registration collisions.

Signed-off-by: Hrushikesh Ramilla <ramillahrushikesh@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 4, 2026 05:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new coroutine lacks the _async suffix required by the repository’s async-function naming convention.

1 open issue
What changed in this PR

Fixes #3902 by including ordered template parameter names in TemplateSegmentConverter identity, preventing registry-name collisions between converters with different segment bindings.

Changes:

  • Adds ordered parameter names to identifier generation without changing rendering behavior.
  • Documents how parameter ordering affects identifiers and registry names.
  • Adds regression tests for identifier contents, distinct hashes, and registry coexistence.
File Description
tests/​unit/​converter/​test_template_segment_converter.py Adds identifier and registry regression tests.
pyrit/​converter/​template_segment_converter.py Includes ordered parameters in identity and documents the behavior.

Review effort: Balanced

assert second.get_identifier().params["parameters"] == ["right", "left"]


async def test_template_segment_converter_reordered_parameters_coexist_in_registry():
…routine

Signed-off-by: Hrushikesh Ramilla <ramillahrushikesh@gmail.com>
@romanlutz

Copy link
Copy Markdown
Contributor

duplicate of #3905

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: TemplateSegmentConverter omits ordered parameter bindings from identity

3 participants