pyrit.message_normalizer.ConversationContextNormalizer#

class ConversationContextNormalizer[source]#

Bases: MessageStringNormalizer

Normalizer that formats conversation history as turn-based text.

This is the standard format used by attacks like Crescendo and TAP for including conversation context in adversarial chat prompts. The output format is:

Turn 1: User: <content> Assistant: <content>

Turn 2: User: <content> …

__init__()#

Methods

__init__()

normalize_string_async(messages)

Normalize a list of messages into a turn-based context string.

async normalize_string_async(messages: List[Message]) str[source]#

Normalize a list of messages into a turn-based context string.

Parameters:

messages – The list of Message objects to normalize.

Returns:

A formatted string with turn numbers and role prefixes.

Raises:

ValueError – If the messages list is empty.