Redact recognizable secrets before passing text to AI.
A small Go library and CLI for removing passwords, tokens, private keys and other recognizable credentials from logs, configuration snippets and prompts. Everything runs locally, without model calls, telemetry or network requests.
Go 1.23+ · Standard library only · MIT
From this project's directory:
go test ./...
go build -o bin/promptveil ./cmd/promptveil
./bin/promptveil
./bin/promptveil -emails testdata/context.txtStarting without arguments in a terminal displays ASCII art and help. When input is piped, text is processed directly. Data output contains no banner.
./bin/promptveil application.log > context.txt
./bin/promptveil -json -emails application.log
./bin/promptveil -key vault_code -key internal_pin application.log
./bin/promptveil -check -json application.log
cat application.log | ./bin/promptveilFlags must precede the optional file argument. An omitted file or - reads stdin. -check emits metadata only and exits 1 when sensitive spans are found. Ordinary redaction exits 0 after masking. Usage, input and I/O errors exit 2 and do not echo input.
The default input limit is 8 MiB (-max-bytes). Oversized input is rejected before analysis.
Before:
APP_API_KEY="demo-key"
Authorization: Bearer demo-token
postgres://demo:demo-password@db.example.test/app
After:
APP_API_KEY="[REDACTED_CREDENTIAL]"
Authorization: [REDACTED_AUTH_TOKEN]
postgres://[REDACTED_URL_CREDENTIAL]@db.example.test/app
Recognizes labeled passwords, secrets, API/access keys and tokens in common env, JSON, YAML scalar and query-string forms; authorization and cookie header lines; Basic/Bearer credentials; URL user information; structurally recognizable JWTs; and private-key PEM blocks. Email masking is opt-in. Additional key names are literal and case-insensitive.
Findings contain only a kind and byte offsets in the original input. Overlapping spans are merged. Identical placeholders intentionally do not identify or distinguish different secrets. The output is text, not a guarantee of valid JSON, YAML, or a usable configuration file.
result := promptveil.Redact("APP_API_KEY=demo-secret")
fmt.Println(result.Text) // APP_API_KEY=[REDACTED_CREDENTIAL]
redactor := promptveil.NewRedactor(promptveil.RedactOptions{
MaskEmails: true,
ExtraKeys: []string{"vault_code"},
})
result = redactor.Redact(logText)
cleanHeaders := redactor.RedactHeaders(requestHeaders)The library exposes Redact, NewRedactor, Redactor.Redact and Redactor.RedactHeaders. Header redaction only removes sensitive values; it does not audit HTTP configuration. A redactor is immutable and safe to share across goroutines. Inputs are not modified; callers must not concurrently mutate supplied header maps.
Install the CLI with go install github.com/dc9-dev/promptveil/cmd/promptveil@latest. Import the library as github.com/dc9-dev/promptveil. This is a standalone module; no sibling project is required.
Redaction is heuristic. Unlabeled opaque tokens, encoded or obfuscated secrets, nested formats such as HAR, multiline YAML scalars, and arbitrary personal data may not be recognized. It does not provide prompt-injection protection. Redacted context remains untrusted input, and strings are not securely erased from memory.
Use realistic fictional examples in your integration tests. Library callers must impose their own input limits. See detector coverage.
go test -race -cover ./...
go vet ./...
go test -run '^$' -fuzz FuzzRedact -fuzztime 10s .
go test -bench BenchmarkRedact -benchmem -run '^$' .Contributing · Security · GitHub description · MIT license
The README banner was generated with an AI image tool; its original prompt and provenance are included.
