Search⌘ K
AI Features

Untrusted Output and Safe Rendering in React

Understand how to handle untrusted AI output safely in React applications by treating all assistant responses as external input. Learn to separate raw text from validated data, avoid dangerous HTML rendering, validate structured output before rendering, and implement fallback states to prevent UI crashes or security issues.

Those five failure states all assumed the text itself was safe to show. That assumption is the next thing to question. A chat response that contains <b>Important</b> can land in your UI in two visibly different ways. If a React component renders it as a normal text node, the user sees the literal characters <b>Important</b>. If a component routes the same string into an HTML rendering path, the browser interprets it as markup and the UI changes shape. ...