.. include:: /Includes.rst.txt .. _adr-020: ========================================== ADR-020: Backend Output Format Rendering ========================================== :Status: Accepted :Date: 2025-12 :Authors: Netresearch DTT GmbH .. _adr-020-context: Context ======= LLM responses can contain markdown, HTML, JSON, or plain text depending on the task's output format. Users need to view output in an appropriate rendering mode without re-executing the (potentially expensive) LLM call. .. _adr-020-decision: Decision ======== Store raw LLM output and handle format rendering entirely client-side. The toggle between formats is ephemeral (not persisted) and operates on the cached raw content. Four rendering modes in :file:`Resources/Public/JavaScript/Backend/TaskExecute.js`: .. code-block:: javascript :caption: Format rendering dispatch renderOutput() { const content = this._rawContent; const escaped = this.escapeHtml(content); switch (this._activeFormat) { case 'html': this.renderHtmlOutput(content); break; case 'markdown': this.renderMarkdownOutput(escaped); break; case 'json': this.renderJsonOutput(content); break; default: this.renderPlainOutput(); break; } } .. _adr-020-modes: Rendering modes --------------- .. csv-table:: :header: "Mode", "Technique", "Security" :widths: 15, 45, 40 "Plain", "``
`` with ``textContent`` assignment", "Fully escaped (DOM API)"
   "Markdown", "Regex transforms on HTML-escaped content", "Pre-escaped before transform"
   "JSON", "``JSON.stringify`` pretty-print in ``
``", "``textContent`` assignment"
   "HTML", "Sandboxed iframe (``sandbox=\"\"``)", "No script execution, no parent DOM access"

.. _adr-020-security:

Security approach
-----------------

LLM responses are untrusted external content. Each mode uses a different
security strategy:

- **Plain/JSON:** Content set via ``textContent`` (automatic HTML escaping by the DOM).
- **Markdown:** Content is first HTML-escaped via ``escapeHtml()`` (``textContent``
  assignment to a temporary element, then read back via ``innerHTML``). Markdown
  regex transforms operate on already-escaped content, making injection safe.
- **HTML:** Rendered inside a fully sandboxed ``