PII Redaction Configuration
Configure kind = "pii_redaction" in plugins.toml. Use the reference tables to
look up settings, then use the worked examples to compare
input event data with the published result. For runtime placement and the
middleware comparison, refer to About.
For selection and preservation rules, refer to
Redaction Behavior.
There are two supported configuration forms:
- Profiles: Define one or more policies under
[[components.config.profiles]]. Every enabled profile covers all supported surfaces. - Single policy: Omit
profilesand define a policy directly under[components.config]. This form also provides surface flags.
Configuration Reference
All configuration keys use snake_case in plugins.toml and every binding.
A field shown as Unset has no configured value.
Component Shape
The plugin document has root version = 1. Each [[components]] entry uses:
The following shared fields belong under [components.config] in either form:
How to choose a codec
Choose the value by the API payload format:
Omit codec when the managed call supplies an active codec. A configured value
is only a fallback for a call without one; it cannot override an active codec.
Request policies use the active codec’s resolved decode/encode capability,
including runtime and opaque codecs. Normalized response projection requires a
recognized built-in codec because response codec capabilities are decode-only.
For a mixed-provider gateway, rely on the active codec of each call. The LLM request-only example shows the selector boundary for an OpenAI Chat Completions request.
Configuration validation policy
Set these fields under [components.config.policy] to control configuration
diagnostics. Each accepts ignore, warn, or error.
The global plugin policy can also affect the resolved policy. Refer to Configure for precedence.
Profile Settings
These fields belong under each [[components.config.profiles]] entry:
At least one profile must be enabled. Use either profiles or the single-policy settings; do not combine the two forms.
How profiles compose and execute
Profiles execute by ascending priority, with array order breaking ties.
Relay assigns internal positional names such as profile_0; no user-supplied
ID is required. Disabled profiles are still validated, but do not register
callbacks. At least one profile must be enabled.
Each enabled profile covers all supported sanitization surfaces. Profiles do
not accept input, output, mark, tool_input, or tool_output flags.
Use the single-policy form when you need those controls.
Profile lists concatenate during configuration layering, with higher-precedence profiles placed before lower-precedence profiles. Refer to Configure for file discovery and merge rules.
Built-in Settings
Use [components.config.profiles.builtin] for a profile, or
[components.config.builtin] for a single policy. The shipped builtin backend
implements deterministic actions and detector presets.
remove requires at least one selector. redact and regex_replace require
pattern or detector. For string actions, omitting both selector lists
selects every string leaf within each payload boundary. Selecting a container
with a string action does not select its descendant strings.
trajectory_context defines its own policy. Do not combine it with action,
pattern, detector, target selectors, or masking fields. It accepts
replacement, custom_mark_payload_policy, and
metric_string_attribute_allowlist.
Single-Policy Settings
When profiles is omitted, set these fields directly under [components.config]:
At least one surface flag must be enabled. These fields cannot be combined
with profiles; profile entries do not accept surface flags.
How surface flags apply to scope events
Scope-start processing is enabled when either input or tool_input is true;
scope-end processing is enabled when either output or tool_output is true.
On LLM and tool events, metadata follows the corresponding LLM or tool flag.
Other scope categories use the enabled shared scope-start or scope-end hook.
Local Backend Fields
Use [components.config.profiles.local] or [components.config.local]:
Refer to Available Backends for runtime availability and the current local-model implementation status.
Detector Presets
Supported detectors
The built-in detector presets are grouped into three deterministic families:
Common PII
emailphoneip_addressipv6url
Structured Secrets
api_keyuuidbearer_tokenjwtcredit_card
Cloud Credentials
aws_access_key_idaws_secret_access_keygcp_api_keyazure_storage_account_key
They are deterministic regex-backed helpers, not model inference.
Refer to Detector Matching for matching behavior and detector limitations.
CLI Editor Support
Setup and interactive editing
The CLI and primary language bindings register the component. Direct Rust
applications must call
nemo_relay_pii_redaction::component::register_pii_redaction_component() before
validating or initializing a pii_redaction component.
For file discovery, precedence, merge behavior, and gateway conflict rules, refer to Configure.
The NeMo Relay CLI plugin editor exposes pii_redaction directly through
nemo-relay plugins edit.
Use the editor when you want to:
- Toggle the component on or off
- Choose
builtinorlocal_model - Add and order multiple redaction profiles
- Enable or disable individual profiles
- Set the LLM
codec - Edit
builtinaction settings such asaction,target_paths,target_path_globs,pattern,detector,replacement, and masking fields - Edit
local.backendfor a runtime-provided future local-model backend
The editor preserves unknown fields when it rewrites an existing
pii_redaction component, so future or runtime-specific settings are not
discarded by the interactive edit flow.
If your policy needs callback code instead of editor or configuration fields, use raw middleware.
Redaction Behavior
The Redaction Behavior page explains how a valid configuration selects, transforms, and preserves observability data:
For backend availability, refer to Available Backends.
Worked Examples
Each tab contains a complete plugins.toml document and synthetic event data.
Published payload means the value delivered to subscribers and exporters;
real provider requests, tool arguments, and application results retain their
execution values. Tool results and result annotations are separate payloads.
Common Actions
Redact email
Redact API keys
Remove a field
Mask text
Hash text (SHA-256)
Regex replacement
Replace detected email addresses while preserving surrounding text.
Configuration
Input event payload: tool arguments
Published payload
No selectors are needed: the detector inspects every string leaf. Numeric values remain unchanged.
Replace a synthetic API key that matches the built-in api_key detector.
Configuration
Input event payload: tool arguments
Published payload
No selectors are needed. This detector matches supported API-key patterns;
the email remains unchanged because this profile uses only api_key. Use
separate profiles to apply both email and API-key redaction.
Remove an entire credentials object from the event payload.
Configuration
Input event payload: tool arguments
Published payload
remove deletes the selected object field, including its nested values.
Preserve only the last four characters of an account identifier.
Configuration
Input event payload: tool arguments
Published payload
Without a detector, the explicit suffix setting applies to the whole selected string.
Use action = "hash" to replace a customer identifier with its SHA-256
hexadecimal digest.
Configuration
Input event payload: tool arguments
Published payload
Without a matcher, hash computes SHA-256 for the entire selected string.
With a pattern or detector, it computes a separate digest for each matching
substring, leaving the surrounding text unchanged.
Preserve a token label while replacing the captured number.
Configuration
Input event payload: tool arguments
Published payload
regex_replace expands capture references in replacement for every match. redact uses a literal replacement marker.
Targeting and Composition
Nested content
Multiple profiles
LLM request only
LLM request and response
Trajectory removal
Metric dimensions
Select string leaves inside content-parts arrays.
Configuration
Input event payload: tool arguments
Published payload
This example is a JSON-native tool payload whose keys happen to be messages
and content. Each * matches one array index. Selecting only
/messages/0/content would select an array and leave the email unchanged.
Putting * in target_paths would match literal keys instead of array indices.
Refer to Path Semantics for the matching contract.
Apply email redaction, then remove the credentials field.
Configuration
Input event payload: tool arguments
Published payload
Priority 80 runs before 90. Each profile receives the payload produced by the preceding profile; array order breaks priority ties.
Redact request message content using an active OpenAI Chat Completions codec.
Configuration
Input event payload: OpenAI Chat Completions request body
Published payload
The managed call in this example supplies the OpenAI Chat Completions codec.
Selectors address normalized Relay message content. Other APIs can use different
provider payload shapes; select the normalized string leaves appropriate to
the active codec. Omit codec for a gateway that supplies it per call. For a
manual call without an active codec, the fallback for this API format is
codec = "openai_chat" under [components.config].
These selectors cover request messages. The LLM request and response tab adds a selector for assistant response text.
Use one policy to redact email addresses in both directions of an OpenAI Chat Completions call. The managed call supplies its active request and response codecs.
Configuration
Request: input event payload
Request: published payload
Response: input event payload
Response: published payload
The codec exposes request message text at /messages/*/content and assistant
response text at /message in Relay’s normalized representation. The response
selector therefore uses /message even though the emitted provider-shaped
response stores that text under choices[0].message.content. The selectors are
evaluated independently for the request and response payloads.
Remove conversational content while preserving the structure of an OpenAI Chat
exchange that uses native function calling. This example uses synthetic customer
data captured before and after sanitization through managed LLM and tool calls.
The managed LLM calls supply OpenAIChatCodec as their request and response codec.
The payloads below show provider-shaped message bodies; LLM request headers are
omitted from the display.
Configuration
The model first requests lookup_customer with
{"email":"alice@example.com"} as its arguments. The tool returns
{"email":"alice@example.com","plan":"Enterprise"}. The application then
sends the tool result back to the model in the following request.
LLM request before sanitization
Published LLM request after sanitization
The assistant’s tool_calls[0].id and the tool message’s tool_call_id both
remain call_lookup_1. The tool name, message roles, model, and temperature
remain available. The preset replaces user and tool-result text, empties tool
arguments and the parameter schema, and replaces the function description.
The minimal projection sets strict to false after discarding the schema.
The final model response is sanitized independently:
LLM response before sanitization
Published LLM response after sanitization
Response text and the response ID use the replacement marker. Token counts, model, finish reason, and the assistant role remain available.
Initial tool-call response and standalone tool events
The first model response proposes the same tool call. Its correlation ID survives even though its arguments are removed:
Initial tool-call response before sanitization
Published initial tool-call response
The standalone tool execution is a separate pair of lifecycle events. Its published argument and result payloads are empty objects:
Both events retain tool_call_id = "call_lookup_1", so exporters can link the
execution and result to the model’s request. The application receives the
original tool result and LLM responses; sanitization affects observability data.
Refer to Trajectory Context Preset for the full preservation contract, codec requirements, and custom-mark behavior.
Keep an approved metric dimension while removing other metric attributes.
Configuration
Input event payload: typed metric mark data
Published payload
This payload belongs to a mark with data schema
nemo.relay.metric_measurements, version 1. The preset preserves the typed
measurement and approved gen_ai.operation.name value, replaces the description,
and drops the other attributes. The allowlist requires an exact attribute name
and value; see Typed Metric Marks.
Verify the Policy
Valid selector syntax does not guarantee that the policy changes a payload.
Enable runtime diagnostics at startup and inspect
pii_redaction.selector_evaluated observations for the JSON documents the
built-in sanitizer processes. Recording is best effort and depends on diagnostic
admission and retention.
For the Nested content example:
Zero counts are informational: some traffic legitimately lacks the configured path or a matching sensitive value. Diagnostic detail includes only bounded counts, never the original matched content.
Diagnostic Component Keys
Profile observations use component keys such as
pii_redaction.selector.profile_0, even with a single profile. Single-policy
observations use pii_redaction.selector.
For container removal, omitted selectors, and unchanged selected values, refer
to Selection Accounting.
The trajectory_context preset uses its semantic sanitization path rather than
this selector diagnostic.