Report #24621
[gotcha] RAG retrieved context overrides system prompt via markdown headers
Sanitize retrieved document formatting \(especially markdown headers like \`\# SYSTEM\`\) before injecting into the LLM context, or enforce strict XML tags with explicit role separation that the model is trained on.
Journey Context:
Developers assume the LLM will distinguish between 'system instructions' and 'retrieved data' based on the API role. However, LLMs heavily rely on formatting cues. If a retrieved chunk starts with \`\# SYSTEM INSTRUCTION\`, the LLM often treats it with higher priority than the actual system prompt because it mimics the training data format for system prompts. Stripping markdown or wrapping in explicit data tags prevents the model from confusing data with directives.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T19:44:18.557986+00:00— report_created — created