[GH-ISSUE #3766] Angle brackets in cards, personas, and lorebooks get mangled to < before reaching the model #2030

Closed
opened 2026-10-21 05:44:43 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @kolacheee on GitHub (Jul 18, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3766

Originally assigned to: @kolacheee on GitHub.

If you type an angle bracket into a character card field, a persona/user description, a lorebook entry, or example dialogue, the model doesn't get what you typed. A < is turned into &lt; and a & into &amp; before the prompt is sent.

That matters because a lot of people organize their cards and lorebooks with angle-bracket / HTML-style tags like <thinking>, <scenario>, or <div>, and some cards use inline HTML like <font color=...> for styling. All of that reaches the model garbled — it sees &lt;thinking> and &lt;font color=...&gt; — so tag-based structure and HTML formatting break in the reply. The prompt viewer also shows the literal &lt;, and the escaped entities waste tokens.

This happens whenever the Conversation preset uses the default XML wrap format, which is the out-of-the-box setup.

Try it yourself (on released v2.3.3)

  1. Open any persona (user) and put <test> in its description. (A character card field or a lorebook entry works too.)
  2. Open or start a chat that uses the default XML-wrapped Conversation preset.
  3. Open the Peek Prompt / Assembled Prompt view.
  4. You'll see &lt;test> where you typed <test>. That's exactly what the model receives.

This affects "leaf" content generally: character card fields (description, personality, scenario, etc.), the persona / user description, lorebook entries, recalled memories, scene text, and example dialogue.

Why it happens (short note)

In packages/server/src/services/prompt/prompt-escaping.ts, the function escapeXmlText runs value.replace(/&/g,'&amp;').replace(/</g,'&lt;') on this leaf content and is applied to the XML-wrapped path via sanitizePromptLeaf. It was originally added as a prompt-injection guard against untrusted imported cards — but for a local single-user tool that "injection" is at most a rare, self-fixable annoyance (you see the weird output and edit your own card), while the escaping corrupts the very common, legitimate use of tags in cards and lorebooks. Leaf content should reach the model verbatim.

This exact behavior has been broken and re-fixed several times, because each pass only partially carved out the guard (dropping >, exempting the <START> example-dialogue marker, decoding on the display layer in #3206) instead of removing it — so the < escaping kept surviving.

Not part of this bug

The agent value/attribute escapers that feed strictly machine-parsed XML — agent world-state, knowledge/entry catalogs, storyboard sections, attachment attributes — are correct to keep escaping and should stay as they are. This is only about the human-authored prompt leaf path.

Fix

A fix is already open in #3765: it makes leaf content verbatim and hardens the code so this stops recurring — https://github.com/Pasta-Devs/Marinara-Engine/pull/3765

Originally created by @kolacheee on GitHub (Jul 18, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3766 Originally assigned to: @kolacheee on GitHub. If you type an angle bracket into a character card field, a persona/user description, a lorebook entry, or example dialogue, the model doesn't get what you typed. A `<` is turned into `&lt;` and a `&` into `&amp;` before the prompt is sent. That matters because a lot of people organize their cards and lorebooks with angle-bracket / HTML-style tags like `<thinking>`, `<scenario>`, or `<div>`, and some cards use inline HTML like `<font color=...>` for styling. All of that reaches the model garbled — it sees `&lt;thinking>` and `&lt;font color=...&gt;` — so tag-based structure and HTML formatting break in the reply. The prompt viewer also shows the literal `&lt;`, and the escaped entities waste tokens. This happens whenever the Conversation preset uses the default XML wrap format, which is the out-of-the-box setup. ## Try it yourself (on released v2.3.3) 1. Open any persona (user) and put `<test>` in its description. (A character card field or a lorebook entry works too.) 2. Open or start a chat that uses the default XML-wrapped Conversation preset. 3. Open the Peek Prompt / Assembled Prompt view. 4. You'll see `&lt;test>` where you typed `<test>`. That's exactly what the model receives. This affects "leaf" content generally: character card fields (description, personality, scenario, etc.), the persona / user description, lorebook entries, recalled memories, scene text, and example dialogue. ## Why it happens (short note) In `packages/server/src/services/prompt/prompt-escaping.ts`, the function `escapeXmlText` runs `value.replace(/&/g,'&amp;').replace(/</g,'&lt;')` on this leaf content and is applied to the XML-wrapped path via `sanitizePromptLeaf`. It was originally added as a prompt-injection guard against untrusted imported cards — but for a local single-user tool that "injection" is at most a rare, self-fixable annoyance (you see the weird output and edit your own card), while the escaping corrupts the very common, legitimate use of tags in cards and lorebooks. Leaf content should reach the model verbatim. This exact behavior has been broken and re-fixed several times, because each pass only partially carved out the guard (dropping `>`, exempting the `<START>` example-dialogue marker, decoding on the display layer in #3206) instead of removing it — so the `<` escaping kept surviving. ## Not part of this bug The agent value/attribute escapers that feed strictly machine-parsed XML — agent world-state, knowledge/entry catalogs, storyboard sections, attachment attributes — are correct to keep escaping and should stay as they are. This is only about the human-authored prompt leaf path. ## Fix A fix is already open in #3765: it makes leaf content verbatim and hardens the code so this stops recurring — https://github.com/Pasta-Devs/Marinara-Engine/pull/3765
bsakaguchi 2026-10-21 05:44:43 +07:00
Sign in to join this conversation.
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
Pasta-Devs/Marinara-Engine#2030
No description provided.