Blank white background with no objects or features visible.

Wir stellen Ihnen den vollständigen Gartner Hype Cycle für KI-Governance 2026 kostenlos zur Verfügung. Hier Exemplar sichern →

Secrets Detection in Prompts: Stop Credential Leaks to LLMs

von Ashish Dubey

Published: October 16, 2026

TL;DR
  • Secrets end up in prompts constantly — a developer pastes a stack trace with an API key, a coding agent reads an .env file, a RAG chunk contains a connection string. Once it’s in the prompt, it’s left your perimeter.
  • A secrets-detection guardrail scans content for credentials — AWS keys, OpenAI/Anthropic API keys, JWTs, private keys, database strings, and dozens more — and either blocks the request or redacts the secret.
  • In TrueFoundry it runs on all four hooks: LLM input, LLM output, MCP pre-tool, and MCP post-tool — so secrets are caught whether they come from a user, a model, or a tool result.
  • It runs inside the gateway with no external API call, so it’s fast and adds no per-call cost.
  • Two modes: Validate blocks the request; Mutate redacts the secret (***REDACTED***, configurable) and lets it through.

Why secrets end up in prompts

Nobody means to send a credential to a model provider. It happens anyway, because prompts are assembled from messy, real-world text:

A developer debugging an integration pastes a config snippet — with a live API key in it — and asks the model to find the bug. A coding agent, told to “fix the failing test,” reads the repo’s .env file into its context. A RAG pipeline retrieves a document that happens to contain a database connection string. An agent calls a tool that returns an object with an embedded OAuth token, and that result goes straight back into the model’s context.

In every case the secret has now been transmitted to a third-party provider, logged somewhere, and possibly used in training or retained. The developer did nothing obviously wrong; the system had no checkpoint. That checkpoint is what a secrets-detection guardrail provides — and the right place for it is the gateway every call already passes through.

What leaks, and where

Credentials come in recognizable shapes, and a good detector knows the patterns.

What the secrets guardrail catches

What the secrets guardrail catches

TrueFoundry’s built-in Secrets Detection guardrail recognizes 40-plus credential patterns across cloud providers (AWS, Azure, GCP), AI/ML API keys (OpenAI’s sk-, Anthropic’s sk-ant-), repository and package tokens (GitHub, GitLab, NPM, PyPI), communication platforms (Slack, Discord, Telegram), payment keys (Stripe, Square, Shopify), database connection strings, and private keys and certificates (RSA, OpenSSH, PGP). Beyond fixed patterns, it does contextual detection — flagging high-entropy hex or base64 strings that appear near keywords like token=, secret=, or password=, which catches credentials that don’t follow a standard format.

Because it runs inside the gateway rather than calling an external service, detection is fast and adds no extra per-request cost.

Where to catch it: four hooks

A secret can enter the conversation from three directions — the user, the model, or a tool — so the guardrail runs at four points.

Secrets detection on all four hooks

Secrets detection on all four hooks

LLM Input stops a user or app from sending credentials to the model in the first place. LLM Output catches a model that generates or echoes a secret (for example, producing a sample config with a real-looking key). MCP Pre-Tool scans tool parameters before a tool runs, and MCP Post-Tool redacts secrets in tool results — the file contents and API responses an agent pulls back into its context. For agentic systems, the MCP hooks matter as much as the LLM ones, because the agent is reading files and calling APIs on its own.

Block or redact

You choose what happens when a secret is found.

Validate blocks; Mutate redacts

Validate blocks; Mutate redacts

Validate mode blocks the request outright when a secret is detected — the right choice when a credential in the content is a hard policy violation. Mutate mode redacts the secret, replacing it with configurable text (***REDACTED*** by default) and letting the request continue — useful when you want the agent to keep working on the non-sensitive part of the content, and when you want clean text in your logs. Many teams run Mutate on input (so work continues with the secret stripped) and consider Validate where a leak must hard-stop.

Where teams get this wrong

They only guard user input. Secrets leak from model output and tool results too. Guard all four hooks, not just the prompt.

They forget output guardrails skip streaming. With stream: true, output scanning doesn’t run — there’s no complete response to check. Use stream: false where output redaction matters.

They rely on developers to be careful. “Don’t paste secrets” is not a control. The whole point of a gateway guardrail is that it doesn’t depend on anyone remembering.

They don’t tune for false positives. High-entropy strings like UUIDs or encoded blobs can trip detection. Test against your real traffic and adjust before enforcing hard blocks.

‍

Try now.

One gateway for all your models, MCP servers, and agents.
No credit card needed.

Melde dich an
Inhaltsverzeichniss

Steuern, implementieren und verfolgen Sie KI in Ihrer eigenen Infrastruktur

Buchen Sie eine 30-minütige Fahrt mit unserem KI-Experte

Eine Demo buchen

Der schnellste Weg, deine KI zu entwickeln, zu steuern und zu skalieren

Demo buchen
Summarize with
ChatGPT logo by OpenAI
Perplexity AI logo
Blurry red snowflake on white background, symmetrical frosty design with soft edges and abstract shape.

Entdecke mehr

Keine Artikel gefunden.
October 16, 2026
|
Lesedauer: 5 Minuten

Secrets Detection in Prompts: Stop Credential Leaks to LLMs

Keine Artikel gefunden.
October 16, 2026
|
Lesedauer: 5 Minuten

Jailbreak and Prompt-Injection Detection at the Gateway

Keine Artikel gefunden.
October 16, 2026
|
Lesedauer: 5 Minuten

Realtime / Live API and Voice Agents Through the Gateway

Keine Artikel gefunden.
October 16, 2026
|
Lesedauer: 5 Minuten

LiteLLM Tutorial: Install, Configure, Run the Proxy

Keine Artikel gefunden.
Keine Artikel gefunden.

Aktuelle Blogs

Black left pointing arrow symbol on white background, directional indicator.
Black left pointing arrow symbol on white background, directional indicator.

Häufig gestellte Fragen

What is secrets detection for LLMs?

A guardrail that scans prompts, responses, and tool traffic for credentials — API keys, AWS keys, JWTs, private keys, database strings — and blocks the request or redacts the secret before it reaches a model provider.

What secrets can it detect?

40-plus patterns across cloud credentials, AI/ML API keys, repository and package tokens, communication-platform tokens, payment keys, database connection strings, and private keys — plus contextual detection of high-entropy strings near keywords like token= or secret=.

Does it add latency or cost?

Minimal. TrueFoundry’s Secrets Detection runs inside the gateway with no external API call, so it’s fast and adds no per-request charge.

Should I block or redact?

Redact (Mutate) when you want work to continue with the secret stripped and clean logs; block (Validate) when a credential in the content must hard-stop the request. Many teams redact on input and block where policy requires.

Does it work for AI agents and MCP tools?

Yes. It runs on MCP pre-tool and post-tool hooks as well as LLM input and output, so secrets in tool parameters and tool results are caught — important for agents that read files and call APIs.

Can I run it in my own cloud?

Yes. As a built-in, in-gateway guardrail it runs wherever your TrueFoundry data plane runs, including VPC and on-prem, so secrets never leave your environment.

Machen Sie eine kurze Produkttour
Produkttour starten
Produkttour