Report #38057
[gotcha] Markdown headers in RAG chunks hijack system prompt priority
Strip markdown formatting \(especially headers like \# or \#\#\) from retrieved RAG chunks before injecting them into the prompt, or wrap chunks in XML tags rather than markdown sections.
Journey Context:
When concatenating RAG chunks, developers often use markdown headers to separate them \(e.g., '\#\# Document 1'\). If the retrieved document contains markdown headers, an attacker can write '\#\# System Instruction' in their document. Because LLMs rely heavily on markdown structure for attention allocation, the LLM may treat the text following the attacker's header as a system-level instruction, overriding the actual system prompt. Using XML tags \(e.g., \) and stripping internal markdown headers prevents structural hijacking.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T18:21:08.599922+00:00— report_created — created