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
1 change: 1 addition & 0 deletions pyrit/prompt_target/prompt_shield_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def _input_parser(self, input_str: str) -> dict[str, Any]:
user_prompt += contents[0]
else:
documents.append(contents[0])
user_prompt += contents[1]

return {"userPrompt": user_prompt, "documents": documents if documents else []}

Expand Down
13 changes: 13 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 @@ -84,6 +84,19 @@ async def test_prompt_shield_document_parsing(
assert result == sample_delineated_prompt_as_dict


def test_prompt_shield_document_parsing_preserves_text_between_and_after_documents(
promptshield_target: PromptShieldTarget,
):
input_str = "q1 <document> d1 </document> q2 <document> d2 </document> q3"

result = promptshield_target._input_parser(input_str)

assert result == {
"userPrompt": "q1 q2 q3",
"documents": [" d1 ", " d2 "],
}


async def test_prompt_shield_response_validation(promptshield_target: PromptShieldTarget):
# This tests handling both an empty request and an empty response
promptshield_target._validate_response(request_body={}, response_body={})
Expand Down