Class StructuredOutputValidationAdvisor.Builder

java.lang.Object
org.springframework.ai.chat.client.advisor.StructuredOutputValidationAdvisor.Builder
Enclosing class:
StructuredOutputValidationAdvisor

public static final class StructuredOutputValidationAdvisor.Builder extends Object
  • Method Details

    • advisorOrder

      public StructuredOutputValidationAdvisor.Builder advisorOrder(int advisorOrder)
      Sets the advisor order. Must be strictly between Ordered.HIGHEST_PRECEDENCE and Ordered.LOWEST_PRECEDENCE. Defaults to LOWEST_PRECEDENCE - 2000.
      Parameters:
      advisorOrder - the advisor order
      Returns:
      this builder
    • outputType

      public StructuredOutputValidationAdvisor.Builder outputType(Type outputType)
      Sets the expected output type; the JSON schema is derived automatically. Mutually exclusive with outputJsonSchema(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 with outputJsonSchema(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 with outputJsonSchema(String).
      Type Parameters:
      T - the type parameter
      Parameters:
      outputType - the expected output type
      Returns:
      this builder
    • outputJsonSchema

      public StructuredOutputValidationAdvisor.Builder outputJsonSchema(String outputJsonSchema)
      Sets a pre-generated JSON schema string to validate against. Mutually exclusive with the outputType methods.
      Parameters:
      outputJsonSchema - the JSON schema as a string
      Returns:
      this builder
    • maxRepeatAttempts

      public StructuredOutputValidationAdvisor.Builder maxRepeatAttempts(int repeatAttempts)
      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 the JsonMapper used for JSON parsing and validation. Defaults to JacksonUtils.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