Output Safety, XSS, and Sensitive Data
Model output is untrusted text. Render Markdown and HTML safely, sanitize any permitted HTML, and avoid direct unsanitized insertion into the DOM. Treat code, links, citations, and tool arguments as data. Validate URLs before making them clickable, especially schemes and hosts. If the model generates SQL or code, do not execute it automatically in a privileged environment.
Sensitive data handling includes minimization, redaction, retention, access controls, encryption in transit and at rest, and provider-specific review. Logs should be useful for debugging but should not become a secondary database of secrets or private conversations.
// Prefer textContent for plain text:
messageElement.textContent = modelResponse;
// If rendering Markdown, use a maintained renderer plus sanitization
// and an explicit link/HTML policy rather than injecting raw HTML.- Escape plain text and sanitize permitted rich content.
- Validate generated links and tool arguments.
- Redact sensitive values in logs and define retention.
Why should model output be treated as untrusted when rendered in a web page?