# Discourse AI: structured output response was not valid JSON

**URL:** https://meta.discourse.org/t/discourse-ai-structured-output-response-was-not-valid-json/408821
**Category:** Support
**Tags:** ai
**Created:** [July 29, 2026, 2:11pm UTC](https://meta.discourse.org/t/discourse-ai-structured-output-response-was-not-valid-json/408821 "2026-07-29T14:11:05Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![lilydjwg](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilydjwg/32/515838_2.png) [@lilydjwg](https://meta.discourse.org/u/lilydjwg)
#### Post date: [August 5, 2026, 5:54am UTC](https://meta.discourse.org/t/discourse-ai-structured-output-response-was-not-valid-json/408821/8 "2026-08-05T05:54:04Z")

</div>

I believe that llama.cpp forces the schema by picking only tokens that conforms to it. I also captured a response with tcpdump and checked that the returned response is valid JSON.

It contained spaces and line breaks outside strings however (i.e. it is a pretty-printed JSON), and those line breaks were escaped by Discourse, making it invalid (I checked it in rails console).

I’m using the spam detection feature btw.

---

_[View the full topic](https://meta.discourse.org/t/discourse-ai-structured-output-response-was-not-valid-json/408821)._
