org.llm4s.agent.guardrails.builtin.SecretLeakGuardrail
See theSecretLeakGuardrail companion object
class SecretLeakGuardrail(val secretTypes: Seq[SecretType], val onFail: GuardrailAction) extends InputGuardrail, OutputGuardrail
Detects and redacts secrets / credentials in LLM input and output.
Prevents two classes of leak:
- Input leak: a user accidentally pastes an API key into a prompt that is then logged, cached, or forwarded to third-party LLM providers.
- Output leak: the LLM echoes a secret back in its response (e.g. when asked to summarise a config file that contains credentials).
Detected credential types (defaults):
- OpenAI API keys (sk-... / sk-proj-...)
- Anthropic API keys (sk-ant-...)
- Google API keys (AIza...)
- Voyage API keys (pa-...)
- Langfuse keys (pk-lf-... / sk-lf-...)
- AWS Access Key IDs (AKIA...)
- JWT tokens (eyJ...eyJ...sig)
Behaviour is controlled by GuardrailAction:
Block(default) – reject the text and return aLefterror.Fix– replace secrets with typed placeholders and continue (e.g.[REDACTED_OPENAI_KEY]).Warn– allow the text through unchanged; the caller may inspect theRightand decide what to log.
Example usage:
// Block any input that contains a credential
agent.run(
query = userInput,
tools = tools,
inputGuardrails = Seq(SecretLeakGuardrail())
)
// Mask secrets automatically and let the query proceed
agent.run(
query = userInput,
tools = tools,
inputGuardrails = Seq(SecretLeakGuardrail.masking)
)
// Also scrub LLM responses
agent.run(
query = userInput,
tools = tools,
outputGuardrails = Seq(SecretLeakGuardrail.masking)
)
Value parameters
- onFail
-
Action to take when a secret is detected (default: Block)
- secretTypes
-
Secret types to detect (default: all common provider keys)
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait OutputGuardrailtrait InputGuardrailtrait Guardrail[String]class Objecttrait Matchableclass Any
Members list
In this article