<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/a-guide-to-structured-output-in-spring-ai-fhz21l4ic" -->

---
title: A Guide to Structured Output in Spring AI | daily.dev
description: A tutorial walks through Spring AI's structured output support, showing how to configure a ChatClient bean and convert LLM responses directly into Java...
canonical: https://daily.dev/posts/a-guide-to-structured-output-in-spring-ai-fhz21l4ic
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: A Guide to Structured Output in Spring AI | daily.dev
og:description: A tutorial walks through Spring AI's structured output support, showing how to configure a ChatClient bean and convert LLM responses directly into Java...
og:url: https://daily.dev/posts/a-guide-to-structured-output-in-spring-ai-fhz21l4ic
og:image: https://api.daily.dev/og/posts/fhZ21L4iC.png
og:image:alt: A Guide to Structured Output in Spring AI
og:image:width: 1200
og:image:height: 630
og:locale: en
---

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

# A Guide to Structured Output in Spring AI

**[Baeldung](https://daily.dev/sources/baeldung)** · 9 min read · 1 upvotes · 0 comments

## Summary

A tutorial walks through Spring AI's structured output support, showing how to configure a ChatClient bean and convert LLM responses directly into Java records, lists, and maps instead of parsing raw strings. It covers self-correcting output via client-side validateSchema() and provider-side useProviderStructuredOutput(), manual conversion using ChatModel with BeanOutputConverter, and building a custom StructuredOutputConverter for YAML responses.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://feeds.feedblitz.com/~/970058585/0/baeldung>

## Questions this post answers

### How do I get Spring AI's ChatClient to return a Java object instead of raw text from an LLM?

Call the entity() method on the ChatClient response spec, passing your target class, such as chatClient.prompt("...").call().entity(Recipe.class). Spring AI generates a JSON schema from the type, appends format instructions to the prompt, and deserializes the model's reply into a fully populated instance without manual parsing.

_daily.dev surfaces practical Spring AI patterns like this for developers wiring LLMs into Java apps._

### How can I make Spring AI retry when the LLM response doesn't match my expected schema?

Pass a lambda to entity() calling spec.validateSchema(), which checks the response against the generated JSON schema before deserializing and resends validation errors to the model on failure, retrying up to three times by default. The retry limit can be raised, for example to five, via a StructuredOutputValidationAdvisor registered as a default advisor on the ChatClient bean.

_Developers hardening LLM integrations can track patterns like schema retries on daily.dev._

### How do I get a list of strings back from an LLM call in Spring AI instead of a JSON object?

Pass a ListOutputConverter instance to the entity() method, for example chatClient.prompt("List 5 popular vegetarian dishes.").call().entity(new ListOutputConverter()). This asks the model for a comma-separated list rather than JSON and splits the reply into a List of String values, avoiding the need for a full schema.

_daily.dev helps developers comparing structured-output approaches in Spring AI stay on top of these details._

## Similar posts on daily.dev

- [Spring AI : Structured Output](https://daily.dev/posts/spring-ai-structured-output-vawtiuqjk) · SivaLabs · 4 upvotes · 1 comments
- [Spring AI tutorial: Get started with Spring AI](https://daily.dev/posts/spring-ai-tutorial-get-started-with-spring-ai-phjfbwkwg) · InfoWorld · 0 upvotes · 0 comments
- [Structured Outputs in LLM Applications: A Complete C\# Developer Guide](https://daily.dev/posts/structured-outputs-in-llm-applications-a-complete-c-developer-guide-yys1kk1ad) · C\# Corner · 3 upvotes · 0 comments

---

Tags: [#llm](https://daily.dev/tags/llm), [#java](https://daily.dev/tags/java), [#spring-ai](https://daily.dev/tags/spring-ai)

[View this post on daily.dev](https://daily.dev/posts/a-guide-to-structured-output-in-spring-ai-fhz21l4ic)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"A Guide to Structured Output in Spring AI","url":"https://daily.dev/posts/a-guide-to-structured-output-in-spring-ai-fhz21l4ic","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/a-guide-to-structured-output-in-spring-ai-fhz21l4ic"},"datePublished":"2026-09-25T05:20:36.129Z","dateModified":"2026-10-15T02:22:45.418Z","description":"A tutorial walks through Spring AI's structured output support, showing how to configure a ChatClient bean and convert LLM responses directly into Java...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f3936b726a3720f3151636207d7cddad?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/f3936b726a3720f3151636207d7cddad?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Baeldung","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Baeldung","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/52cccfb454d946c4b7dfa5e816f9e576","url":"https://daily.dev/sources/baeldung"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/a-guide-to-structured-output-in-spring-ai-fhz21l4ic","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"llm,java,spring-ai","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Baeldung","item":"https://daily.dev/sources/baeldung"},{"@type":"ListItem","position":3,"name":"A Guide to Structured Output in Spring AI"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/a-guide-to-structured-output-in-spring-ai-fhz21l4ic#faq","mainEntity":[{"@type":"Question","name":"How do I get Spring AI's ChatClient to return a Java object instead of raw text from an LLM?","acceptedAnswer":{"@type":"Answer","text":"Call the entity() method on the ChatClient response spec, passing your target class, such as chatClient.prompt(\"...\").call().entity(Recipe.class). Spring AI generates a JSON schema from the type, appends format instructions to the prompt, and deserializes the model's reply into a fully populated instance without manual parsing. daily.dev surfaces practical Spring AI patterns like this for developers wiring LLMs into Java apps."}},{"@type":"Question","name":"How can I make Spring AI retry when the LLM response doesn't match my expected schema?","acceptedAnswer":{"@type":"Answer","text":"Pass a lambda to entity() calling spec.validateSchema(), which checks the response against the generated JSON schema before deserializing and resends validation errors to the model on failure, retrying up to three times by default. The retry limit can be raised, for example to five, via a StructuredOutputValidationAdvisor registered as a default advisor on the ChatClient bean. Developers hardening LLM integrations can track patterns like schema retries on daily.dev."}},{"@type":"Question","name":"How do I get a list of strings back from an LLM call in Spring AI instead of a JSON object?","acceptedAnswer":{"@type":"Answer","text":"Pass a ListOutputConverter instance to the entity() method, for example chatClient.prompt(\"List 5 popular vegetarian dishes.\").call().entity(new ListOutputConverter()). This asks the model for a comma-separated list rather than JSON and splits the reply into a List of String values, avoiding the need for a full schema. daily.dev helps developers comparing structured-output approaches in Spring AI stay on top of these details."}}]}
```

