WithExampleConverter

class WithExampleConverter<T>(delegate: <Error class: unknown class><T>, outputClass: Class<T>, ifPossible: Boolean, generateExamples: Boolean)

Decorator for Spring's StructuredOutputConverter that adds few-shot examples to the output format description.

Few-shot examples are often used in prompt engineering to help AI models understand the expected output format by providing concrete example outputs. This converter generates such examples automatically using dummy data and injects them into the format description returned by [getFormat()].

Parameters

T

the output type for the converter

delegate

the underlying output converter to which conversion is delegated

outputClass

the class type for which dummy example instances will be generated

ifPossible

determines whether to include both success and failure examples (true) or just a simple example (false)

generateExamples

whether to generate examples or not. This class does nothing if it is false Wraps an existing StructuredOutputConverter with this class to enhance its format description for LLM prompting.

Constructors

Link copied to clipboard
constructor(delegate: <Error class: unknown class><T>, outputClass: Class<T>, ifPossible: Boolean, generateExamples: Boolean)

Functions

Link copied to clipboard
open fun convert(source: String): T?

Delegates conversion to the underlying delegate.

Link copied to clipboard
open fun getFormat(): String

Returns a format description string, augmented with few-shot examples.