Skip to contents

redaction_strategy() controls how scanner spans are rewritten in text_clean. The default strategy preserves the original package behavior: every matched span is replaced by [REDACTED].

Usage

redaction_strategy(
  operator = c("replace", "mask", "hash", "drop", "keep"),
  replacement = "[REDACTED]",
  mask = "*",
  hash_algo = "sha256",
  hash_prefix = 12L
)

Arguments

operator

One of "replace", "mask", "hash", "drop", or "keep".

replacement

Replacement text used by operator = "replace".

mask

Single-character mask used by operator = "mask".

hash_algo

Digest algorithm passed to digest::digest() for operator = "hash".

hash_prefix

Number of digest characters to keep in hash labels.

Value

A shieldr_redaction_strategy object.

Details

Redaction only applies to findings that include start and end character offsets. Regex rules and some semantic reviewer schemas can provide spans. Function rules and synthetic findings can still change score and action, but they do not rewrite text unless they include span metadata.

Supported operators:

  • "replace": replace the span with replacement.

  • "mask": replace each character in the span with mask.

  • "hash": replace the span with a short deterministic digest label.

  • "drop": remove the span.

  • "keep": leave the span unchanged while still returning findings.

Hash redaction is deterministic for the same matched string and algorithm, which can help link repeated values without storing the original secret. It is not anonymization and should still be treated as sensitive metadata.

Examples

scan_prompt(
  "Email neel@example.com",
  redaction = redaction_strategy("mask", mask = "*")
)
#> llmshieldr report
#> action: redact
#> risk_score: 0.300
#> findings: 1

scan_prompt(
  "Email neel@example.com",
  redaction = redaction_strategy("hash")
)
#> llmshieldr report
#> action: redact
#> risk_score: 0.300
#> findings: 1