> ## Documentation Index
> Fetch the complete documentation index at: https://apione.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Structured output

> Request JSON, validate it on the server, and recover from incomplete results.

Structured output is useful for classification, extraction, and workflow arguments. Whether `response_format`, JSON Schema, or other format constraints are supported depends on the model parameters.

## Basic strategy

1. Check whether the model supports structured output.
2. Use the smallest, clearest structure possible.
3. Parse JSON and validate the schema on the server side.
4. On validation failure, retry a limited number of times, or fall back to plain text parsing.

## JSON object example

```json theme={null}
{
  "model": "YOUR_APIONE_MODEL_ID",
  "messages": [
    {"role": "system", "content": "Return JSON only, without Markdown."},
    {"role": "user", "content": "Extract product name and quantity: order 3 blue keyboards."}
  ],
  "response_format": {"type": "json_object"}
}
```

Do not rely on the prompt alone to guarantee the format. Even with HTTP 200, catch empty content, truncated JSON, type errors, and missing fields.

## Server-side validation

```javascript theme={null}
function parseOrder(text) {
  const value = JSON.parse(text);
  if (typeof value.product !== "string") throw new Error("product is required");
  if (!Number.isInteger(value.quantity) || value.quantity < 1) {
    throw new Error("quantity must be a positive integer");
  }
  return value;
}
```

## Truncation and finish reason

When `finish_reason` indicates a length limit, the JSON may be missing closing braces. Do not attempt to silently concatenate untrusted JSON; increase the reasonable output limit, reduce the schema, or re-request. In tool call scenarios, read the tool parameters rather than treating the content as JSON.

## Schema design suggestions

* Keep field names short and unambiguous.
* Limit enums to the necessary range.
* Avoid deep nesting and unbounded arrays.
* Use strings for amounts, times, and identifiers, and validate their format separately.
* State explicitly which fields allow `null`.
* Do not let the model decide permissions, final prices, or security policy.

Next: [Tool calls](https://apione.ai/docs/en/api/tool-calls.md), [Chat Completions](https://apione.ai/docs/en/models/chat.md), [Model parameters](https://apione.ai/docs/en/models/parameters.md), [Request reliability](https://apione.ai/docs/en/api/request-reliability.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.