Skip to content

How should I render AI-written text in my application without executing generated markup?

Treat generated text as untrusted data. Render plain text by default, or use a restricted Markdown pipeline with unsafe HTML disabled and a reviewed sanitizer where necessary. AISwapLab's text-only chat capability does not make its output safe to insert as executable page markup.

DESIGN A CLEAR API PRODUCT EXPERIENCEAISwapLab team · Editorial methodUpdated 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Choose the required format; Constrain active content; Keep content and commands separate.
Workflow diagram: Choose the required format → Constrain active content → Keep content and commands separate. Read the article for evidence and limits.

The output is content

A request for a script or a product description can still return code blocks, links or HTML-like text. That text may be copied from source material or invented. Its origin does not authorize it to modify your page, load resources or execute browser behavior.

What to do next

  1. 01

    Choose the required format

    If the feature only needs paragraphs, render paragraphs as text and preserve line breaks safely. Add Markdown features only when they serve a user need, rather than enabling arbitrary HTML for visual convenience.

  2. 02

    Constrain active content

    Disable raw HTML, restrict link protocols and avoid automatic embedding of remote images or iframes. If sanitized HTML is unavoidable, use a maintained sanitizer and test the actual parsing and rendering pipeline together.

  3. 03

    Keep content and commands separate

    Do not derive privileged application actions from generated tags, hidden attributes or rendered buttons. A user must invoke your real controls, and the backend must validate the resulting operation independently of the displayed text.

A concrete example

Illustrative example: a generated script includes a literal script tag as part of dialogue. The preview displays those characters; it does not execute them. A Markdown link with an unsafe protocol is rejected before it becomes clickable.

Before you call it ready

  • Script tags are displayed or removed safely.
  • Unsafe link protocols are rejected.
  • Generated buttons cannot invoke backend actions.

A locally executed, reproducible check

React server rendering escapes a text child that contains markup syntax.

We executed this exact synthetic fixture on November 16, 2026 with Node v24.16.0 and React 19.2.6. It ran locally with no network requests, account data or model generation. The recorded output below is an observation from that environment, not a platform benchmark. Copy the code into a separate CommonJS file to repeat it with the stated dependencies in a suitable local Node environment; compare the mechanism and check your runtime version.

javascript
const React=require('react');
const {renderToStaticMarkup}=require('react-dom/server');
const raw='<img src=x onerror="example()">';
console.log(renderToStaticMarkup(React.createElement('p',null,raw)));

Recorded output and interpretation

No browser executes the string. This checks a React text child under the recorded version, not dangerous HTML insertion, Markdown plugins, URL props or sanitization. Passing generated content to dangerouslySetInnerHTML or a later HTML parser creates a separate boundary that this result does not validate.

A matching local output establishes only the illustrated library or database behavior under these inputs. It does not certify a production integration. Preserve the approved action, authorization boundaries and current AISwapLab request contract when applying the idea.

text
<p>&lt;img src=x onerror=&quot;example()&quot;&gt;</p>

When to stop or choose another method

Stop rendering generated text through raw HTML APIs until the complete rendering path has a verified restriction and sanitization policy.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation