Interface TextSanitizer
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 Summary
Modifier and TypeMethodDescriptionReturnstextwith its sensitive parts masked, ortextitself when there is nothing to mask.default CompletionStage<String> sanitizeAsync(String text) Async variant ofsanitize(java.lang.String), for implementations that prefer composing futures.
-
Method Details
-
sanitize
Returnstextwith its sensitive parts masked, ortextitself 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
Async variant ofsanitize(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 throwUnsupportedOperationExceptionor returnnull.- Returns:
- a CompletionStage with the masked text
-