spring-projects / spring-projects/spring-ai
ThinkingTagCleaner.Builder.withoutDefaultPatterns() does not disable default patterns
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 5
Description
Bug description
ThinkingTagCleaner.Builder#withoutDefaultPatterns() does not take effect unless a custom pattern is added afterwards, so the default patterns can be silently retained even though the method is documented to "Disable default patterns".
The builder clears the defaults lazily — only inside addPattern(...), and only the first time it runs after withoutDefaultPatterns() was called:
public Builder withoutDefaultPatterns() {
this.useDefaultPatterns = false; // does not clear the defaults
return this;
}
public Builder addPattern(String patternString) {
Assert.hasText(patternString, "patternString cannot be empty");
if (!this.useDefaultPatterns) { // clearing happens here, lazily
this.patterns.clear();
this.useDefaultPatterns = true;
}
this.patterns.add(Pattern.compile(patternString, Pattern.CASE_INSENSITIVE));
return this;
}
If addPattern(...) is never called, the defaults are never cleared.
Minimal reproducible example
ResponseTextCleaner cleaner = ThinkingTagCleaner.builder()
.withoutDefaultPatterns()
.build();
String result = cleaner.clean("<thinking>secret</thinking>visible");
Expected: the default <thinking> pattern is disabled, so it is not applied (and, since the cleaner now has no patterns, building should fail fast with the constructor's existing patterns cannot be empty assertion).
Actual: returns "visible" — the default <thinking> pattern was still applied, proving withoutDefaultPatterns() had no effect.
Environment
- Spring AI version:
2.0.1-SNAPSHOT(main); class is@since 1.1.0
I'd be happy to submit a PR (with regression tests) that clears the defaults immediately in withoutDefaultPatterns() and removes the redundant lazy-clear flag.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating ThinkingTagCleaner.Builder and inspect withoutDefaultPatterns(), addPattern(), and build(), especially the constructor assertion that patterns cannot be empty. Add regression coverage for building after disabling defaults without adding a custom pattern, and confirm the defaults are no longer applied and the existing empty-pattern assertion occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100