hiddenlayer-apim workflows.
End-to-End Request Guardrails
.env, list the available fragment packages, then deploy and apply request evaluation guardrails:
apply prints the inbound and outbound fragments it is about to inject and waits for yes before updating the APIM policy. Pass --yes to skip the prompt in CI or scripted runs:
Request and Response Guardrails
Deploy and apply both v2 packages:Preview Before Applying
Use--dry-run to inspect the API policy XML before updating APIM:
Update Existing HiddenLayer Resources
Deploy is non-destructive by default. If APIM already has a HiddenLayer named value or policy fragment with different content, the command stops instead of overwriting it. After reviewing the difference and deciding to replace the existing HiddenLayer-managed resources, run:deploy --overwrite lists the named values and policy fragments it will replace and waits for yes before continuing. Secret named values are shown by name only; their values are never printed.
Test an Applied API
Afterapply, send a request through your APIM gateway:
-i to show response headers. If HiddenLayer blocks a request or response, APIM surfaces:
Outcomes depend on HiddenLayer console policy configurationThe block, redact, and allow outcomes shown here are produced by the HiddenLayer policy attached to the project referenced by
HL_PROJECT_ID. Whether a given request is blocked, redacted, or allowed — and which entities are redacted — depends entirely on the rules and detection categories configured in the HiddenLayer console. The same request can produce a different outcome in another project. See Runtime Security Policy for how to configure policies, actions, and PII entities.Example: Prompt Injection Is Blocked
In this example the project’s policy has the Prompt Injection detection category set to Block. Thev2-request-evals package calls HiddenLayer on the inbound path, sees the BLOCK action, and returns an OpenAI-shaped payload to the caller without forwarding the request to the model. The response body replaces the assistant content with a “message was blocked” payload and the HL-Runtime-Action: BLOCK header is set on the APIM response.
Example: PII Is Redacted in the Response
In this example the project’s policy has a PII rule with action Redact that includes a US SSN entity. The request flows through to the backend, then thev2-response-evals package calls HiddenLayer on the outbound path and replaces the matched span with a token such as [REDACTED:US_SSN] before APIM returns the response to the caller.
Request:
Export Bicep
Generate a Bicep bundle for review or infrastructure-as-code deployment:apimServiceName. Deploy with Azure CLI:
./hl-bicep/main.bicepparam and pass --parameters ./hl-bicep/main.bicepparam instead.
Deploy From a Release Bicep Bundle
Customers who cannot run the CLI in their environment can deploy the pre-built Bicep bundle published with each GitHub release.- Download and extract
hiddenlayer-apim-vX.Y.Z-bicep.zipfrom the desired release. - Pick the package directory to deploy, for example
v1-interactions/,v2-request-evals/, orv2-response-evals/. - Set
apimServiceNameto your existing APIM service name. You can either edit the package’smain.bicepparamor pass the value on the command line with--parameters apimServiceName=<apim-name>. The resource group comes fromaz deployment group create --resource-groupand is not a Bicep parameter. - Preview and deploy one package directory at a time:
az deployment group create once per package directory.
After deployment completes, the fragments are available in API Management. To enable them on an API without running the CLI, open the target API in the Azure portal policy editor and add the package’s <include-fragment fragment-id="..." /> entries to the appropriate <inbound> and <outbound> sections. The package’s package.json manifest and fragments/ directory show which fragment IDs belong to each package.
Remove Guardrails From an API
Remove the fragments deployed by a specific package:remove previews the fragment IDs it will delete and waits for yes before updating the policy. When multiple HiddenLayer packages are applied, shared fragments such as hl-oauth-token-management are preserved so the remaining packages keep working.
Remove every detected HiddenLayer fragment in one step:
--yes:
remove only touches HiddenLayer <include-fragment> references and the correlation-ID setup it injects; unrelated APIM policy rules in <inbound>, <backend>, <outbound>, and <on-error> are preserved.
