pyrit.models.PromptRequestResponse#

class PromptRequestResponse(request_pieces: Sequence[PromptRequestPiece], *, skip_validation: bool | None = False)[source]#

Bases: object

Represents a response to a prompt request.

This is a single request to a target. It can contain multiple prompt request pieces.

Parameters:

request_pieces (Sequence[PromptRequestPiece]) – The list of prompt request pieces.

__init__(request_pieces: Sequence[PromptRequestPiece], *, skip_validation: bool | None = False)[source]#

Methods

__init__(request_pieces, *[, skip_validation])

flatten_to_prompt_request_pieces(...)

from_prompt(*, prompt, role)

from_system_prompt(system_prompt)

get_all_values(request_responses)

Return all converted values across the provided request responses.

get_piece([n])

Return the nth request piece.

get_role()

Return the role of the first request.

get_value([n])

Return the converted value of the nth request piece.

get_values()

Return the converted values of all request pieces.

is_error()

Returns True if any of the request pieces has an error response.

set_response_not_in_database()

Set that the prompt is not in the database.

validate()

Validates the request response.

static flatten_to_prompt_request_pieces(request_responses: Sequence[PromptRequestResponse]) MutableSequence[PromptRequestPiece][source]#
classmethod from_prompt(*, prompt: str, role: Literal['system', 'user', 'assistant', 'tool', 'developer']) PromptRequestResponse[source]#
classmethod from_system_prompt(system_prompt: str) PromptRequestResponse[source]#
static get_all_values(request_responses: Sequence[PromptRequestResponse]) list[str][source]#

Return all converted values across the provided request responses.

get_piece(n: int = 0) PromptRequestPiece[source]#

Return the nth request piece.

get_role() Literal['system', 'user', 'assistant', 'tool', 'developer'][source]#

Return the role of the first request.

get_value(n: int = 0) str[source]#

Return the converted value of the nth request piece.

get_values() list[str][source]#

Return the converted values of all request pieces.

is_error() bool[source]#

Returns True if any of the request pieces has an error response.

set_response_not_in_database()[source]#

Set that the prompt is not in the database.

This is needed when we’re scoring prompts or other things that have not been sent by PyRIT

validate()[source]#

Validates the request response.