Skip to contents

Replaces the values of registered secrets (and their URL-encoded, JSON-escaped and base64 forms) with markers such as [secret:TYPESAFE_API_KEY] and, except for the user_data profile, applies the pattern layer (provider key shapes, bearer tokens, URL passwords, private keys, NAME=value lines). gptr applies the same redactor at every sink; plugins and users call it for their own logs. Redaction is idempotent and never fails on invalid UTF-8 (it then matches bytewise). Opaque replay fields of messages (signatures, encrypted reasoning) are never modified.

Usage

gptr_redact(
  x,
  profile = c("persist", "stream", "context", "code", "user_data")
)

Arguments

x

A character vector, or a list (redacted recursively).

profile

The sink profile: "persist" (files), "stream" (console and events), "context" (text sent to a model), "code" (R code for a history document: a string literal whose value is a registered secret becomes Sys.getenv("NAME")) or "user_data" (registered values only).

Value

x with secrets replaced by markers; the same type and attributes as x.

Options

gptr.redact_min_chars (8): shortest value that is value-redacted. gptr.redact_patterns (TRUE): the pattern layer; values are always redacted. gptr.stream_hold_max (4096): streaming hold-back cap in characters. gptr.env_export (TRUE): default of gptr_env(set_env =). gptr.prompt_secrets ("redact"): secret-looking text in prompts, "redact" or "ask". gptr.secret_guard (TRUE): guarded secret reads ask even in auto mode.

Examples

gptr_redact("Authorization: Bearer abcdef0123456789abcdef")
#> [1] "Authorization: Bearer [secret:auth-header]"
gptr_redact(list(note = "db at postgres://analyst:hunter2x@db.example.test/prod"))
#> $note
#> [1] "db at postgres://analyst:[secret:url-password]@db.example.test/prod"
#>