Report #81978
[gotcha] LLM structured output generation allows JSON injection attacks
Treat LLM-generated JSON as completely untrusted user input. Parse it strictly, never evaluate it directly, and sanitize or reject fields that could override application logic \(like 'role', 'type', or '\_\_class\_\_'\).
Journey Context:
When LLMs are forced to output JSON \(via function calling or JSON mode\), developers often trust the structure and pass it directly to backend APIs or databases. An attacker can craft a prompt that forces the LLM to inject unexpected keys \(e.g., 'role': 'admin'\) or escape the JSON string, leading to NoSQL injection, mass assignment, or privilege escalation in the downstream application.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T20:11:24.468056+00:00— report_created — created