Why does requested JSON still contain code fences or fail parsing?
Requested JSON parses reliably only when the request enables native structured output with response_format and the model finishes the reply without truncation. Prompt wording alone still allows Markdown code fences, extra commentary, or incomplete objects when output hits a token cap.
Request structured output natively
Confirm that the target model supports native response_format on POST /v1/chat/completions, then declare the required schema in the request payload rather than relying solely on prompt text. Keep max_tokens large enough for the full JSON object while staying at or below the model’s max_output_tokens.
When calling a model through Capabilities, inspect the model’s exposed Capabilities input fields before passing any format option.
Validate completion state and schema
- Inspect
choices[0].finish_reasonbefore parsing. Onlystopindicates a complete answer; log truncation and refusals as separate states instead of running a JSON parser on partial text. - Parse
choices[0].message.contentand validate every required field (such ascategoryandsummary) against an application schema. An HTTP200confirms transport delivery, not schema compliance. - Route parse errors and schema validation failures to manual review so malformed records never enter downstream automation.
Contracts and related questions
Before sending a paid request, inspect the model contracts for free: model:gpt-6-luna, model:gpt-image-2.5-flare-std.

