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 user, assistant, and tool messages of the request, each with its own role (tool results use the
toolrole). System prompts are not sent. - Output guardrails send the request messages 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 identity is taken from the authenticated TrueFoundry user, not from request headers.
Output guardrails are skipped for streamed responses.
Validation logic
TrueFoundry maps the HiddenLayeroutcome.action as follows:
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
Ordinary prompts or responses are blocked under Validate
Ordinary prompts or responses are blocked under Validate
HiddenLayer’s default policy can redact entities such as
PERSON, LOCATION, ORGANIZATION, and URL, and flag code or URLs as DETECT. Under Validate, any redaction or DETECT outcome is a violation, so a prompt like “What is the capital of France?” can be blocked because France is a LOCATION. Either narrow the redaction list in your HiddenLayer policy, switch the guardrail to Mutate, or run it with the Audit enforcing strategy.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, or use a Validate guardrail alongside the Mutate one.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 a redaction that the gateway could not apply safely (for example, a different number of messages than were sent), so the request was blocked instead of forwarded unredacted.