Mitigate prompt injection via user-message wrapping + explicit guard #64

Merged
plank merged 1 commit from feature/prompt-injection-mitigation into main 2026-11-09 22:13:10 +01:00
Owner

None of the prompts that embed the raw user message (classify_intent,
direct_response, synthesize_response, and the RAG grade/rewrite/generate
steps) distinguished user-typed content from instructions to the model.

Wrap the user message in a <user_message> tag
(app/llm.py::wrap_user_input, added in the previous commit) and prepend
PROMPT_INJECTION_GUARD, an explicit instruction telling the model to
treat that block strictly as data, never as commands - even if it
claims system/developer/admin authority. wrap_user_input also strips
any literal occurrence of the tag from the input so a crafted message
can't fake a closing tag and escape the wrapper.

This is a meaningful mitigation, not a hard guarantee - documented as
such in the README's "Known limitations" section.

Refs #15

None of the prompts that embed the raw user message (classify_intent, direct_response, synthesize_response, and the RAG grade/rewrite/generate steps) distinguished user-typed content from instructions to the model. Wrap the user message in a <user_message> tag (app/llm.py::wrap_user_input, added in the previous commit) and prepend PROMPT_INJECTION_GUARD, an explicit instruction telling the model to treat that block strictly as data, never as commands - even if it claims system/developer/admin authority. wrap_user_input also strips any literal occurrence of the tag from the input so a crafted message can't fake a closing tag and escape the wrapper. This is a meaningful mitigation, not a hard guarantee - documented as such in the README's "Known limitations" section. Refs #15
plank added 1 commit 2026-11-09 22:04:10 +01:00
None of the prompts that embed the raw user message (classify_intent,
direct_response, synthesize_response, and the RAG grade/rewrite/generate
steps) distinguished user-typed content from instructions to the model.

Wrap the user message in a <user_message> tag
(app/llm.py::wrap_user_input, added in the previous commit) and prepend
PROMPT_INJECTION_GUARD, an explicit instruction telling the model to
treat that block strictly as data, never as commands - even if it
claims system/developer/admin authority. wrap_user_input also strips
any literal occurrence of the tag from the input so a crafted message
can't fake a closing tag and escape the wrapper.

This is a meaningful mitigation, not a hard guarantee - documented as
such in the README's "Known limitations" section.

Refs #15
plank merged commit 2207b52d63 into main 2026-11-09 22:13:10 +01:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: PWC/agentic-rag-policy-assistant#64
No description provided.