Skip to content

Keep secrets and PII out of prompts with content rules

Add content rules to a guardrail so API keys, emails and card numbers are redacted or refused before a model sees them, then prove it with a dirty prompt.

14 min readLast reviewed October 19, 2026Verified against gateway chart 0.10.0

What you’ll have at the end

By the end you will have a guardrail whose content rules redact email addresses and refuse anything that looks like a live API key, bound to a service key. You will also have sent one deliberately dirty prompt through it and read what the caller sees, what the trace records, and which traffic the rules do not reach.

Before you begin

  • A team on the Nautili dashboard with a gateway reporting in, hosted or self-hosted.
  • A governance mode of shadow or enforce on that gateway (GOVERNANCE_MODE). With the mode off, the gate does not run, and content rules ride the gate's decision.
  • An ownerless service key from API keys under Access. Only service keys bind to a guardrail directly; a person's key follows their identity's guardrail.
  • curl, or Python 3 with openai, or Node 20 with openai.
  • Read Content rules once. This guide applies it and does not repeat every constraint.

Step 1: Know where a content rule runs

A guardrail has two halves. The governance half (budget, rate ceilings, model and provider access) is enforced by DevZero on every request, whoever's credential pays. The content half is the request-path scan this guide is about, and it runs in one of two places depending on the serving upstream.

PathThe gateway enforces locallyWhenThe serving upstream applies no guardrails of its ownChange lands inSeconds, with the decision cache
PathThe upstream enforcesWhenThe serving upstream can apply guardrails. DevZero projects your rules onto a guardrail object attached to your team's provisioned keysChange lands inUp to 5 minutes, on the reconciliation sweep

Either way the scan happens before the cache lookup and before the forward. A redaction rewrites the request body the gateway goes on to use, so the cache key, the prompt hash, the preview and the stored request body all see the redacted bytes. The consequence is that two requests that differ only in a redacted value share one cache entry.

Content rules read the request only. A model's answer is never scanned.

Step 2: Add the rules in the guardrail editor

Open Guardrails under Access, create a guardrail or edit one, and go to the Content filters step. Every detector shows an explicit action, and Off means the detector is absent from the saved guardrail.

The Content filters step of the guardrail editor with Email addresses set to Redact and Credit card numbers set to Block, and the custom patterns form below

Set these for this guide, then save and assign the guardrail to your service key from its Assignments dialog. A service key is issued with a guardrail of its own, named after the key, and that binding outranks the team default, so marking this guardrail the team default does not reach the key by itself.

RuleemailActionredactWhyA customer email in a prompt is useful context without the address itself
Rulecredit-cardActionblockWhyChecksum-validated, so a block rarely misfires
RuleCustom pattern sk-live-[A-Za-z0-9]+, label [API_KEY]ActionblockWhyA live key never belongs in a prompt

The builtin detector slugs are email, phone, ssn, credit-card, ip-address, person-name, address and prompt-injection. One action per detector; a second entry for the same slug is rejected. Custom patterns are RE2, up to 1000 characters, up to 100 per list, each with an optional label of up to 100 characters. A pattern that does not compile is rejected when you save; one the gateway still cannot compile refuses the request at enforcement time rather than being skipped.

The same document over the API, trimmed to the content fields:

{
"content_filter_builtins": [
{ "slug": "email", "action": "redact" },
{ "slug": "credit-card", "action": "block" },
{ "slug": "prompt-injection", "action": "flag", "scan_scope": "user_only" }
],
"content_filters": [
{ "pattern": "sk-live-[A-Za-z0-9]+", "action": "block", "label": "[API_KEY]" }
]
}

scan_scope is user_only or all_messages, and only prompt-injection accepts it. Empty leaves the engine default, which is all messages; the wizard offers All messages (sent as empty) and User messages only. Sending it on any other slug is rejected.

Step 3: Decide between block, redact and flag

ActionblockCaller sees403 and an error body. The request never reaches a model.Trace recordsguardrail_outcome = blocked, entity types such as EMAIL, CREDIT_CARD, CUSTOM
ActionredactCaller seesAn ordinary success. Each match replaced with the detector's placeholder before the forward.Trace recordsguardrail_outcome = redacted
ActionflagCaller seesAn ordinary success and an unchanged request.Trace recordsguardrail_outcome = flagged

Where the gateway enforces locally, the placeholders are [EMAIL], [PHONE], [SSN], [CREDIT_CARD] and [IP_ADDRESS]. A custom pattern's label is honoured only where the upstream enforces; locally every custom pattern redacts to [REDACTED] and reports the entity CUSTOM.

When rules overlap, the strongest outcome wins. A prompt that trips a redact rule and a block rule is blocked, and the row records blocked. Upstream, a team's guardrails are unioned onto one provisioned key with block winning over redact, which is why content rules are effectively team-wide there.

Step 4: Send a deliberately dirty prompt

The prompt below carries a fake key that matches the custom pattern and an email that matches the builtin detector. Because block beats redact, expect a refusal.

curl -s -D - https://<your-gateway-host>/v1/chat/completions \
-H "Authorization: Bearer $NAUTILI_KEY" \
-H "Content-Type: application/json" \
-H "X-Dz-Session-Id: content-rules-test-1" \
-d '{
"model": "anthropic/claude-haiku-4.5",
"messages": [{"role": "user",
"content": "Rotate sk-live-EXAMPLE0000 and email jane.doe@example.com when done."}]
}'

The gateway scans the body, the custom pattern matches, and the request stops before any provider is called. Tokens and cost on the row are zero.

Verify

Where the gateway enforces locally, the refusal looks like this (headers trimmed to the ones that matter):

HTTP/1.1 403 Forbidden
Content-Type: application/json
X-Dz-Request-Id: 7c0e5b4a-...
X-Cache: MISS
x-should-retry: false
{
"error": {
"type": "invalid_request_error",
"code": "content_blocked",
"message": "this request's content matched a content filter on your organization's DevZero LLM policy (CUSTOM, EMAIL)"
}
}

The body names the entity types that fired and never the matched text. x-should-retry: false tells SDKs not to retry, because the content will not become acceptable by waiting.

Where the upstream enforces, the status is still 403 but the body is the gateway's upstream-failure envelope, with "type": "upstream_error", "code": "upstream_content_blocked" and a dz_upstream object naming the upstream and its status. Branch on the status, not the code, if your client must handle both.

Now remove the key from the prompt and send it again with only the email. The response is an ordinary 200, and the model received jane.doe@example.com as [EMAIL]. The only evidence is in telemetry. Open Traces under Usage, find the row by the X-Dz-Request-Id you received, and open it. The visibility notice reads "A content filter redacted this prompt before it was stored: EMAIL."

In the telemetry row itself the columns are guardrail_outcome (blocked, redacted or flagged, empty when nothing fired), guardrail_entity_types (the categories) and guardrail_id. A trace with an empty outcome is not a clean bill of health on its own: the notice distinguishes "we looked and nothing fired" from "we could not check," and says so when the outcome could not be read.

Two things you cannot read from a row. Which enforcer ran, because both paths write the same columns. And the matched text, because the upstream's echo of it is never parsed, logged or stored.

Options

content_status

Saving rules is not the same as enforcing them. The Guardrails table shows the content half's own status beside the rule count, and the API returns it as content_status.state with a message and last_synced_at.

Statenot_applicableBadgenoneMeaningNo content rules configured
StatedisabledBadgeFilters offMeaningThe content half is switched off for this installation
StateunboundBadgeNot enforcedMeaningRules exist but nothing to attach them to: no managed-custody enrollment, or the guardrail is unassigned or disabled. They enforce nothing
StatependingBadgeApplying…MeaningRules changed and the projection has not converged yet
StateactiveBadgeFilteringMeaningProjected and enforcing
StateerrorBadgeFilter errorMeaningThe last projection attempt failed; message carries the reason

While pending, the previous rules keep applying upstream. Switching a detector from block to redact keeps blocking until the badge reads Filtering. Where the gateway enforces locally, a change lands with the decision cache instead, so a guardrail can be Applying… upstream and already enforcing on a local path.

Scan scope for prompt injection

{ "slug": "prompt-injection", "action": "flag", "scan_scope": "user_only" }

With user_only the detector reads user messages only; with all_messages or empty it reads system and assistant turns too. Prompt injection, person names and postal addresses are model-scored upstream and have no local implementation. A guardrail that names one of them, served on an upstream where the gateway enforces locally, is refused with 400 unsupported_capability rather than forwarded unfiltered:

{
"error": {
"type": "invalid_request_error",
"code": "unsupported_capability",
"message": "content filter \"prompt-injection\" cannot be enforced locally: prompt injection is model-scored upstream; a regex would be a different check wearing the same name"
}
}

The same code and status are returned when a custom pattern does not compile, or when a redaction would break the JSON body.

Keep the original inside your network

Content rules redact what the provider sees. Whether the original ever leaves your network is a separate, per-deployment decision. A self-hosted gateway defaults to a content-free telemetry uplink: full request and response bodies, prompt and response previews, extracted user prompt text and tool-call argument summaries are blanked before upload, while token counts, costs, latencies, hashes, tool names, attribution and the guardrail outcome columns still upload. The gateway's own cache and originals stay in your cluster.

# values.yaml for the nautili-gateway chart
config:
telemetryContentUplink: null # null: the binary decides by deployment method; self-hosted stays content-free

The environment variable is LLM_TELEMETRY_CONTENT_UPLINK. It is env-only, never dashboard-managed, and a change takes effect on restart. Set true to upload content; that restores the features that read prompt text (Model Trials and anything else that needs the stored body) at the cost of prompt and response text leaving the VPC. A hosted gateway keeps the uplink on, because bodies already transit DevZero infrastructure.

Pair the two: content rules so the provider never receives the secret, and a content-free uplink so DevZero never receives the original. What your team stores for its own traces is then governed by prompt retention, which decides what is kept and for how long. Where the gateway enforces locally, the stored prompt is the redacted one; where the upstream enforces, the stored prompt is what your client sent.

Troubleshooting

Symptom403 with "code": "content_blocked" on a prompt you expected to passCauseA block rule matched. The message lists the entity types in parenthesesFixRead the types. Promote the rule to flag, read the flagged rows, then tighten the pattern
Symptom403 with "code": "upstream_content_blocked"CauseThe serving upstream applied your projected rulesFixSame as above. The dz_upstream object names the upstream
Symptom400 with "code": "unsupported_capability" and "cannot be enforced locally"CauseA rule names person-name, address or prompt-injection and the serving upstream has no engine of its ownFixRoute the guardrail's traffic to an upstream that applies guardrails, or drop the model-scored detector
Symptom400 with "code": "unsupported_capability" and "does not compile"CauseA custom pattern is not valid RE2FixFix the pattern; the request is refused rather than forwarded unfiltered
Symptom400 with "code": "unsupported_capability" and "no upstream this request can be served on applies them"CauseThe rules are delegated and no eligible path applies themFixCheck the routing profile's provider lists against the upstreams that enforce content rules
SymptomResponse is 200 and nothing looks differentCauseThe matching rule is redact or flag, which are invisible by designFixRead the trace. The visibility notice and guardrail_outcome carry the result
SymptomBadge reads Not enforcedCausecontent_status is unbound: the guardrail is unassigned or disabled, or the team has no managed-custody enrollmentFixAssign the guardrail to a service key or mark it the team default
SymptomBadge stays on Applying…CauseThe projection has not converged. It sweeps every 5 minutesFixWait one sweep. If it turns to Filter error, read content_status.message
SymptomBadge reads Filter errorCauseThe last projection attempt failed; the status carries the upstream's messageFixFix what the message names, usually a pattern the upstream rejected, and save again
SymptomRules pass on one key and are bypassed on anotherCauseThe second key forwards on your own upstream account (Tier 1 BYOK) to the upstream that applies guardrails itselfFixConfigure equivalent filters in that provider account
SymptomSaving rejects a duplicate detectorCauseOne action per detector; a second entry for the same slug is refusedFixRemove the duplicate
SymptomPrompt text appears in the Nautili dashboard from a self-hosted gatewayCauseLLM_TELEMETRY_CONTENT_UPLINK is pinned trueFixSet config.telemetryContentUplink: false or leave it null, then restart the pods

Next steps

Ready to keep going?

Explore the next guide or start routing through Nautili.