liveBook · Manning

Entity()

As explained in Spring AI in Action

entity() is a Spring AI ChatClient method that requests a language-model response converted to a specified Java type.

entity() is a Spring AI ChatClient method for requesting an LLM response and converting it into a specified Java type. Passing Answer.class replaces String-oriented content extraction with object binding. section 3.4.2

Calling entity(Answer.class) changes prompt handling in two ways:

  • Spring AI adds formatting instructions derived from the Answer record and its properties. section 3.4.2
  • Spring AI parses the returned JSON object and binds it to Answer. section 3.4.2

Obtaining an Answer object

In a board-game service, change the response operation from content() to entity(Answer.class) so the ChatClient returns an Answer instead of a String. section 3.4.2

How Spring AI in Action covers it

How deep it goes
Explains prompt decoration, JSON parsing, and binding, but stops short of describing converter internals.
Examples
Uses a board-game Answer record and generated JSON containing answer and gameTitle properties.
What it assumes
Assumes familiarity with ChatClient and Java types while deriving formatting requirements from the target record.
What you can do after
Build structured ChatClient results by replacing content() with entity(Answer.class).
How it connects
Connects ChatClient with output conversion, Java records, JSON, and JSON Schema.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.