pyrit.prompt_target.PromptTarget#

class PromptTarget(verbose: bool = False, max_requests_per_minute: int | None = None, endpoint: str = '', model_name: str = '', underlying_model: str | None = None, capabilities: TargetCapabilities | None = None)[source]#

Bases: Identifiable

Abstract base class for prompt targets.

A prompt target is a destination where prompts can be sent to interact with various services, models, or APIs. This class defines the interface that all prompt targets must implement.

__init__(verbose: bool = False, max_requests_per_minute: int | None = None, endpoint: str = '', model_name: str = '', underlying_model: str | None = None, capabilities: TargetCapabilities | None = None) None[source]#

Initialize the PromptTarget.

Parameters:
  • verbose (bool) – Enable verbose logging. Defaults to False.

  • 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. If not provided, model_name will be used for the identifier. Defaults to None.

  • capabilities (TargetCapabilities, Optional) – Override the default capabilities for this target instance. Useful for targets whose capabilities depend on deployment configuration (e.g., Playwright, HTTP). If None, uses the class-level _DEFAULT_CAPABILITIES. Defaults to None.

Methods

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

Initialize the PromptTarget.

dispose_db_engine()

Dispose database engine to release database connections and resources.

get_identifier()

Get the component's identifier, building it lazily on first access.

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.

Attributes

capabilities

The capabilities of this target instance.

supports_multi_turn

Whether this target supports multi-turn conversations.

supported_converters

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

property capabilities: TargetCapabilities#

The capabilities of this target instance.

Defaults to the class-level _DEFAULT_CAPABILITIES. Can be overridden per instance via the capabilities constructor parameter, which is useful for targets whose capabilities depend on deployment configuration (e.g., Playwright, HTTP).

Returns:

The capabilities for this target.

Return type:

TargetCapabilities

dispose_db_engine() None[source]#

Dispose database engine to release database connections and resources.

abstract async send_prompt_async(*, message: Message) list[Message][source]#

Send a normalized prompt async to the prompt target.

Returns:

A list of message responses. Most targets return a single message,

but some (like response target with tool calls) may return multiple messages.

Return type:

list[Message]

set_model_name(*, model_name: str) None[source]#

Set the model name for this target.

Parameters:

model_name (str) – The model name to set.

supported_converters: list[Any]#

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

property supports_multi_turn: bool#

Whether this target supports multi-turn conversations.

Convenience property that delegates to self.capabilities.supports_multi_turn.

Returns:

False by default. Subclasses declare multi-turn support by setting

_DEFAULT_CAPABILITIES or passing capabilities to the constructor.

Return type:

bool