pyrit.prompt_target.PromptChatTarget#

class PromptChatTarget(*, max_requests_per_minute: int | None = None, endpoint: str = '', model_name: str = '', underlying_model: str | None = None)[source]#

Bases: PromptTarget

A prompt chat target is a target where you can explicitly set the conversation history using memory.

Some algorithms require conversation to be modified (e.g. deleting the last message) or set explicitly. These algorithms will require PromptChatTargets be used.

As a concrete example, OpenAI chat targets are PromptChatTargets. You can set made-up conversation history. Realtime chat targets or OpenAI completions are NOT PromptChatTargets. You don’t send the conversation history.

__init__(*, max_requests_per_minute: int | None = None, endpoint: str = '', model_name: str = '', underlying_model: str | None = None) None[source]#

Initialize the PromptChatTarget.

Parameters:
  • max_requests_per_minute (int, Optional) – Maximum number of requests per minute.

  • endpoint (str) – The endpoint URL. Defaults to empty string.

  • model_name (str) – The model name. Defaults to empty string.

  • underlying_model (str, Optional) – The underlying model name (e.g., “gpt-4o”) for identification purposes. This is useful when the deployment name in Azure differs from the actual model. Defaults to None.

Methods

__init__(*[, max_requests_per_minute, ...])

Initialize the PromptChatTarget.

dispose_db_engine()

Dispose database engine to release database connections and resources.

get_identifier()

Get an identifier dictionary for this prompt target.

is_json_response_supported()

Abstract method to determine if JSON response format is supported by the target.

is_response_format_json(message_piece)

Check if the response format is JSON and ensure the target supports it.

send_prompt_async(*, message)

Send a normalized prompt async to the prompt target.

set_model_name(*, model_name)

Set the model name for this target.

set_system_prompt(*, system_prompt, ...[, ...])

Set the system prompt for the prompt target.

Attributes

supported_converters

A list of PromptConverters that are supported by the prompt target.

abstract is_json_response_supported() bool[source]#

Abstract method to determine if JSON response format is supported by the target.

Returns:

True if JSON response is supported, False otherwise.

Return type:

bool

is_response_format_json(message_piece: MessagePiece) bool[source]#

Check if the response format is JSON and ensure the target supports it.

Parameters:

message_piece – A MessagePiece object with a prompt_metadata dictionary that may include a “response_format” key.

Returns:

True if the response format is JSON, False otherwise.

Return type:

bool

Raises:

ValueError – If “json” response format is requested but unsupported.

set_system_prompt(*, system_prompt: str, conversation_id: str, attack_identifier: dict[str, str] | None = None, labels: dict[str, str] | None = None) None[source]#

Set the system prompt for the prompt target. May be overridden by subclasses.

Raises:

RuntimeError – If the conversation already exists.

supported_converters: list#

A list of PromptConverters that are supported by the prompt target. An empty list implies that the prompt target supports all converters.