Class AssistantTextSanitizer

java.lang.Object
smile.llm.tool.AssistantTextSanitizer

public final class AssistantTextSanitizer extends Object
Strips chat-template / tool / thinking markup from assistant text so API and streaming clients never see role specials or raw tool XML mixed into visible content.
  • Method Details

    • sanitize

      public static String sanitize(String text)
      Cleans assistant-visible text for API / SSE content fields.

      Removes thinking spans, tool-call / tool-response blocks, and chat specials. When an open <think> was part of the prompt (so the completion only has a closing tag), keeps the text after the last </think>.

      Parameters:
      text - raw decoded generation; may be null.
      Returns:
      cleaned text, or null when empty after cleaning.
    • stripToolCalls

      public static String stripToolCalls(String text)
      Removes tool-call XML from message content used when re-encoding history that already has structured tool_calls.
      Parameters:
      text - message content; may be null.
      Returns:
      content without tool-call blocks (may be empty).