What is HiddenLayer?
HiddenLayer AISec is a runtime security platform for LLM applications. Detection and enforcement policies are defined in a project in the AISec Platform Console; the AI Gateway sends each guarded request to the HiddenLayer Detection v2 interaction-evaluations API and applies the outcome. In the TrueFoundry AI Gateway integration, HiddenLayer can run as either a Validate or Mutate guardrail. Validate inspects and can block. Mutate can also apply the redactions that your HiddenLayer project policy returns before the request continues.Key capabilities
- Prompt injection and jailbreak detection — Flags adversarial inputs designed to override system instructions.
- PII detection and redaction — Detects sensitive entities and, in Mutate mode, forwards the redacted text (for example,
[REDACTED:US_SSN]) instead of the original. - Policy-driven enforcement — Whether HiddenLayer alerts, redacts, or blocks is decided by the project policy you select with Project ID, not by the gateway.
- MCP tool coverage — The guardrail can also run on MCP tool calls and results.
Redaction only happens when the HiddenLayer project policy is set to redact for the entity. A policy set to alert returns a
DETECT outcome with no redaction. HiddenLayer treats PII in assistant messages more strictly than PII in user messages, so response-side redaction can trigger on content that is not redacted on the request side.Adding HiddenLayer to TrueFoundry
HiddenLayer is a first-class guardrail in the AI Gateway — you configure it through the same form as any other built-in guardrail, no adapter service required.1
Pick HiddenLayer from the guardrail registry
From AI Gateway → Guardrails → Registry, select HiddenLayer under External Providers. See Get started with guardrails for the end-to-end flow of adding any guardrail.
2
Create API credentials in HiddenLayer
In the AISec Platform Console, open the API Keys tab and create an OAuth2 client. Note the client ID and client secret, and the project ID or alias whose policy you want to apply. Keep the secret secure — it grants access to your HiddenLayer detection API.
3
Fill in the HiddenLayer form
Provide the following fields:
4
Bind the guardrail to models or tools with a rule
Once the guardrail is saved, attach it through a Guardrail Rule. Use
llm_input_guardrails to scan prompts before they reach the model, llm_output_guardrails to scan completions before they’re returned, and the MCP tool hooks to scan tool arguments and results.For a step-by-step walkthrough, see Getting Started. For the full policy reference, see Guardrails Configuration.What is sent to HiddenLayer
- Input guardrails send the system, user, assistant, and tool messages of the request, each with its own role (tool results use the
toolrole). System prompts are sent so HiddenLayer can detect tampering, and are never rewritten, even under Mutate. - Output guardrails send the request messages (including the system prompt) as context followed by the model response. Only the response is ever rewritten.
- MCP tool calls send each tool argument as a
usermessage and the tool result as a singletoolmessage. - Requester is the authenticated TrueFoundry user by default, or the fixed Requester ID if you set one. It is never taken from request headers or metadata.
- Session: when the request carries an
x-tfy-conversation-idheader, its value is sent asmetadata.external_session_id, so HiddenLayer can group the calls of one conversation. Send the samex-tfy-conversation-idon every turn; without it, each call appears as a separate entry in HiddenLayer.
Output guardrails are skipped for streamed responses.
Validation logic
TrueFoundry maps the HiddenLayeroutcome.action as follows:
HiddenLayer automatically replaces content it already redacted in earlier turns of a conversation, and reports
NONE when there is nothing new to detect. Validate forwards the original payload unchanged, so it treats that replaced text as a violation rather than passing the original history to the model. For conversations that carry history, use Mutate: it applies HiddenLayer’s returned text, so the model only ever sees the redacted history.
A violation blocks the request subject to your Enforcing Strategy. A redaction that cannot be applied — for example, HiddenLayer returns a different number of messages than were sent, or the payload cannot be rebuilt — is treated as a violation rather than forwarding the unredacted content.
If the HiddenLayer call fails (authentication error, timeout, 5xx), behavior follows your Enforcing Strategy:
- Enforce — fail closed; the request is blocked.
- Enforce But Ignore On Error — fail open; the request proceeds and the failure is logged.
- Audit — never block; violations and errors are logged only.
Example: Mutate redaction
With Operation: Mutate and a project policy that redactsEMAIL_ADDRESS and US_SSN, this prompt:
llm_output_guardrails. The guardrail check in the response shows transformed: true.
Example: blocked request
Error details contain only the action, threat level, rule names, and detected signal and entity types. They never quote the matched content.Supported detections
Exact detector enablement and actions are configured in your HiddenLayer project. Typical coverage includes:Migrating from the custom guardrail wrapper
Earlier setups ran theintegrations/hiddenlayer FastAPI wrapper behind a Custom Guardrail. The native integration replaces it:
After creating the native guardrail, update your guardrail rules or
X-TFY-GUARDRAILS selectors to the new <group>/<name> and remove the wrapper’s Custom Guardrail configs and deployment.
Troubleshooting
Prompt injection is not blocked under Mutate
Prompt injection is not blocked under Mutate
When the HiddenLayer policy lists prompt injection under Detect rather than Block, HiddenLayer returns
DETECT. Mutate passes DETECT through unchanged. To stop these requests, add the rule to the policy’s Block list in HiddenLayer. A blocked request is reported as a violation by the Mutate guardrail.PII is detected but not redacted
PII is detected but not redacted
Redaction is decided by the HiddenLayer project policy. Confirm the policy for that entity is set to redact rather than alert, that Project ID points at that project, and that the guardrail Operation is
Mutate. Under Validate, a redaction is reported as a violation instead of being applied.Test values such as 123-45-6789 are not flagged
Test values such as 123-45-6789 are not flagged
HiddenLayer’s detectors can allow obviously fake values that do not follow real-world structure. Test with realistic values.
Authentication errors (401)
Authentication errors (401)
Verify the Client ID and Client Secret, and that the Region matches your HiddenLayer tenant. The gateway refreshes its cached token once on a 401 before reporting the failure.
Requests are blocked with a redaction reason
Requests are blocked with a redaction reason
A
redaction_* reason means HiddenLayer returned text that the gateway could not safely use, so the request was blocked instead of forwarded unredacted:redaction_returned_under_validate— HiddenLayer returned text that differs from what was sent, usually earlier turns’ redactions in a conversation with history, and Validate cannot apply it. Switch the guardrail to Mutate, which forwards HiddenLayer’s redacted text to the model.redaction_message_count_mismatch— HiddenLayer returned a different number of messages than were sent.redaction_unavailableorredaction_not_applied— HiddenLayer reported a redaction that was missing from its response, or the gateway could not rebuild the request with it.