Own Weights

Structured JSON output without slowing down

Structured output LLM guide: get valid JSON on the first try, cut retries, keep prompts short and test values, without slowing your app down at all.

Updated

Structured output means the model returns data in a fixed shape, such as JSON with named fields and set types, so your code can read it without parsing free text. There are two ways to get that shape: constrain the model while it writes, or train the format into the model so it becomes the default. Done well, neither one has to slow your app down. When a structured app does slow down, the cause is almost always retries or prompt length, and both are fixable in code you already own.

Why JSON output gets slow

Most of the delay comes from retries, not from the JSON itself. A reply that drops a closing bracket, puts a sentence before the object or invents a field name forces a second call. Your code then waits for two full round trips and pays for both.

Long prompts add to it. Teams often paste the full schema, several examples and a list of rules into every request. Those tokens are read on each call and add time before the first character comes back. Extra keys and prose around the JSON also make the answer longer to produce, so it finishes later.

The fix is an answer that is right the first time. Ask for the fields you need and nothing else.

JSON mode versus schema-constrained output

Basic JSON mode only promises that the output parses. It does not promise your keys or your types, so you still need validation code and a retry path for missing fields.

Schema-constrained decoding goes further. At each step the decoder allows only the tokens that keep the output valid for the schema you supplied, so the shape matches every time. The cost is extra work per token. Deep nesting and long enum lists make that work heavier, so keep schemas flat and use short field names.

A constrained decoder guarantees the shape, not the values. A field can be valid and still hold the wrong clause, the wrong date or the wrong amount. Only a test set catches that.

A worked example: contract fields

Suppose your app reads commercial agreements and returns four fields: the parties, the effective date, the governing law and the notice period for termination. A flat schema for that looks like this:

{
  "parties": ["string"],
  "effective_date": "YYYY-MM-DD or null",
  "governing_law": "string or null",
  "termination_notice_days": "integer or null"
}

Four fields, no nesting, and an explicit null for “not found” give the decoder little to do and give your code a clear signal. Now compare that with a schema that also asks for a quote and a confidence score for each field. Every answer gets longer, and the model has more fields to get wrong, while your app may never read the extras. Ask for the quote only when a reviewer needs it.

Training the format into the model

The other route is fine-tuning. You train the model on your own examples, and every target answer is the exact JSON you want. After training, the model produces that shape without a long schema in the prompt. Prompts get shorter, and retries drop because the format is no longer something the model has to recall on each call.

This suits one task that runs at volume, such as pulling the same fields from every invoice or tagging every support ticket with the same labels. A general model has to handle every format it has seen. A trained model only has to handle yours. Split the training and test data by contract, never by chunk, so no contract appears in both. Otherwise the score flatters the model.

To check that the trained format holds, run both setups on the same held-out records and compare schema failures, retries per 100 calls and the share of fields with the right value. The trained model should win on the first two without losing on the third. The full method is in how to build a test set.

Mistakes that add time

  • Treating a parse as a pass. A reply that parses can still have wrong values. Validate the keys and types, then score the values.
  • Retrying the same request. If the prompt caused the failure, an identical second call often fails the same way. Log which field broke and change the prompt or schema.
  • Repeating the schema on every call when a fine-tuned format, or a shorter prompt, would carry the same instruction.
  • Putting reasoning inside the JSON. It makes every answer longer and harder to validate. If the model must think first, do that in a separate step.
  • Leaving output length unbounded. One runaway answer can take far longer than the rest of the batch.

Keeping structured output fast

  1. Measure the retry rate and the tokens per answer on your current calls. Those two numbers show where the time goes and give you a baseline to beat.
  2. Drop fields the app never reads, and drop explanations unless a person reads them.
  3. Keep enum lists short and field names plain.
  4. Set a maximum output length so a runaway answer stops.
  5. Send work that has no deadline in batches, and keep the real-time path small.
  6. Score the current model and any replacement on the same fixed examples before you switch.

To estimate what retries cost at your volume, use the LLM cost calculator. For the speed side of this topic, read tokens per second, explained. For the reliability side, read making LLM JSON output reliable. If you are deciding between a trained model and better prompts, fine-tuning vs prompt engineering covers when each one earns its place.

If your app sends the same structured task to a frontier API every day, Own Weights can start with a free audit. We map your AI calls by task, build a test from your real data, and train a model only if it beats the current one on that test. Use the free audit button on this page to book a call.

Questions

Does structured output make LLM responses slower?

Not by itself. The slowdown usually comes from retries after malformed JSON and from long prompts that repeat the schema on every call. Cutting those two causes is often the fastest fix.

Is JSON mode enough to get reliable JSON from a model?

JSON mode guarantees output that parses, but not the keys or types your code expects. Pair it with a schema check and a retry path, and test the values against labeled examples.

Can a fine-tuned model return JSON without a long schema in the prompt?

Yes, if every training answer uses the exact format you want. The model then keeps the shape without the schema repeated in each request, which shortens every call. Check the first release against a fixed test set before you rely on it.