Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyrit/prompt_target/prompt_shield_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async def _send_prompt_to_target_async(self, *, normalized_conversation: list[Me
"api-version": self._api_version,
}

parsed_prompt: dict[str, Any] = self._input_parser(request.original_value)
parsed_prompt: dict[str, Any] = self._input_parser(request.converted_value)

body = {"userPrompt": parsed_prompt["userPrompt"], "documents": parsed_prompt["documents"]}

Expand Down
23 changes: 23 additions & 0 deletions tests/unit/prompt_target/target/test_prompt_shield_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,26 @@ def test_identity_auth_mode_with_explicit_key_raises(sqlite_instance, explicit_k
def test_identity_auth_mode_non_azure_endpoint_raises(sqlite_instance):
with pytest.raises(ValueError, match="Identity-based authentication requires a recognized Azure Content Safety"):
PromptShieldTarget(endpoint="https://test.endpoint.com", auth_mode="identity")


async def test_prompt_shield_send_prompt_async_sends_converted_value(promptshield_target: PromptShieldTarget):
request = Message(
message_pieces=[
MessagePiece(
role="user",
conversation_id="123",
original_value="original prompt",
converted_value="converted prompt",
)
]
)
with patch("pyrit.common.net_utility.make_request_and_raise_if_error_async") as mock_request:
mock_response = MagicMock()
mock_response.content = b'{"userPromptAnalysis": {"attackDetected": false}, "documentsAnalysis": []}'
mock_request.return_value = mock_response

await promptshield_target.send_prompt_async(message=request)

mock_request.assert_called_once()
body = mock_request.call_args.kwargs["request_body"]
assert body["userPrompt"] == "converted prompt"