Package akka.javasdk

Interface TextSanitizer


public interface TextSanitizer
A text sanitizer masks the sensitive parts of a text. Can be implemented with rules or regex, a detection model, or an external service — the implementation is just user code calling out to whatever it needs.

An implementation has a public constructor into which the platform's managed dependencies can be injected — including a SanitizerContext for the sanitizer's configured name and config section, and a ClassifierClient for a sanitizer that masks what a configured classifier detects.

The runtime calls a sanitizer for the text of the entries it is configured for: the text of an agent's model request, and what an agent's tool returned. Application code calls it by name through an injected SanitizerClient. To mask log messages, implement LogSanitizer.

Text sanitizers are enabled with configuration; see sanitization documentation.

  • Method Details

    • sanitize

      String sanitize(String text)
      Returns text with its sensitive parts masked, or text itself when there is nothing to mask.

      This is the method to implement. It may block: sanitizers are always invoked on virtual threads. The text can be of any size, from a single tool result to a whole model request.

      A thrown exception fails the call the text was masked for, so unmasked text is never passed on.

      Returns:
      the masked text
    • sanitizeAsync

      default CompletionStage<String> sanitizeAsync(String text)
      Async variant of sanitize(java.lang.String), for implementations that prefer composing futures.

      The default implementation delegates to sanitize(java.lang.String). When this method is overridden, sanitize(java.lang.String) is no longer used, and it is then safe to have it throw UnsupportedOperationException or return null.

      Returns:
      a CompletionStage with the masked text