LLMs, GenAI, RAG, agents, evaluation · insight-0651
Encode or parameterise model output before it reaches SQL, HTML or a shell
- Evidence type
- documented fact
- Difficulty
- easy
- Roles
- ML engineer, Applied AI
- Industries
- e-commerce, saas
Summary: situation, action, reason, boundary
Situation
Generated text is inserted into a web page, a database query, a template or a command line.
Action
Treat model output like untrusted user input: use parameterised queries, context-aware encoding for HTML and other sinks, a strict content security policy for rendered output, and allow-lists for any identifiers that select tables, files or commands.
Reason
OWASP's Improper Output Handling entry describes how unvalidated LLM output can lead to XSS, SSRF, privilege escalation or remote code execution, and recommends zero-trust handling, encoding and parameterised queries.
Boundary
Any pipeline where model text is consumed by another program.
Symptom or risk
Output shaped by a user or by injected content becomes cross-site scripting, SQL injection or command execution in a downstream system.
Exceptions
Output shown only as plain escaped text to the same user who wrote the prompt, with no tools involved.
Trade-offs
Strict encoding can break legitimate rich formatting; allow a small, sanitised Markdown subset.
Pitfalls
Validating the model's input but not its output, or trusting output because "our model would not do that".
Lessons and concepts
Claims and their sources
OWASP LLM05:2025 recommends treating model output as untrusted, applying context-aware output encoding and using parameterised queries for database operations.