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:
OutputParser<T>
,Parser<T>
,FormatProvider
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
-
Constructor Summary
ConstructorDescriptionBeanOutputParser
(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 and a custom object mapper. -
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 and a custom object mapper.- Parameters:
clazz
- The target type's class.objectMapper
- Custom object mapper for JSON operations.
-
-
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.
-