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.