Secret redaction
How zn-gate removes credentials from MCP tool output and tool arguments before they reach the model, and what it does not cover.
Tools often return more than they should: a file with an API key, a database URL with its password, a log with a token. zn-gate replaces those values with a placeholder before the text reaches the model. Redaction is local and always on in the paths below.
What is redacted
| Secret | Placeholder |
|---|---|
AWS access key IDs (AKIA…) |
[REDACTED_AWS_KEY] |
AWS secret keys after aws_secret_access_key= and similar |
[REDACTED_AWS_SECRET] |
OpenAI keys (sk-, sk-proj-, sk-svcacct-) |
[REDACTED_OPENAI_KEY] |
Anthropic keys (sk-ant-) |
[REDACTED_ANTHROPIC_KEY] |
GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_, github_pat_) |
[REDACTED_GITHUB_TOKEN] |
| JWTs | [REDACTED_JWT] |
| PEM private keys | [REDACTED_PRIVATE_KEY] |
Passwords in postgres, mysql, mongodb, redis and amqp URLs (only the password) (a reference such as ${PGPASSWORD} is left as is) |
[REDACTED_DB_PASSWORD] |
Values of SECRET_KEY, API_KEY, AUTH_TOKEN, PRIVATE_KEY, DATABASE_PASSWORD assignments (12+ characters) |
[REDACTED_SECRET] |
The rest of the line keeps its shape, so the agent can still work with it: DATABASE_URL=postgres://app:[REDACTED_DB_PASSWORD]@db:5432/main. Placeholders are fixed and one-way: zn-gate keeps no copy of the original value.
Where it runs
- MCP server:
check_tool_resultalways returns the output with secrets redacted insanitized_content, with the count insecrets_redacted.check_tool_callreturnssanitized_argumentswith secrets masked. zn-gate shieldandinit: output of wrapped MCP servers is forwarded with secrets redacted (not in--shadowmode, which never alters traffic).- Local audit log: stores a redacted preview of each payload.
- Python:
redact_secrets,sanitize_tool_result,@guard(mask_secrets=True)and the framework integrations withmask_secrets=True. For LangChain, wrap tools withguard_langchain_toolto hide secrets in tool output. - Optional cloud: with
ZN_CLOUD=1, the secrets zn-gate detects are removed from prompts locally before they are sent. Personal data is not removed on this path.
From code
from zn_gate import guard, redact_secrets, sanitize_tool_result
redacted_text, found = redact_secrets(raw_text)
print(redacted_text, len(found), "secrets masked")
clean = sanitize_tool_result("db_query", untrusted_output)
if clean["safe_to_ingest"]:
llm.invoke(clean["sanitized_content"])
@guard(mask_secrets=True) # off by default in @guard
def fetch_profile():
return "Profile loaded. AWS key: AKIAIOSFODNN7EXAMPLE"
print(fetch_profile())
# Profile loaded. AWS key: [REDACTED_AWS_KEY]
const { checkToolResult } = require('zn-gate');
const res = await checkToolResult('read_file', untrustedOutput);
if (res.safe_to_ingest) {
feedToModel(res.sanitized_content); // secrets already redacted
}
sanitize_tool_result and checkToolResult also check the output for indirect prompt injection. If it carries one, safe_to_ingest is false and sanitized_content is a short notice instead of the original text.
What this page does not cover
This redaction applies to what passes through zn-gate's MCP tools. For your agent's built-in tools (file reads, shell output, searches), pasted prompts, personal data (checksum-validated cards, IBAN, DNI/NIE, SSN; email, phone, IPv4) and stable markers backed by an encrypted local vault, use the Scrubber (zn-gate 1.5 and later, npm).