OWASP LLM05

LLM05 Improper Output Handling: Sanitise Model Output Before Use

OWASP LLM Top 10 · 2025 edition · Updated 25 November 2026 · Independent educational guide

New to LLMs, classifiers or RAG? Read the beginner FAQ and terminology.

Building an action-taking agent? Read the full agent runtime security guide for execution-time boundaries, safe tests and OWASP mapping.

Read the dated field-test post.

What is improper output handling in LLM applications?

Improper output handling occurs when an application passes model output to a browser, database, shell or another system without validation. Because output can be influenced by attackers, it must be treated as untrusted. Encode for the destination, validate against a schema and never execute generated code without sandboxing.

Why is LLM output untrusted?

Model output reflects its inputs, and those inputs can include attacker-controlled text from users, documents or tools. A successful prompt injection can make the model emit HTML, SQL, shell commands or links crafted to exploit whatever system consumes the response next. Treat it exactly like user-submitted data.

How do I safely render LLM output in a web page?

Render as text by default, or convert Markdown with a sanitiser that removes scripts, event handlers and unsafe URLs. Avoid inserting raw HTML. Restrict images and links that could exfiltrate data through query strings, and apply a content security policy as a second layer of defence.

How do I audit my app for OWASP LLM05?

Trace every place model output goes: the UI, databases, file systems, shells, emails and other APIs. For each, confirm output is encoded or parameterised for that destination and validated against an expected structure. Try test outputs containing script tags, SQL fragments and shell metacharacters.

What does this OWASP LLM risk look like in practice?

Illustrative scenario: Model-generated HTML is inserted directly into a browser page.

How can I test it safely?

Pass harmless script-like test strings through the same output path in staging. Verify they display as text or are sanitised, cannot execute, and cannot introduce unsafe links; separately validate any structured action output.

What evidence should I keep?

Record destination-specific encoding, schema rejection and browser execution results. Schema-valid text can still be unsafe when used in a shell or query.

LLM05 audit checklist

Control to consider: Output sanitizer. Some controls run outside the request path; model inline checks, then measure your own deployment.

General guidance only, written with AI assistance and human oversight. Verify against your own system and the official OWASP project before relying on it.

Sources and scope

Examples and checklists are our explanatory guidance, not an official OWASP audit, endorsement or a test of your application. Calculator values are modelled assumptions, not detector benchmarks.

Other OWASP LLM risks