Skip to content

API Reference — Converters

Payload converters transform payloads before injection or delivery.

converters

Payload converters — transform payloads before injection or delivery.

Re-exports concrete PayloadConverter implementations.

DocxConverter

Python
DocxConverter()

Convert a text payload into a Word (.docx) document.

Thin wrapper around PyRIT's WordDocConverter. Accepts a RAMPART Payload (text format) and returns a new Payload with format=DOCX and the artifact path set.

PyRIT's import chain is heavy (~14s), so initialization is deferred until the first convert_async call.

Initialize with deferred PyRIT converter.

Source code in rampart/converters/docx.py
Python
def __init__(self) -> None:
    """Initialize with deferred PyRIT converter."""
    self._pyrit_converter: _WordDocConverter | None = None

convert_async async

Python
convert_async(*, payload)

Convert a text payload into a .docx payload.

Delegates document generation to PyRIT's WordDocConverter. Preserves payload.id and payload.content for traceability and reporting.

Parameters:

Name Type Description Default
payload Payload

A text-format payload to convert.

required

Returns:

Name Type Description
Payload Payload

A new payload with format=DOCX and the artifact path set.

Raises:

Type Description
ValueError

If the payload format is not a text format.

Source code in rampart/converters/docx.py
Python
async def convert_async(self, *, payload: Payload) -> Payload:
    """Convert a text payload into a ``.docx`` payload.

    Delegates document generation to PyRIT's ``WordDocConverter``.
    Preserves ``payload.id`` and ``payload.content`` for
    traceability and reporting.

    Args:
        payload (Payload): A text-format payload to convert.

    Returns:
        Payload: A new payload with ``format=DOCX`` and the
            artifact path set.

    Raises:
        ValueError: If the payload format is not a text format.
    """
    if not payload.format.is_text:
        msg = f"DocxConverter requires a text payload, got {payload.format.value}."
        raise ValueError(
            msg,
        )

    result = await self._get_converter().convert_async(
        prompt=payload.content,
        input_type="text",
    )

    artifact_path = Path(result.output_text)

    metadata = {**payload.metadata, "converter": "DocxConverter"}

    return Payload(
        content=payload.content,
        id=payload.id,
        format=PayloadFormat.DOCX,
        artifact=artifact_path,
        metadata=metadata,
    )