Class StructuredOutputValidationAdvisor.Builder
java.lang.Object
org.springframework.ai.chat.client.advisor.StructuredOutputValidationAdvisor.Builder
- Enclosing class:
- StructuredOutputValidationAdvisor
Builder for
StructuredOutputValidationAdvisor.-
Method Summary
Modifier and TypeMethodDescriptionadvisorOrder(int advisorOrder) Sets the advisor order.build()Builds the StructuredOutputValidationAdvisor.jsonMapper(tools.jackson.databind.json.JsonMapper jsonMapper) Sets theJsonMapperused for JSON parsing and validation.maxRepeatAttempts(int repeatAttempts) Sets the maximum number of retry attempts after a validation failure.outputJsonSchema(String outputJsonSchema) Sets a pre-generated JSON schema string to validate against.outputType(Type outputType) Sets the expected output type; the JSON schema is derived automatically.outputType(org.springframework.core.ParameterizedTypeReference<T> outputType) Sets the expected output type; the JSON schema is derived automatically.outputType(tools.jackson.core.type.TypeReference<T> outputType) Sets the expected output type; the JSON schema is derived automatically.
-
Method Details
-
advisorOrder
Sets the advisor order. Must be strictly betweenOrdered.HIGHEST_PRECEDENCEandOrdered.LOWEST_PRECEDENCE. Defaults toLOWEST_PRECEDENCE - 2000.- Parameters:
advisorOrder- the advisor order- Returns:
- this builder
-
outputType
Sets the expected output type; the JSON schema is derived automatically. Mutually exclusive withoutputJsonSchema(String).- Parameters:
outputType- the expected output type- Returns:
- this builder
-
outputType
public <T> StructuredOutputValidationAdvisor.Builder outputType(tools.jackson.core.type.TypeReference<T> outputType) Sets the expected output type; the JSON schema is derived automatically. Mutually exclusive withoutputJsonSchema(String).- Type Parameters:
T- the type parameter- Parameters:
outputType- the expected output type- Returns:
- this builder
-
outputType
public <T> StructuredOutputValidationAdvisor.Builder outputType(org.springframework.core.ParameterizedTypeReference<T> outputType) Sets the expected output type; the JSON schema is derived automatically. Mutually exclusive withoutputJsonSchema(String).- Type Parameters:
T- the type parameter- Parameters:
outputType- the expected output type- Returns:
- this builder
-
outputJsonSchema
Sets a pre-generated JSON schema string to validate against. Mutually exclusive with theoutputTypemethods.- Parameters:
outputJsonSchema- the JSON schema as a string- Returns:
- this builder
-
maxRepeatAttempts
Sets the maximum number of retry attempts after a validation failure. Zero means no retries; the model is called exactly once. Defaults to 3.- Parameters:
repeatAttempts- the number of retry attempts, must be >= 0- Returns:
- this builder
-
jsonMapper
public StructuredOutputValidationAdvisor.Builder jsonMapper(tools.jackson.databind.json.JsonMapper jsonMapper) Sets theJsonMapperused for JSON parsing and validation. Defaults toJacksonUtils.getDefaultJsonMapper().- Parameters:
jsonMapper- the JSON mapper- Returns:
- this builder
-
build
Builds the StructuredOutputValidationAdvisor.- Returns:
- a new StructuredOutputValidationAdvisor instance
- Throws:
IllegalArgumentException- if neither outputType nor outputJsonSchema is set, or if both are set
-