pyrit.models.TextDataTypeSerializer#

class TextDataTypeSerializer(*, prompt_text: str, data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] = 'text')[source]#

Bases: DataTypeSerializer

Serializer for text and text-like prompt values that stay in-memory.

__init__(*, prompt_text: str, data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output'] = 'text')[source]#

Initialize a text serializer.

Parameters:
  • prompt_text (str) – Prompt value.

  • data_type (PromptDataType) – Text-like prompt data type.

Methods

__init__(*, prompt_text[, data_type])

Initialize a text serializer.

data_on_disk()

Indicate whether this serializer persists data on disk.

get_data_filename([file_name])

Generate or retrieve a unique filename for the data file.

get_extension(file_path)

Get the file extension from the file path.

get_mime_type(file_path)

Get the MIME type of the file path.

get_sha256()

Compute SHA256 hash for this serializer's current value.

read_data()

Read data from storage.

read_data_base64()

Read data from storage and return it as a base64 string.

save_b64_image(data[, output_filename])

Save a base64-encoded image to storage.

save_data(data[, output_filename])

Save data to storage.

save_formatted_audio(data[, num_channels, ...])

Save PCM16 or similarly formatted audio data to storage.

Attributes

category: str#
data_on_disk() bool[source]#

Indicate whether this serializer persists data on disk.

Returns:

Always False for text serializers.

Return type:

bool

data_sub_directory: str#
data_type: Literal['text', 'image_path', 'audio_path', 'video_path', 'binary_path', 'url', 'reasoning', 'error', 'function_call', 'tool_call', 'function_call_output']#
file_extension: str#
value: str#