# LLM05 - Improper Output Handling

> Insufficient validation of LLM output leading to XSS, RCE, or other vulnerabilities.

- **Category**: Owasp Llm
- **Subcategory**: top10_2025
- **Canonical URL**: https://designpattern.fyi/owasp_llm/llm05_improper_output/

---

## Description
'**Intent**: Ensure all LLM-generated output is properly validated and sanitized before use in downstream systems.

**Context**: LLM outputs are often passed directly to other components, browsers, or APIs without validation. This can lead to XSS, SSRF, privilege escalation, or remote code execution.

**Solution**: Treat LLM output as untrusted. Apply output encoding appropriate to the context. Validate outputs against expected formats. Implement content security policies. Sandbox code execution environments.'



## Use Cases
Use whenever LLM outputs are rendered in web pages, executed as code, or passed to other systems.





## Trade-offs


### Advantages

- Prevents XSS and injection attacks

- Blocks code execution exploits

- Ensures output safety

- Protects downstream systems




### Considerations & Drawbacks

- May alter intended output formatting

- Context-dependent sanitization is complex

- Overly aggressive filtering reduces utility







---
**Reference**: [Original Source](https://genai.owasp.org)

