Package org.springframework.ai.parser
Class BeanOutputParser<T>
java.lang.Object
org.springframework.ai.parser.BeanOutputParser<T>
- Type Parameters:
T
- The target type to which the output will be converted.
- All Implemented Interfaces:
FormatProvider
,OutputParser<T>
,Parser<T>
An implementation of
OutputParser
that transforms the LLM output to a specific
object type using JSON schema. This parser works by generating a JSON schema based on a
given Java class, which is then used to validate and transform the LLM output into the
desired type.- Author:
- Mark Pollack, Christian Tzolov, Sebastian Ullrich, Kirk Lund
-
Constructor Summary
ConstructorsConstructorDescriptionBeanOutputParser
(Class<T> clazz) Constructor to initialize with the target type's class.BeanOutputParser
(Class<T> clazz, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Constructor to initialize with the target type's class, a custom object mapper, and a line endings normalizer to ensure consistent line endings on any platform. -
Method Summary
Modifier and TypeMethodDescriptionProvides the expected format of the response, instructing that it should adhere to the generated JSON schema.protected com.fasterxml.jackson.databind.ObjectMapper
Configures and returns an object mapper for JSON operations.
-
Constructor Details
-
BeanOutputParser
Constructor to initialize with the target type's class.- Parameters:
clazz
- The target type's class.
-
BeanOutputParser
Constructor to initialize with the target type's class, a custom object mapper, and a line endings normalizer to ensure consistent line endings on any platform.- Parameters:
clazz
- The target type's class.objectMapper
- Custom object mapper for JSON operations. endings.
-
-
Method Details
-
parse
-
getObjectMapper
protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()Configures and returns an object mapper for JSON operations.- Returns:
- Configured object mapper.
-
getFormat
Provides the expected format of the response, instructing that it should adhere to the generated JSON schema.- Specified by:
getFormat
in interfaceFormatProvider
- Returns:
- The instruction format string.
-