Skip to main content

neutralizeDelimiters

@forge/monorepo


@forge/monorepo / backend/src / neutralizeDelimiters

Function: neutralizeDelimiters()

neutralizeDelimiters(body, nonce): string

Defined in: backend/src/security/prompt-safety.ts:69

Strip anything that could impersonate a delimiter or a section boundary.

The envelope's whole value rests on the content being unable to end it. Three classes:

  • The delimiter itself. Content containing the closing tag closes the block early. Neutralised by removing any occurrence of the nonce, which content cannot know — but removing it anyway, because a nonce that leaks through a previous turn's transcript is exactly the kind of thing that happens.
  • Markdown structure. A body containing \n## forges a sibling section, and \n# forges a top-level heading that reads like a new part of the prompt. Indented rather than deleted, so the reader still sees what the content said.
  • Chat-format markers. <|im_start|>, [INST], ### System: and friends are how a provider's own template delimits turns. Content carrying one can end the system message.

Parameters

body

string

nonce

string

Returns

string