LLM JSON output validator
Updated
In short: Five common causes of invalid JSON from an LLM: a code fence or prose around it, trailing commas, single or curly quotes, unquoted keys, or output cut off at max_tokens (finish_reason "length"). Paste the output to find the error by line and column, apply safe repairs and validate it against your JSON Schema.
Report a wrong price or number (email to info@broadnet.ai, with this page's link and your inputs filled in).
How it works
- Paste the model's reply as it came back, with any code fence or surrounding text. Or load one of the examples.
- Read the verdict: valid as-is, or the first error with its line and column, and whether the output looks cut off.
- Choose which repairs to allow. The repaired JSON is parsed again, and you can copy it raw or formatted.
- Optionally paste a JSON Schema, or a whole
response_formatobject, to check fields, types and required keys.
Why model JSON breaks, and the fix for each
| What you see | Cause | Fix at the source |
|---|---|---|
```json or “Here is…” around it | The model formats its answer for a chat window | Use structured output where the model supports it, or say “Reply with only the JSON object” |
,} or ,] | Trailing comma, valid in JavaScript but not JSON | Repair is safe; a schema-constrained mode prevents it |
'key', “key” or key: | Python or JavaScript habits, or curly quotes | Show a JSON example in the prompt; repair is safe |
True, None, NaN | Python or JavaScript literals | Repair maps them to true, null |
| Ends mid-string, brackets left open | The reply hit max_tokens (finish_reason: "length") | Raise max_tokens; on reasoning models leave room for reasoning; split long lists |
| Parses, but fields are wrong | Valid JSON, wrong shape | Validate against a schema and retry with the errors in the prompt |
A safe parsing loop
- Check
finish_reasonfirst. If it is"length", do not repair: retry with a largermax_tokens. - Strip a code fence or surrounding text, then parse strictly.
- On failure, apply only value-preserving repairs and parse again.
- Validate against your JSON Schema. On errors, send them back to the model once, then give up and log the item.
Repairs that keep every value (quotes, commas, keys, comments) are safe to automate. Repairs that guess, such as closing cut-off output, belong in a debugging session, not in production code.
What this validator does not do
It checks a common subset of JSON Schema 2020-12 (with draft-07 definitions), not every keyword. Remote $ref URLs, dependentRequired, if/then/else and unevaluatedProperties are reported as not checked. Strict structured-output modes add their own rules, which the JSON schema generator checks.
Questions
Why does my LLM return invalid JSON?
The common causes: the model wrapped the JSON in a code fence or a sentence, left a trailing comma, used single or curly quotes, wrote keys without quotes, or ran out of tokens mid-object. Python-style True and None, and comments, also turn up. The validator names the error and the line and column where it starts.
How can I tell if the JSON was cut off by max_tokens?
Truncated output ends inside a string or with brackets still open. Check the response too: OpenAI's API reference defines finish_reason: "length" as the maximum number of tokens being reached (checked 2026-11-15). On reasoning models such as DeepSeek V4.1 Flash, GLM 5.3, Qwen3.8 27B, BroadNet's docs say reasoning counts toward max_tokens, so a small limit can cut the JSON short.
Is it safe to repair LLM JSON automatically?
Quote, comma, comment and key fixes keep every value, so they are generally safe, but check the result against your schema. Closing cut-off output is different: everything after the cut is lost, so the tool leaves that repair off by default. Raise max_tokens and request the item again instead.
Which BroadNet models support structured output?
BroadNet's developer reference lists structured output for GLM 5.3 and Qwen3.8 27B (checked 2026-11-15). It does not document which response_format types they accept, so send a test request. For other models, ask for JSON in the prompt, show an example, validate every reply and retry on failure.
Which JSON Schema keywords does the validator check?
type (including integer and type lists), properties, required, additionalProperties, patternProperties, propertyNames, items, prefixItems, contains, enum, const, string length, pattern, common formats, numeric bounds, multipleOf, array and object size, uniqueItems, allOf, anyOf, oneOf, not and local $ref. Keywords it does not check are listed, not passed silently.
Is my output sent anywhere?
No. Parsing, repair and validation run in your browser, and nothing you paste is stored in the page address or sent to a server. Close the tab and it is gone.
Go deeper
Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity
Sources
- BroadNet Inference machine-readable prices (pricing.json)
- BroadNet Inference API reference: structured output listed for GLM 5.3 and Qwen3.8 27B; reasoning counts toward max_tokens (checked 2026-11-15)
- OpenAI API reference, chat completions: finish_reason "length", response_format json_object and json_schema (checked 2026-11-15)
- RFC 8259, the JSON data interchange format: grammar with no trailing commas, comments or single quotes (checked 2026-11-15)
- JSON Schema 2020-12 validation vocabulary (checked 2026-11-15)