> For the complete documentation index, see [llms.txt](https://anyint.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anyint.gitbook.io/docs/features/structured-outputs.md).

# structured outputs

Structured output is a product pattern, not one dedicated AnyInt endpoint. The exact mechanism depends on the compatibility family and model you choose.

## Recommended approach

1. define the schema you need first
2. tell the model exactly what keys and types to return
3. validate the returned JSON in your application
4. keep a repair or retry path for malformed output

## Good use cases

* extraction pipelines
* workflow orchestration
* agent state handoff
* form or UI generation

## Cross-family guidance

| Family               | Recommended pattern                                             |
| -------------------- | --------------------------------------------------------------- |
| OpenAI-compatible    | ask for a strict JSON object and validate it server-side        |
| Anthropic-compatible | return JSON in a text block and validate it after parsing       |
| Gemini-compatible    | keep `contents[].parts[]` simple and ask for a JSON-only answer |

## Example prompt pattern

```json
{
  "task": "extract_invoice",
  "fields": {
    "invoice_number": "string",
    "currency": "string",
    "total": "number"
  }
}
```

Use a prompt that clearly says:

* return valid JSON only
* do not add markdown fences
* do not add explanatory text

## Important note

Support for strict JSON control can differ by model. Confirm the behavior with the specific model ID you plan to run in production, then enforce schema validation on your side.
