> 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/guides-and-quickstarts/workflow-builder/structured-outputs-and-templates.md).

# Structured outputs and templates

Structured outputs give model responses a defined set of fields. Templates combine those fields with fixed text. Use these features when later steps need predictable data or a consistent presentation.

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSQ1Sgy933krTyK0S4JpP%2Fuploads%2FlxKAYMxjy2hyLcpzTFpC%2FG023.mp4?alt=media&token=4dc173c8-f46d-4a1d-a477-737a3364c549>" %}

## Connect the processing steps

Connect the input, model, and output, then describe the information the model must extract.

![Input, model, and output extraction path](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/mUsX7zK8fCe5mAxBlSZt/assets/g023-g023-01-canvas.png)

Separate the extraction rules from the way you eventually want to display the result.

## Understand the field types

A structured response is like a row with named columns. A **string** is text, a **number** is numeric data, a **boolean** is true or false, and an **array** is a list. A JSON Schema describes the allowed fields and types; it is not the answer itself.

Start with [First input to output workflow](/guides-and-quickstarts/workflow-builder/first-input-to-output-workflow.md) if you do not yet have a connected input, model, and output. Choose a model that supports **JSON Schema**; the available answer formats depend on the model.

## Define the response fields

In the model's Settings, set Answer Format to JSON Schema.

![JSON Schema answer format setting](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/U3zCbCsZMzpLGhv7LFzK/assets/g023-g023-02-format.png)

Use a schema when later steps need specific field names and types.

Define the fields, their data types, and which fields are required.

![Schema fields, types, and required properties](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/sHVxen9Jjz6K1ntJVyQA/assets/g023-g023-03-schema.png)

Use allowed values and additional-property rules when you need to constrain the response further.

## Start with a small schema

Use two fields for an initial extraction task: `summary` as text and `amount` as a number. In the schema editor, this is:

```json
{
  "type": "object",
  "properties": {
    "summary": {"type": "string"},
    "amount": {"type": "number"}
  },
  "required": ["summary", "amount"],
  "additionalProperties": false
}
```

For the first check, supply text that contains one explicit amount. Tell the model to return a brief summary and that exact amount. An amount written as `12` is a number; `"12"` is text. Decide how your real task should handle a missing amount before using this required-field schema more broadly. A required field does not justify inventing a value.

Then use [Map variables and expressions](/guides-and-quickstarts/workflow-builder/map-variables-and-expressions.md) to select `summary` or `amount` from the actual model result.

## Review the structured result

Run the workflow and inspect the structured output.

![Structured model output](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/dPWuIObgGKLDZc7xtzg0/assets/g023-g023-04-json-result.png)

Confirm that the keys, types, and values match the schema before using them in later steps.

## Format the result with a template

Add a Template to present individual fields in readable form.

![Template containing live field references](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/Xi4rB91dCHRLBcTsLFrM/assets/g023-g023-05-template.png)

Insert field references with the picker and expression editor so each value updates on the next run.

Run the formatted path and inspect Template and Output.

![Formatted Template and Output results](https://content.gitbook.com/content/SQ1Sgy933krTyK0S4JpP/blobs/uAVFWSBfhjLA6X7J2uVE/assets/g023-g023-06-formatted-result.png)

The template controls presentation while the schema defines the structure produced by the model.

## Important behavior

Use Text for a normal written answer, JSON Object for a JSON response, or JSON Schema for defined fields and types.

A template changes how values are displayed. It does not correct inaccurate source values.


---

# 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/guides-and-quickstarts/workflow-builder/structured-outputs-and-templates.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.
