Skip to content

Clean ListOutputConverter responses with the shared ResponseTextCleaner - #6975

Open
anjeongkyun wants to merge 2 commits into
spring-projects:mainfrom
anjeongkyun:fix/list-output-converter-code-fence
Open

anjeongkyun wants to merge 2 commits into
spring-projects:mainfrom
anjeongkyun:fix/list-output-converter-code-fence

Conversation

@anjeongkyun

Copy link
Copy Markdown

Builds on #6941, which adds ResponseTextCleaner.defaultCleaner(). Only the last commit here is new.

ListOutputConverter doesn't clean the response at all, so a fenced list comes back with the markers as elements:

"```\nfoo, bar, baz\n```"     -> [```, foo, bar, baz, ```]
"```csv\nfoo, bar, baz\n```"  -> [```csv, foo, bar, baz, ```]
"<think>reasoning</think>\nfoo, bar, baz" -> [<think>reasoning</think>\nfoo, bar, baz]

It fails more quietly than the Map case in #6941: no exception, just extra elements in the caller's list.

I mentioned this in #6941 and left it out because every cleaner in the chain trims, and csvWithOnlyWhitespace asserts that " \t\n " converts to a single blank element rather than an empty list. That turned out to be avoidable: cleaning only when the cleaned text is non-empty keeps the blank case on the original string, so that test passes unchanged.

String cleaned = this.textCleaner.clean(text);
if (cleaned != null && !cleaned.isEmpty()) {
    text = cleaned;
}

No existing test needed changing. The four new cases fail before the change with the markers present in the list, and mvn -pl spring-ai-model test is green (790 tests).

Signed-off-by: anjeongkyun <anwjdrbs123@gmail.com>
Signed-off-by: anjeongkyun <anwjdrbs123@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants