pyrit.prompt_converter.PersuasionConverter#
- class PersuasionConverter(*, converter_target: PromptChatTarget = REQUIRED_VALUE, persuasion_technique: str)[source]#
Bases:
PromptConverterRephrases prompts using a variety of persuasion techniques.
Based on https://arxiv.org/abs/2401.06373 by Zeng et al.
- Supported persuasion techniques:
- “authority_endorsement”:
Citing authoritative sources in support of a claim.
- “evidence_based”:
Using empirical data, statistics, and facts to support a claim or decision.
- “expert_endorsement”:
Citing domain experts in support of a claim.
- “logical_appeal”:
Using logic or reasoning to support a claim.
- “misrepresentation”:
Presenting oneself or an issue in a way that’s not genuine or true.
- __init__(*, converter_target: PromptChatTarget = REQUIRED_VALUE, persuasion_technique: str)[source]#
Initialize the converter with the specified target and prompt template.
- Parameters:
converter_target (PromptChatTarget) – The chat target used to perform rewriting on user prompts. Can be omitted if a default has been configured via PyRIT initialization.
persuasion_technique (str) – Persuasion technique to be used by the converter, determines the system prompt to be used to generate new prompts. Must be one of “authority_endorsement”, “evidence_based”, “expert_endorsement”, “logical_appeal”, “misrepresentation”.
- Raises:
ValueError – If converter_target is not provided and no default has been configured.
ValueError – If the persuasion technique is not supported or does not exist.
Methods
__init__(*[, converter_target])Initialize the converter with the specified target and prompt template.
convert_async(*, prompt[, input_type])Convert the given prompt using the persuasion technique specified during initialization.
convert_tokens_async(*, prompt[, ...])Convert substrings within a prompt that are enclosed by specified start and end tokens.
get_identifier()Return an identifier dictionary for the converter.
input_supported(input_type)Check if the input type is supported by the converter.
output_supported(output_type)Check if the output type is supported by the converter.
send_persuasion_prompt_async(request)Send the prompt to the converter target and process the response.
Attributes
Tuple of input modalities supported by this converter.
Tuple of output modalities supported by this converter.
supported_input_typesReturns a list of supported input types for the converter.
supported_output_typesReturns a list of supported output types for the converter.
- SUPPORTED_INPUT_TYPES: tuple[Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'], ...] = ('text',)#
Tuple of input modalities supported by this converter. Subclasses must override this.
- SUPPORTED_OUTPUT_TYPES: tuple[Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'], ...] = ('text',)#
Tuple of output modalities supported by this converter. Subclasses must override this.
- async convert_async(*, prompt: str, input_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] = 'text') ConverterResult[source]#
Convert the given prompt using the persuasion technique specified during initialization.
- Parameters:
prompt (str) – The input prompt to be converted.
input_type (PromptDataType) – The type of input data.
- Returns:
The result containing the converted prompt text.
- Return type:
- Raises:
ValueError – If the input type is not supported.
- async send_persuasion_prompt_async(request: Message) str[source]#
Send the prompt to the converter target and process the response.
- Parameters:
request (Message) – The message containing the prompt to be converted.
- Returns:
The converted prompt text extracted from the response.
- Return type:
- Raises:
InvalidJsonException – If the response is not valid JSON or missing expected keys.