diff --git a/spring-ai-client-chat/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java b/spring-ai-client-chat/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java index 64b64a77a78..0c4ff3c63dc 100644 --- a/spring-ai-client-chat/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java +++ b/spring-ai-client-chat/src/main/java/org/springframework/ai/converter/BeanOutputConverter.java @@ -61,18 +61,18 @@ */ public class BeanOutputConverter implements StructuredOutputConverter { - private final Logger logger = LoggerFactory.getLogger(BeanOutputConverter.class); + protected final Logger logger = LoggerFactory.getLogger(BeanOutputConverter.class); /** * The target class type reference to which the output will be converted. */ - private final Type type; + protected final Type type; /** The object mapper used for deserialization and other JSON operations. */ private final ObjectMapper objectMapper; /** Holds the generated JSON schema for the target type. */ - private String jsonSchema; + protected String jsonSchema; /** * Constructor to initialize with the target type's class. @@ -128,7 +128,7 @@ private BeanOutputConverter(Type type, ObjectMapper objectMapper) { /** * Generates the JSON schema for the target type. */ - private void generateSchema() { + protected void generateSchema() { JacksonModule jacksonModule = new JacksonModule(JacksonOption.RESPECT_JSONPROPERTY_REQUIRED, JacksonOption.RESPECT_JSONPROPERTY_ORDER); SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder( @@ -206,7 +206,16 @@ protected ObjectMapper getObjectMapper() { */ @Override public String getFormat() { - String template = """ + return String.format(getFormatTemplate(), this.jsonSchema); + } + + /** + * Provides the template for the format instruction. Subclasses can override this + * method to customize the instruction format. + * @return The format template string. + */ + protected String getFormatTemplate() { + return """ Your response should be in JSON format. Do not include any explanations, only provide a RFC8259 compliant JSON response following this format without deviation. Do not include markdown code blocks in your response. @@ -214,7 +223,6 @@ public String getFormat() { Here is the JSON Schema instance your output must adhere to: ```%s``` """; - return String.format(template, this.jsonSchema); } /**