Skip to content

Invalid or truncated JSON from the model

Symptom

Parsing fails; output has trailing text, markdown fences or is cut off.

Likely causes

  • Prompt-only JSON requests on small models
  • max_tokens reached before closing braces
  • Temperature too high

How to fix it

  1. Use constrained decoding (JSON schema / grammar) instead of asking nicely.
  2. Raise max_tokens and lower temperature to 0 to 0.2.
  3. Validate the parsed object against your schema and retry on failure.
bash
# llama-server
"response_format": {"type": "json_schema", "json_schema": {"name": "out", "schema": {...}}}

Still stuck? Check the lessons or measure first with the benchmark lab.