Triple Quotes: Encapsulating User Inputs & Text Blocks

Using triple quotes (''' or """) effectively isolates larger sections of text or user inputs, preventing prompt injection attacks and ensuring the LLM processes a specific block of content distinctly, such as for summarization or rephrasing tasks.

The top 3

  1. Triple Quotes' Primary Role: Instruction-Context Segregation: Triple quotes (`"""`) are a fundamental delimiter for clearly separating user inputs or long text blocks from system instructions within an LLM prompt. This distinct encapsulation minimizes ambiguity, ensuring the model accurately interprets which part is context versus command, thereby improving response relevance and precision, especially for tasks like summarization or analysis.
  2. Delimiter Hierarchy: When Triple Quotes Outperform: While triple quotes excel for general multi-line text and user input, specific tasks benefit from other delimiters: triple backticks (```) are favored for code snippets, XML tags (`<tag>`) for complex, hierarchical data structures (especially with models like Claude), and triple hashes (###) for distinct instructional steps.
  3. Triple Quote Blunders: Common Injection Vulnerabilities: Despite their utility, improper use of triple quotes—such as unmatched delimiters, internal content mimicking the delimiter, or insufficient sanitization—can create 'delimiter confusion,' leaving LLMs vulnerable to prompt injection attacks where malicious inputs escape their intended boundaries.

Sources

Open the full topic