Skip to content

Preserve user message structure in generic system squash#1505

Open
biefan wants to merge 1 commit intoAzure:mainfrom
biefan:preserve-multipart-generic-system-squash
Open

Preserve user message structure in generic system squash#1505
biefan wants to merge 1 commit intoAzure:mainfrom
biefan:preserve-multipart-generic-system-squash

Conversation

@biefan
Copy link
Contributor

@biefan biefan commented Mar 17, 2026

Summary

  • squash the first system message into the first user message instead of rewriting whichever message happens to come second
  • preserve multipart user messages when squashing system instructions into user content
  • add regression coverage for assistant-before-user conversations and multipart user messages

Problem

GenericSystemSquashNormalizer currently assumes messages[1] is the user message and rebuilds it with Message.from_prompt(). That causes two issues:

  • assistant messages that appear before the first user message get rewritten as user
  • multipart user messages lose non-text pieces when the normalizer collapses them into a single text prompt

Validation

  • .venv/bin/pytest tests/unit/message_normalizer -q
  • .venv/bin/ruff check pyrit/message_normalizer/generic_system_squash.py tests/unit/message_normalizer/test_generic_system_squash_normalizer.py

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.

1 participant