> For the complete documentation index, see [llms.txt](https://docs.stackai.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stackai.com/technical-reference/models-agents-and-skills/structured-outputs-and-schema-validation.md).

# Structured Outputs and Schema Validation

Structured output defines fields and value types for a model response. Use it when another step needs to read specific values instead of interpreting free-form prose.

{% embed url="<https://1957915746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2FLXKejw4ss7tyf5sBtZOM%2Fstructured-outputs-and-schema-validation.mp4?alt=media&token=d66237c8-4429-4e6e-8e92-11f3f202d180>" %}
Inspect a response schema, run the workflow, and check the returned fields and values.
{% endembed %}

## Before you begin

A model and node that support the required output format.

## Output formats and validation

| Term              | Definition                                                                                                                                                  |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Structured output | A response arranged into defined fields rather than free-form prose. Check both the field structure and the meaning of its values.                          |
| Schema            | A definition of fields, types, required values, and supported constraints. Use it to validate the shape of data; it does not establish factual correctness. |
| Null              | An explicit JSON value indicating no value. It can differ from an omitted field, an empty string, or an empty collection.                                   |

## Configuration options

| Option      | Purpose                                                                        | Behavior                                                                           |
| ----------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------- |
| JSON Object | A JSON-formatted response mode where supported by the selected model.          | Valid JSON alone does not impose every field or type required by your application. |
| JSON Schema | A schema used to specify the supported structure and constraints of an object. | Use schema validation in addition to reviewing factual accuracy.                   |

## Configure structured output

1. Select the structured output format and define the required fields.
2. Describe the meaning of each field in the instructions.
3. Run the node and inspect both schema validity and the accuracy of the values.

<figure><img src="https://1957915746-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2FaYBweQyYjrpYMMJCFBWW%2Fresponse-format-options.png?alt=media" alt="Response format options controls in StackAI" width="800"><figcaption><p>Use Text for a free-form response. JSON Object requests a JSON object without specifying all of its fields. JSON Schema defines the required structure, field types, and constraints. A structurally valid response can still contain incorrect facts; validate the content before using it in a consequential action.</p></figcaption></figure>

The next step can read the expected fields from the generated object.

## Behavior and limitations

Valid JSON is not necessarily valid against your schema. Schema-valid data is not necessarily factually correct. Handle missing evidence explicitly rather than forcing the model to invent required values. A display template formats values; it does not replace validation of the underlying response.

## Related resources

[Model Settings and Supported Capabilities](https://docs.stackai.com/technical-reference/models-agents-and-skills/model-settings-and-supported-capabilities.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stackai.com/technical-reference/models-agents-and-skills/structured-outputs-and-schema-validation.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
