Best Practices for Building LLM Apps

Chapter 3 · Practice 3 of 5

Escape and validate model output before it reaches a browser, shell or database

From Prompt injection and the OWASP LLM Top 10

Why it matters

Improper output handling, LLM10 in the 2026 list, is ordinary injection with a model in the middle. Model text is attacker-influenced input to whatever consumes it next.

Where the output goesWhat can go wrongWhat to do
Browser, as HTMLXSSRender as text or through a sanitiser
SQLInjected queriesParameterized queries
Shell or evalCommands runNever pass model output there
Markdown images and linksData leaks to an attacker's URLRestrict allowed domains

Treat every string the model returns the way you would treat a form field from an unknown user.

Avoid

  • Rendering raw model output with innerHTML
  • Building SQL or shell commands from model text