Secrets-scanners detect API keys, tokens, and credentials in user input via regex and entropy heuristics, then redact or block before the prompt reaches the model.
Imagine you have a smart helper who reads every message you send, then forwards it to a stranger across town to get an answer. One day you accidentally paste your house key, your bank PIN, and your safe combination into the message. The stranger now has all of them. A secrets-scanner is a friend standing at the door who recognises what house keys and PINs look like (the shape, the length, the weird mix of characters), and either covers them with a black marker or refuses to send the letter at all. The friend cannot prevent you from pasting them in, but they can stop the leak before it reaches the stranger.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Every LLM-powered application has a chokepoint problem with secrets. Users paste API keys, tokens, database connection strings, and private keys into prompts as part of their work, sometimes deliberately ("help me debug this auth error") and sometimes by accident (a copy-paste from a config file). Once those secrets enter the prompt, they propagate: to the third-party LLM API, to the request log, to the observability platform, to the conversation history.
An input secrets-scanner is the deterministic input rail that exists to break that propagation. This deep dive walks through what categories it detects, how regex plus entropy detection works, where it has to run in the request path, and what failure modes are worth pre-empting.
What counts as a secret
The category covers anything that grants authentication or access:
- Provider API keys. AWS (AKIA-prefix access keys, ASIA-prefix temporary credentials), GCP service-account JSON, Azure shared keys, OpenAI (sk-prefix), Anthropic (sk ant prefix), Stripe (sk_live_, sk_test_), Twilio, SendGrid, Slack tokens.
- Source-control tokens. GitHub PATs (ghp_, ghs_, github_pat_), GitLab tokens (glpat-), Bitbucket app passwords.
- Authentication tokens. JWTs (three base64 segments dot-separated), OAuth bearer tokens, session cookies with high-entropy values.
- Database credentials. Connection strings with embedded passwords (postgres://user:pass@host), MongoDB URIs (mongodb+srv://), Redis URLs with auth.
- Cryptographic material. SSH private keys (-----BEGIN OPENSSH PRIVATE KEY-----), PGP keys, TLS private keys.
- Custom internal credentials. Tenant-specific tokens, internal-API keys, system of record account references.
Good scanners ship 200-400 provider-specific patterns out of the box and let teams add tenant-specific regexes for internal formats.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- GitHub push-protection uses the same regex library to detect secrets in commits before they reach the remote repository
- AWS Bedrock Guardrails sensitive-information filter includes regex patterns for AWS credentials, AKIA-prefix keys, and IAM tokens
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you tune a secrets-scanner to minimise false positives without missing critical credentials in a multi-tenant SaaS?
Layer the patterns: ship the provider-default library at high precision (AKIA-prefix, ghp_, sk_live_), add per-tenant regexes for internal formats with tenant-specific tests, and put the entropy fallback at a higher threshold with a redact-only action. Maintain a synthetic-secrets test corpus in CI that exercises both classes.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Relying only on the model's RLHF to refuse to repeat secrets, rather than scanning the input before it reaches the model and a third-party API.
60 second bullets to scan on the way to the call.
What categories of strings a secrets-scanner detects
The two detection techniques (regex patterns and entropy heuristics) and what each catches
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.