Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

pyrit.executor.promptgen

Prompt generator strategy imports.

AnecdoctorContext

Bases: PromptGeneratorStrategyContext

Context specific to Anecdoctor prompt generation.

Contains all parameters needed for executing Anecdoctor prompt generation, including the evaluation data, language settings, and conversation ID.

AnecdoctorGenerator

Bases: PromptGeneratorStrategy[AnecdoctorContext, AnecdoctorResult], Identifiable

Implementation of the Anecdoctor prompt generation strategy.

The Anecdoctor generator creates misinformation content by either:

  1. Using few-shot examples directly (default mode when processing_model is not provided)

  2. First extracting a knowledge graph from examples, then using it (when processing_model is provided)

This generator is designed to test a model’s susceptibility to generating false or misleading content when provided with examples in ClaimsReview format. The generator can optionally use a processing model to extract a knowledge graph representation of the examples before generating the final content.

The generation flow consists of:

  1. (Optional) Extract knowledge graph from evaluation data using processing model

  2. Format a system prompt based on language and content type

  3. Send formatted examples (or knowledge graph) to target model

  4. Return the generated content as the result

Constructor Parameters:

ParameterTypeDescription
objective_targetPromptChatTargetThe chat model to be used for prompt generation.
processing_modelOptional[PromptChatTarget]The model used for knowledge graph extraction. If provided, the generator will extract a knowledge graph from the examples before generation. If None, the generator will use few-shot examples directly. Defaults to None.
converter_configOptional[StrategyConverterConfig]Configuration for prompt converters. Defaults to None.
prompt_normalizerOptional[PromptNormalizer]Normalizer for handling prompts. Defaults to None.

Methods:

execute_async

execute_async(kwargs: Any = {}) → AnecdoctorResult

Execute the prompt generation strategy asynchronously with the provided parameters.

ParameterTypeDescription
content_typestrThe type of content to generate (e.g., “viral tweet”, “news article”).
languagestrThe language of the content to generate (e.g., “english”, “spanish”).
evaluation_dataList[str]The data in ClaimsReview format to use in constructing the prompt.
memory_labelsOptional[Dict[str, str]]Memory labels for the generation context.
**kwargsAnyAdditional parameters for the generation. Defaults to {}.

Returns:

AnecdoctorResult

Bases: PromptGeneratorStrategyResult

Result of Anecdoctor prompt generation.

Contains the generated content from the misinformation prompt generation.

PromptGeneratorStrategy

Bases: Strategy[PromptGeneratorStrategyContextT, PromptGeneratorStrategyResultT], ABC

Base class for all prompt generator strategies. Provides a structure for implementing specific prompt generation strategies.

Constructor Parameters:

ParameterTypeDescription
context_typetypeType of the context used by the strategy.
loggerlogging.LoggerLogger instance for logging events. Defaults to logger.
event_handlerStrategyEventHandlerEvent handler for handling strategy events. Defaults to None.

PromptGeneratorStrategyContext

Bases: StrategyContext, ABC

Base class for all prompt generator strategy contexts.

PromptGeneratorStrategyResult

Bases: StrategyResult, ABC

Base class for all prompt generator strategy results.