Skip to main content

Structured Output

Structured Output is essential for agents. People are familiar with the chat UI provided by ChatGPT, where the AI service mostly returns text and images. When building agents, we want to deal with structured outputs, which makes the output very easy to be consumed by code. Most LLMs support JSON as the output format.

Enabling structured output is very straightforward. We just tell the LLM to output JSON content in the prompt. We also need to include the JSON schema of the JSON output, so LLM will generate JSON data satisfying the schema.

For structured output support in Spring AI, see this article.