TokenPad
Safety

LLM JSON Output Validator

Extract the JSON from a chatty response and check it has the keys you need.

Your input

160 characters7 lines0 tokensor drop a file

Output ValidatorExact
0Token change
Token change0no change
Input tokens0what you pasted
Output tokens0what you would send
Token cost of this result
Output tokens0
As input$0.00
× 100K requests$0.00

Everything on this page runs in your browser. Nothing you paste is transmitted, because there is no server here to transmit it to.

Result
 

The wrapping problem

You asked for JSON. The model returned "Here is the result you asked for:" followed by a fenced code block followed by "Let me know if you need anything else!". Your parser fails on the first character.

This extracts the JSON from that wrapper, so you can see whether the structure underneath was actually correct — which it usually is. The failure is presentation, not content.

Checking the contract

Parsing is not enough. Valid JSON with a missing key breaks your application just as thoroughly as malformed JSON, and does so further downstream where it is harder to diagnose.

List the keys your code depends on and the validator reports both what is missing and what arrived unexpectedly. Unexpected keys are worth attention too — they often mean the model is answering a slightly different question than you think.

Fixing the cause rather than the symptom

If you regularly need to strip prose before parsing, the prompt is the problem. Tighten the output-format section: state the exact shape, name the keys, and say explicitly that the response must contain nothing but the JSON object.

Structured output modes, where the provider offers them, remove the problem entirely by constraining generation to a schema. That is strictly better than repairing output, and it is usually a one-line change.

Frequently asked questions

Why does the model add prose when I asked for JSON only?
Conversational helpfulness is trained in deeply. Countering it takes an explicit instruction that the response must contain nothing but the object — or a structured output mode, which enforces it rather than requesting it.
Should I just repair the output in code?
Extraction as a safety net is reasonable. Relying on it is not, because the shapes models invent when unconstrained are open-ended and your repair logic will keep growing. Fix the prompt.
What about truncated JSON?
That is a max_tokens problem, not a format one. Generation stopped mid-object. Raise the ceiling or ask for a more compact response.

More safety tools