Secret detection
The secret detection guardrail (integration id hide-secrets, with hide_secrets accepted as the same name) scans every prompt for credentials, such as cloud access keys, API tokens, private keys, JWTs and passwords, and replaces each one with [REDACTED] before the request leaves the gateway. It exists for the moment a developer pastes a log file, a config file or a stack trace into a chat or a coding agent without noticing the key inside it. It reads the chat messages and tool call arguments, the text completion prompt, the Responses API input and instructions, function call results, and the Anthropic Messages system prompt, so the model, the provider and the gateway's own logs only ever see the redacted text and there is nothing to rotate afterwards. Secret detection is part of Spanway Enterprise, so it needs a valid license. On a gateway without one, adding it over the API or the Admin UI answers 403, and a config.yaml that declares it stops the gateway from starting with the same message, so the gateway never runs without a secret filter you asked for.
A real-world scenario
An engineering organization gives every developer a coding assistant through the gateway. During an incident a developer pastes a failing deployment log into the assistant to ask what went wrong. The log carries a cloud access key and a database password. With hide-secrets turned on for everyone, the assistant receives AWS_ACCESS_KEY_ID=[REDACTED] and password=[REDACTED], still explains the failure, and the security team never has to treat the paste as a leak. The request log records that two secrets were masked, never what they were.
Turn it on
-
Create the guardrail. In the Admin UI open Guardrails under AI Gateway, click Add New Guardrail, then Add Provider Guardrail. Enter
secretsas the Guardrail Name, pick Hide Secrets as the Guardrail Provider, keep Mode atpre_call(the only mode this provider offers), set Always On to Yes so it runs for everyone, and click Next, then Create Guardrail. Over the API:curl -X POST http://localhost:4000/guardrails \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"guardrail": {"guardrail_name": "secrets","spanway_params": {"guardrail": "hide-secrets", "mode": "pre_call", "default_on": true},"guardrail_info": {"description": "Redacts pasted credentials before the model sees them"}}}'In
config.yamlthe same guardrail reads:guardrails:- guardrail_name: secretsspanway_params:guardrail: hide-secretsmode: pre_calldefault_on: trueExpected result: a
200with the stored guardrail, and a row on the Guardrails page with the Default On badge. The oldercallbacks: ["hide_secrets"]setting runs the same detection and also needs a license, with two differences: without a license it stops the gateway with the messageTrying to use secret hidingfollowed by the license notice, and because it has no guardrail name it records no masked count in the log's guardrail section. Prefer theguardrails:form above. -
Test it without a model call. Open the Test Playground tab, select
secrets, typemy key is AKIAIOSFODNN7EXAMPLEunder Input Text and click Test 1 guardrail. Over the API:curl -X POST http://localhost:4000/guardrails/apply_guardrail \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"guardrail_name": "secrets", "text": "my key is AKIAIOSFODNN7EXAMPLE and the db password is hunter2-prod"}'Expected result:
{"response_text": "my key is [REDACTED] and the db password is hunter2-prod"}The access key is recognised by its shape. A plain word like
hunter2-prodis only redacted when it follows a credential keyword such aspassword=, which the keyword detector covers. -
Send a real request through any key and open Logs. The Guardrails & Policy Compliance section lists
secretswith the number of secrets masked by kind. The values themselves are never recorded.
Settings
| Field | Default | What it does |
|---|---|---|
detect_secrets_config | every built-in detector | Advanced. A plugins_used list that picks the detectors and their settings, for example {"plugins_used": [{"name": "AWSKeyDetector"}, {"name": "HexHighEntropyString", "limit": 3.0}]}. Fewer detectors means fewer false alarms but more secrets missed. It also takes filters_used, a list of import paths to filter functions that drop matches, which runs gateway code, so only a proxy admin should set it. In the Admin UI it is the JSON field on the Basic Info step. |
default_on | false | On runs it on every request from every key. Off runs it only on requests, keys or teams that name it. |
The built-in detectors cover AWS, Azure storage, Git hosting tokens such as GitLab, Slack, Stripe, SendGrid, Twilio, npm, PyPI, Discord, Telegram, Mailchimp, IBM Cloud, OpenAI keys, private keys, basic auth URLs, JWTs, credential keywords and high entropy strings.
A key can opt out with permissions: {"hide_secrets": false}, for example a key that must send credentials to a tool on purpose. Only a proxy admin can set key permissions:
curl -X POST http://localhost:4000/key/update \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"key": "sk-9f3a2c7e41b8d6059012ijkl3456mnop", "permissions": {"hide_secrets": false}}'
Privacy
Secrets are redacted before the request is logged, so spend logs, traces and logging integrations never receive them. The guardrail records how many secrets of each kind it masked, never their values. Masking happens on the gateway, so no text leaves your network for the detection itself.
Errors
| Status | Where | Meaning | Fix |
|---|---|---|---|
403 The hide_secrets secret detection guardrail needs a Spanway enterprise license. | POST /guardrails, or Failed to create guardrail in the Admin UI | The gateway has no valid Enterprise license. Nothing was stored and no audit row was written. The Admin UI form shows no lock for this provider, so the message appears when you click Create Guardrail. | Add a license key, see enterprise. |
| Gateway does not start, the same message in the log | Startup | config.yaml declares a hide-secrets (or hide_secrets) guardrail on a gateway without a license. The gateway refuses to run without the filter you asked for. | Add a license, or remove the entry until you have one. |
Gateway does not start, the log shows Trying to use secret hiding and the license notice | Startup | config.yaml sets the older callbacks: ["hide_secrets"] on a gateway without a license. | Add a license, or remove the callback until you have one. |
403 Admin access required to manage guardrails | Create, update, delete | The key is not a proxy admin. | Use an admin key. |
404 Guardrail 'secrets' not found | POST /guardrails/apply_guardrail | The name does not match a guardrail. | Copy the name from the Guardrails page. |
| A secret got through | Any request | The string matches none of the detectors, or the key opted out with permissions.hide_secrets: false. | Add a detector in detect_secrets_config, or remove the opt-out. |
Audit
Creating, changing and deleting the guardrail write audit rows on Spanway_GuardrailsTable with who made the change and the value before and after, see audit logs. A refused create writes no row.
Logs
| Level | Line | What it means | Action |
|---|---|---|---|
| WARNING | Rollback failed for guardrail '<id>': <error> | A create was refused, for example for the license, and the row it had written could not be removed. | Action needed. Delete the guardrail on the Guardrails page. |
| INFO | Immediate sync: Successfully initialized guardrail '<name>' | The guardrail was created and runs now. | Normal. |
Related
- Guardrails for modes, attachment rules and the full error list.
- PII masking with Presidio for personal data rather than credentials.
- Apply guardrail for the test call used in step 2.
- Leaked keys and key expiry for what to do when a Spanway virtual key itself has leaked.
- Guardrails page for the provider fields in the Admin UI.