Redacting secrets from prompts with LiteLLM

LiteLLM's hide-secrets guardrail replaces detected API keys and tokens with [REDACTED] before the model call. This page explains how to configure it, what it cannot catch, and how it fits beside DLP tools.

On this page

How LiteLLM redacts secrets from prompts before a model call

Developers paste API keys, passwords and tokens into prompts all the time, often while debugging a script or asking a model to review a config file. Once that text leaves your network, you cannot recall it from a third-party provider. The LiteLLM gateway is the last point you control before a model provider receives the request, which makes it a practical place to stop credentials from leaving. The hide-secrets guardrail is LiteLLM's built-in check for this. It scans request messages for secrets such as API keys and replaces each one with [REDACTED] before the LLM call is made.

The guardrail runs in pre_call mode, so the redaction happens before the request is sent to the provider. That ordering matters: a pre_call check can change what the provider sees, while a check that runs only after the response cannot undo a disclosure that already happened. Enable it on the guardrail configuration for the proxy, then confirm which routes and models it applies to in your own deployment. Test it with fake credentials in each format your developers use, and confirm that the redacted text still makes sense to the model for the tasks your teams run. Detection covers the patterns the vendor documents, so ask the vendor for the current list of supported secret types before you rely on it for a specific credential format.

Teams need this guardrail when developers or tools send free-form text, logs, configuration or code to models through the gateway, and when a leak to a provider would trigger an incident review. It is a useful default for shared keys and for coding assistants that read whole files. It does not replace a DLP product that inspects documents, email, and endpoints across the business. Treat it as one layer: keep secrets out of source and prompts at the source, rotate any credential that has already been exposed, and decide with your security team which DLP controls sit in front of the gateway and which sit beside it.

Where the hide-secrets guardrail sits in a request

The request starts at the client, where a user or tool pastes a prompt that may contain an API key, password or token. It then reaches the LiteLLM proxy, where the hide-secrets guardrail runs in pre_call mode and replaces each detected secret in the messages with [REDACTED] before any model call is made. Only the redacted request crosses the trust boundary to the external model provider, and the response returns through the proxy. Check that the guardrail is enabled on the right keys or teams, and test what the provider actually receives.

The guardrail redacts secrets inside the proxy before the request leaves for the provider.

Which secret-handling option fits which team

This table compares the hide-secrets guardrail with blocking requests, logging only and relying on an upstream DLP tool. Read each row as one option, checking what the caller sees, when it fits and what it leaves uncovered. The main takeaway is that hide-secrets changes the prompt before the model call, so it does not by itself stop the request, record the event or inspect data outside the gateway.

OptionWhat the caller seesBest fitWhat it leaves uncovered
Hide-secrets guardrail (pre_call)The request proceeds with detected secrets replaced by [REDACTED] before the model callTeams that want developers to keep working while keys pasted into prompts never reach providersSecrets the detector does not recognize, and any secret already stored in a provider or log before the call
Block the requestThe request fails and the caller must remove the secret and resendEnvironments where any secret in a prompt is a policy violation that needs a clear stopDeveloper friction and workarounds if the caller cannot easily see what triggered the block
Logging onlyThe request proceeds unchanged while the event is recordedPilot phases where the team needs to measure how often secrets appear before enforcing anythingThe secret still reaches the model provider, so logging only does not protect the credential
Upstream DLP toolDepends on the tool, usually inspection before traffic reaches the gatewayOrganizations that already run enterprise DLP on browsers, endpoints or network egress and want one policyTraffic that bypasses that tool, and any gap between the DLP policy and the gateway's own key handling
Hide-secrets plus upstream DLPRedaction at the gateway with inspection earlier in the pathRegulated teams that want layered controls and evidence from both pointsRequires confirming how the two policies are kept consistent and which system owns the audit record
Built-in content filter or external guardrailDepends on the chosen guardrail's mode and pattern setCases where prompts carry personal data or other patterns beyond credentialsCoverage depends on the patterns configured, so confirm them against your own secret formats

Setting up the hide-secrets guardrail on a self-hosted gateway

This sequence takes the hide-secrets guardrail from a version check to a tested configuration, so API keys, passwords and tokens pasted into prompts are replaced before any model provider receives them. Each step ends with a check you can record as evidence.

  1. Confirm the proxy version and config location

    The platform engineer running the gateway confirms which LiteLLM release is deployed and where the proxy configuration file is loaded from, whether that is a mounted file, a config map or a repository that feeds the deployment. Check the running version against the release line your organization supports, and confirm the guardrail feature is available in that version by reading the secret detection docs for your release. Done when the version, the config path and the source of truth for changes are written down and the team agrees who can edit them.

  2. Define the hide-secrets guardrail in pre_call mode

    Add a guardrail entry for the hide-secrets check to the proxy configuration and set its mode to pre_call, so detection runs before the model call and the provider only sees the redacted text. Confirm the exact config keys, names and any detection options against the secret detection docs for your version, because key names can change between releases. Apply the change through your normal review process, restart or reload the proxy as the release requires, and confirm the proxy starts with no configuration errors in its logs.

  3. Attach the guardrail to the intended scope

    Decide which traffic the guardrail covers and attach it to those keys, teams or models only, instead of relying on a single global default. Start with the virtual keys or teams that handle developer tools, support tools or any workflow where people paste code, logs or configuration. Record the attachment in the configuration or key metadata so an auditor can see which scope is covered. Done when a request made with an attached key shows the guardrail in its applied list, and a request from an unattached key does not.

  4. Prepare fake secrets for testing

    Create a test set of clearly fake credentials in the formats your teams actually paste, such as cloud access key patterns, bearer tokens, database connection strings with placeholder passwords and private key headers. Mark every value as fake and store the set with the test plan, not in a shared channel. Use values that will never work against a real system, so a leak during testing carries no risk. Done when the set covers each secret type your policy names and the owner has approved it for use on the gateway.

  5. Send test prompts through the gateway

    Send the fake secrets through an attached key in ordinary chat and completion requests, including secrets placed in system, user and multi-message conversations. Confirm the response is generated from the redacted text and that the guardrail marks the replacement with the redaction placeholder rather than returning an error. Run the same prompts through an unattached key and confirm the raw value would have been passed through, which proves the scope works. Record each prompt, the expected result and the observed result.

  6. Verify the provider never receives the raw value

    Check the request logs and traces for the gateway and, where you can, the provider-side request record, searching for each fake secret string. The raw value should appear nowhere downstream of the guardrail, while the redacted placeholder should appear in the forwarded request. If a raw value appears in any log, stop the rollout, find which logging hook captures the original payload, and fix that before continuing. Keep the search results as evidence that the control worked as designed.

  7. Confirm limits and hand off to operations

    Document what the guardrail does not catch, including secrets in formats outside the detection rules, secrets split across messages, and content in files or tool outputs, and state which of these need a DLP tool or another control. Ask the vendor or the secret detection docs to confirm the supported patterns for your version. Add a test run to the upgrade checklist so the guardrail is re-verified after each proxy upgrade. Done when the operations owner signs off on the test results and the known gaps.

Security and operational risks of relying on pattern-based redaction

Pattern-based redaction removes known secret formats before a model call, but it does not see everything that reaches the gateway. The cards below cover the gaps that remain, the logs and tool paths where secrets can still land, and the operating routines that keep redaction trustworthy after launch.

Unfamiliar token formats slip through

Redaction only catches secret patterns the detector knows. Internal service tokens, custom signing keys and passwords pasted without a recognizable prefix can pass unchanged to the provider. Before rollout, collect the credential formats your teams actually use, run them through a test prompt set, and record which ones are missed. Treat a miss as a gap to close with a custom check, not as proof the control works.

Secret detection docs

Secrets logged before redaction

Redaction runs in the request path, but request and error logs can capture the raw prompt depending on how logging is configured. If a secret is written to a log store before it is replaced, the redaction did not protect it. Confirm with your own test which fields the logging callbacks record, who can read them, and how long they are kept, and align that with your retention policy.

Secrets in tool outputs and attachments

Secrets can enter a conversation through tool results, retrieved documents, file uploads or pasted log excerpts rather than the user's typed message. Confirm whether the guardrail you deploy inspects those message parts in your configuration, and test with a file and a tool output containing a dummy key. Where it cannot scan a content type, document that gap and decide whether to block the content type or accept the risk.

Rotating keys already sent

Redaction cannot recall a secret that reached a provider or a log before the control was active. Build a response step: identify keys that appeared in prompts since the earliest logs you hold, revoke and reissue them, and confirm with each provider's console that old keys are disabled. Record the rotation in your incident process so the same key does not get reused.

Monitoring redaction events

A redaction control that fires silently is hard to trust. Decide which events you need to see, such as the count of redactions per team, key and model, and send them to the alerting and SIEM tools your team already runs. A sudden spike can point to a leaked credential in a shared workflow, while a long quiet period may mean the detector has stopped matching. Review these signals on a set schedule.

Protecting the master key and retesting

Keep LITELLM_MASTER_KEY, which must start with sk-, in a secret manager rather than in a configuration file or container image, because anyone holding it can administer the gateway and its guardrail settings. After each LiteLLM upgrade, rerun your redaction test set and confirm the guardrail still loads and matches the same formats. Ask your vendor or partner to include this retest in the upgrade runbook.

Production best practices

How the guardrail sits alongside DLP tools

If your organization already runs a DLP platform, the LiteLLM hide-secrets guardrail should be treated as one enforcement point, not as the policy itself. The guardrail runs in pre_call mode and replaces detected secrets in request messages with [REDACTED] before the call reaches a model provider. That protects traffic that passes through the gateway, and only that traffic. Your DLP platform likely owns the classifiers, policy library and incident workflow, so the question is how the two layers agree.

  • Classifier alignment: Compare what your DLP platform flags as secrets with what the hide-secrets guardrail detects, using a sample set of realistic test strings in a non-production environment.
  • Policy ownership: Decide which system is the source of truth for secret rules, and who approves changes to them.
  • Evidence and alerts: Confirm whether redaction events reach your DLP or SIEM console, or only the gateway logs.
  • Duplicate handling: Check whether a second scanner in front of the gateway changes what the guardrail sees, which can affect detection.
  • Scope of coverage: Document that browser sessions, file uploads and other channels remain under the DLP platform's control.

Confirm with your DLP vendor which integrations exist for your product version, since DeployOpen has not been told of any specific DLP product integration with LiteLLM.

Limits to confirm in your environment before relying on redaction

The hide-secrets guardrail is one layer in front of model providers, and its coverage depends on details that vary by deployment. Each card below names one limit to check, with the test or vendor question that settles it. Treat every item as unproven until your own tests show otherwise.

Which secret formats are detected

Confirm which key and token formats the hide-secrets guardrail actually matches in the version you run. Detection is pattern based, so vendor-specific keys, internal token formats, database connection strings and private key blocks may pass through unchanged. Build a test set from the formats your developers really paste, including ones you have issued yourself, and record which ones are replaced with [REDACTED] before the call.

Secret detection docs

Behavior with streamed responses

The guardrail is documented to run in pre_call mode, which screens the request before the model call. Confirm how your deployment treats streaming requests and whether any response-side behavior applies to streamed output. Test a streamed call that echoes a secret back from the model, since redaction on the request side does not control what a model generates.

Secrets in images and files

Redaction works on the text of request messages. Confirm whether secrets inside images, PDFs, spreadsheets or other attachments are read at all. A screenshot of a terminal showing a credential is likely to bypass a text-based check, so decide whether those uploads need a separate control or a block policy at the gateway.

Supported LiteLLM version line

Pin the release line you test against and confirm the guardrail behaves the same on it. LiteLLM states that it maintains support for the four most recent stable minor versions, so an older line can fall out of support while your rules still depend on it. Retest after every upgrade, because detection patterns and guardrail wiring can change between releases.

Minor versions supported
4
LiteLLM releases

Availability in your edition

Check whether the secret detection guardrail is available in the edition you deploy, and whether team-level guardrails are needed to scope it to particular keys or teams. Team-level guardrails and logging are listed among LiteLLM Enterprise features, so an open source deployment may need a different control. Ask the vendor to confirm this in writing before you write it into a control narrative.

LiteLLM Enterprise docs

Overlap with DLP tools

Confirm what your existing DLP product sees and what the gateway sees, because the two may not match. A DLP tool at the browser or network edge can miss traffic that bypasses it, and the gateway can miss traffic that never reaches it. Write down which tool owns which path, and test a secret through each path to confirm where it is caught.

Questions teams ask before adding secret redaction to LiteLLM

What drives the cost of adding secret redaction to LiteLLM?

The main drivers are the number of teams and callers that send traffic through the gateway, the number of guardrail policies you need, and how wide the test scope is. A single shared gateway with one default policy is a small job. Several teams with different keys, models and exceptions add configuration, review and retest work. Costs are paid for planning, configuration, testing against your own secret formats, and handover. Ask for a quote that lists each of these as separate line items, states which items are one-time, and says what a later retest or policy change costs. DeployOpen does not publish a price list, so a quote follows from the written scope.

How long until the first working secret redaction test?

The first useful test is usually the hide-secrets guardrail running on a non-production gateway, sending known fake secrets and confirming they reach the model as redacted text. How long that takes depends on whether the gateway is already running, whether you have a configuration-as-code workflow, and how many teams need to be tested. Ask for the timeline in the written scope with milestones for the test environment, the first redaction test and the production rollout. No duration is given here because the time depends on your environment.

What does the work need from our own team?

Plan for three groups of people. Gateway administrators provide access to the LiteLLM configuration, the proxy and a non-production environment. Security reviewers decide which secret types matter, approve the redaction behavior and review test results. Test secret owners supply fake keys and tokens in the formats your organization issues, so tests reflect real patterns without exposing live credentials. Confirm who can approve changes to guardrail settings before the work starts, since those settings affect every caller that routes through the gateway.

Can our own engineers build secret redaction in-house?

Yes, if your team already runs LiteLLM and can read its guardrail configuration, test it and keep it under version control. The hide-secrets guardrail runs in pre_call mode and replaces detected secrets in request messages with [REDACTED] before the model call, so the configuration itself is short. The effort is in deciding which secret formats to cover, testing for misses and false positives, and keeping the setup working through upgrades. Teams without that capacity often bring in a partner for the initial build and tests, then keep ownership in-house.

Does secret redaction replace our DLP tool?

No. Secret redaction at the gateway removes credential-shaped strings from prompts before they reach a model provider, which covers a narrow and important risk. Data loss prevention tools look at a wider set of data, such as personal data, financial records, documents and traffic that never passes through the gateway. Keep your DLP tool and treat redaction as one control within it. Confirm with your security team which traffic paths the DLP tool already covers and where the gateway adds coverage.

What should we do about secrets that were already sent to a model provider?

Redaction only protects future requests. Treat any secret that was already sent as exposed: rotate or revoke it at the issuing system, check the provider's retention and logging terms for the account, and review your own gateway logs to find which keys, users and models were involved. Then record the incident under your existing process. Redaction logs and the gateway request logs help scope the exposure, so confirm before enabling any change that could alter what is logged. Your legal and privacy teams should decide whether any notification duty applies.

How do we know redaction catches the secrets we care about?

Test with fake secrets in each format your organization uses, sent through the same paths your callers use, including streaming and multi-message requests. Record which secrets were redacted, which were missed and which normal text was changed by mistake. Check that the redacted prompt still works for the model and that the original secret never appears in gateway logs. Ask for the test scope in writing, including the secret types, endpoints and teams covered, and a retest after any configuration change.

Who should own the guardrail after go-live?

Assign one owner for the guardrail configuration and a second person for review, both inside your organization. The owner handles new secret types, exceptions and upgrades, and the reviewer checks changes before they reach production. Upgrades matter because the LiteLLM release line and guardrail behavior change over time. Ask whether support or retesting after go-live is part of the scope, and whether it runs as a fixed task or as an ongoing retainer.

What a DeployOpen engagement covers for secret redaction

A DeployOpen secret redaction engagement starts with a written scope that names the self-hosted LiteLLM proxy, the teams and keys in scope, the models and providers that receive traffic, and the points where the hide-secrets guardrail must run. The work then covers configuring that guardrail in the guardrails section of the proxy configuration, wiring it to the request paths your developers and chat clients actually use, and confirming how it behaves on the message types you send. Deliverables, timelines and the handover format are agreed in the same written scope before any change is made to your environment, so you can compare the quote against your own team's effort.

Testing uses planted secrets: test values shaped like cloud access keys, database passwords and service tokens are pasted into prompts across the endpoints in scope, and the team checks that each one reaches the model provider as [REDACTED] and that the provider never receives the original value. The results are documented as evidence for your security and compliance reviewers, including the configuration as it was tested, the test cases, the observed request and log output, and the gaps found with their fixes. After changes to the proxy, guardrail settings or model routes, the same tests are rerun and the retest results are added to that evidence. Confirm with your reviewers which artifacts they need, since their format requirements vary.

DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. An independent auditor or certification body decides whether your controls meet a given framework, and that decision is yours to request. Ask in the scoping conversation which findings you will receive, how retests are priced in the quote, and whether ongoing retesting should move to a retainer. Secret redaction at the gateway is one control among several, and the scope should say clearly which other controls, such as your DLP tooling, remain outside this engagement.

How DeployOpen scopes and supports LiteLLM guardrail work

DeployOpen treats secret redaction at the LiteLLM gateway as one control in a larger set: the hide-secrets guardrail, the rules around it, and the evidence your security team needs to review it. Work is agreed as a fixed scope covering the gateway, the guardrail configuration, the test cases and the handover, with ongoing support available as a retainer.

How we scope

  • Inventory which apps, teams and keys send prompts through the gateway and which model providers receive them
  • Agree which keys or teams the hide-secrets guardrail covers, and where it runs in pre_call mode
  • Record in writing how DeployOpen will test detection, how fallback behavior is handled, and what is excluded

How we build

  • Enable the hide-secrets guardrail on a non-production LiteLLM proxy and attach it to the agreed keys or teams
  • Build a labeled test set of fake credentials, tokens and passwords in realistic prompt formats, and record what is redacted
  • Check that redaction happens before the model call, and that logs store the redacted text rather than the original secret

How we hand over

  • Deliver the guardrail configuration as files your team can version, review and promote through your change process
  • Document the test results, known misses, and the gap between the built-in check and any DLP tool you already run
  • Walk your engineers and security reviewers through the runbook for adding detection patterns and reviewing blocked or redacted traffic

How we support

  • Retest the guardrail after each LiteLLM upgrade, since supported release lines change over time
  • Review new secret formats your developers introduce and update the test set to cover them
  • Ongoing support, upgrades and continuous testing are available as a retainer, scoped in writing

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.