Suppress Thinking Converter
class SuppressThinkingConverter<T>(delegate: <Error class: unknown class><T>, thinkBlockFinders: List<ThinkBlockFinder> = listOf(FindMarkupThinkBlock, FindPrefixThinkBlock))
A decorator for Spring AI's StructuredOutputConverter that cleans up LLM outputs by removing "thinking" blocks.
Spring AI's StructuredOutputConverter is designed to parse structured formats (like JSON) from LLM outputs, but it can fail if the output contains additional text like reasoning blocks. For example, if an LLM returns:
<think>
Let me think about what information to include in this person object.
The name should be "John Doe" and the age should be 30.
</think>
{"name": "John Doe", "age": 30}
Content copied to clipboard
A standard converter would fail to parse this as valid JSON.
This decorator sanitizes the input by removing any content enclosed in
Usage
Wrap any existing StructuredOutputConverter with this class:
val originalConverter = BeanOutputConverter(Person::class.java)
val thinkingAwareConverter = SuppressThinkingConverter(originalConverter)
Content copied to clipboard
Parameters
T
The target type that the delegate converter produces
Constructors
Link copied to clipboard
constructor(delegate: <Error class: unknown class><T>, thinkBlockFinders: List<ThinkBlockFinder> = listOf(FindMarkupThinkBlock, FindPrefixThinkBlock))