How Azure AI Content Safety Prompt Shield works at the LiteLLM gateway
A platform team routing approved models through LiteLLM needs jailbreak screening and text moderation before traffic reaches providers. LiteLLM's Azure Content Safety guardrail runs Prompt Shield only in pre_call mode, and Text Moderation can run in either pre_call or post_call mode. The guardrail is configured in the proxy's guardrail settings, so every request that passes through the gateway is screened by the same policy regardless of which provider serves it. It is not a separate connector that each application has to call.
The two checks answer different questions. Prompt Shield looks for jailbreak and prompt injection attempts in the user input before the model call, so pre_call is the only place it can run. Text Moderation scores content for categories such as hate, sexual content, violence and self-harm, and it can screen the incoming prompt or the model's response. Neither check is a substitute for the other, and neither covers sensitive data such as card numbers or secrets, which needs a separate control. Confirm the current category list, severity thresholds and the response format for each check in the LiteLLM Azure Content Safety documentation before you write policy against them.
Before you enable the guardrail, decide which teams, keys or models it applies to and what happens when Azure returns a block or cannot be reached. Check which Azure resource and region you will use, how the proxy authenticates to it, and whether Azure data handling terms fit your data classification. Test with known jailbreak samples in a non-production key, confirm that a blocked request is logged with enough detail for review, and confirm that streaming responses behave as your policy requires. Ask your Azure administrator to confirm the resource is in a region that meets your residency needs.
What you need before configuring Azure Content Safety guardrails
Before you add Azure AI Content Safety to LiteLLM, four foundations need to be in place: a deployed gateway, an Azure resource the gateway can reach, a network path between them, and a clear decision on which routes are screened. Each item below affects how the guardrail behaves in production, so confirm them before editing any guardrail configuration.
LiteLLM proxy deployment baseline
Run the LiteLLM proxy as a gateway with PostgreSQL as the database, since virtual keys and spend tracking depend on it. Once more than one proxy instance runs, add Redis 7.0 or newer for shared rate limits, router state and cache, or guardrail limits can drift between pods. Confirm the exact supported release line against the releases page before you pin an image, because the guardrail configuration syntax can change between minor versions.
LiteLLM releasesAzure AI Content Safety resource
Create an Azure AI Content Safety resource and record its endpoint and key. Prompt Shield and text moderation are separate capabilities, so confirm that the resource and region you choose expose both for your tenant. Confirm the region and API version in your own Azure environment, because availability and the API version that LiteLLM calls can vary, and store the key in your secret manager rather than in the gateway configuration file.
Azure Content Safety docsNetwork path from gateway to Azure
The gateway sends every screened prompt and response to the Azure endpoint, so egress must be allowed from the gateway network to that endpoint. In restricted or private networks, confirm whether the Azure resource is reachable through a private endpoint, a proxy, or an allowlisted egress address. Test this from the actual gateway pods or hosts, and record what happens when the endpoint is unreachable, since that determines your fail-open or fail-closed behavior.
Routes each guardrail applies to
Decide which model routes, teams and keys the Azure guardrail covers before you write any configuration. A guardrail that applies to every route adds a call to Azure on each request, while a narrow scope leaves some traffic unscreened. Document the list of model names and the owner of each route, because a later route added without the guardrail is a common gap in jailbreak screening.
Secret handling for gateway configuration
Keep the Azure key, the LiteLLM master key and the database credentials in a secret manager, and reference them from the gateway rather than pasting them into the config file. The master key must start with sk-. Check who can read the proxy configuration and the container environment, since anyone who can read the Azure key can call the resource outside the gateway and bypass your logging.
Test plan before enabling
Plan a test set of benign prompts, known jailbreak attempts and ordinary text that should pass moderation before you turn the guardrail on for real traffic. Run it in a non-production gateway with logging enabled, and record which requests were blocked and why. Agree the expected results with the security owner in writing, so the first production incident is not the first test of the policy.
Where Prompt Shield and Text Moderation sit in a request
The request starts at a client application inside the company network and reaches the LiteLLM proxy first. In the pre_call stage, the proxy sends the prompt to Azure AI Content Safety for Prompt Shield and Text Moderation, and only a passing result lets the call continue to the model provider. Text Moderation can also check the response after the model returns it, before the client receives it. Check that the block decision returns the error you expect to callers, and that the Azure resource sits on the side of the trust boundary your data policy allows.
Prompt Shield and Text Moderation checks at the LiteLLM proxy, with the Azure trust boundary marked.
Configuring the Azure guardrail in LiteLLM step by step
This sequence takes a self-hosted LiteLLM proxy from stored Azure credentials to a tested Prompt Shield and Text Moderation setup, with a check at each stage so you know the guardrail is actually screening traffic before wider rollout.
Store Azure credentials in the secret manager
Create the Azure AI Content Safety resource in the region your compliance team has approved, then place its endpoint and API key in the secret manager your LiteLLM deployment already uses. Do not paste the key into the proxy config file. Reference both values from the config by environment variable or secret name so the file can live in version control. Confirm that the proxy pod or service can read the secret and that the key does not appear in the proxy startup logs. The step is done when the proxy starts cleanly with the references resolved.
Define the Prompt Shield guardrail in pre_call mode
In the proxy configuration, add a guardrail entry that uses the Azure Content Safety integration with the Prompt Shield check. Set its mode to pre_call so it screens the request before the model provider is called, which is the only mode LiteLLM supports for Prompt Shield. Give the entry a clear name such as azure-prompt-shield so logs and policies identify it later. Restart or reload the proxy and confirm the guardrail appears in the admin UI or the guardrail list endpoint. The step is done when the guardrail loads without a configuration error.
Add a separate Text Moderation guardrail for input and output
Add a second guardrail entry that uses Text Moderation, configured as its own item rather than folded into the Prompt Shield entry. Enable it on input with pre_call and on output with post_call so harmful text is checked in both directions. Keeping the two entries separate lets you attach, test and remove each check independently. Confirm the entry loads and that both modes are shown as active. The step is done when both guardrail entries are listed with their intended modes.
Attach the guardrails to a test key or team
Create a test virtual key, or a test team and a key assigned to it, so the guardrails apply to a small population before any production traffic. Attach the Prompt Shield and Text Moderation guardrails to that key or team. Scope the key to one approved model so test results are easy to read. Verify in the key details that both guardrails are present. Attaching to a test identity first keeps the blast radius small if a check is misconfigured. The step is done when the key record lists both guardrails.
Send a benign test request
Call the proxy with the test key using an ordinary prompt, such as a short factual question, through the OpenAI-compatible endpoint. The request should pass all guardrails and return a normal model response. Check the response and the proxy logs to confirm that the guardrails ran and did not block the request. A passing benign request shows that the integration does not reject normal traffic. If it fails, check the Azure endpoint, key and region before changing any policy. The step is done when the benign request returns a completion and the logs record the guardrail calls.
Send an adversarial test request
Send a prompt that imitates a jailbreak attempt, such as an instruction asking the model to ignore its system prompt, using a text your security team has approved for testing. Prompt Shield should block it before the model provider receives the request. Confirm that the caller gets a guardrail rejection rather than a model answer, and that no call reaches the provider. Check the proxy logs for a guardrail event that names the Prompt Shield entry. The step is done when the adversarial request is rejected and the event is recorded.
Confirm logging and document the configuration
Review the guardrail events in your logging destination to confirm they include the guardrail name, the key or team, the outcome and the time. Record the config references, the attached policy and the test prompts used, in your configuration repository, so reviewers can reproduce the result. Ask Azure and your compliance team to confirm the data processing terms for the content sent to the service before expanding the policy. The step is done when the test evidence is stored and the events are visible to the team that will operate the gateway.
Choosing pre_call, post_call or both for each Azure check
Prompt Shield runs only in pre_call mode in LiteLLM, so it is the one Azure check that must finish before the provider receives the request. Its purpose is to stop jailbreak attempts before any model tokens are generated, which means a blocked request costs only the screening call and the gateway's own processing. The trade-off is that every request waits for the Azure check, so the added latency applies to all traffic on the guarded route, including requests that were never a risk.
- Cost effect: a blocked prompt avoids the provider charge entirely, since the model is never called.
- Latency effect: the screening round trip is added in front of every guarded request.
- Failure behavior: confirm whether the guardrail fails open or closed when the Azure endpoint is unreachable, because that decides whether an outage blocks users or lets traffic through unscreened.
- Best fit: routes that accept free-form user input from untrusted sources, such as public or customer-facing assistants.
- Scope limit: confirm with the LiteLLM documentation which endpoints and message types the check covers before relying on it.
Ask your security team to confirm the failure mode and the set of routes that must carry this check before you accept the latency cost.
Text Moderation on input runs in pre_call mode and screens the user's content for harmful categories before the provider call. It shares the blocking behavior of Prompt Shield, so it adds the same wait to each request, but it targets content risk rather than jailbreak patterns. Teams often use it on routes where users can submit material that would be unacceptable to pass to a model or store in provider logs, even when no adversarial intent is involved.
- Cost effect: blocked input never reaches the model, so provider spend is avoided for those requests.
- Latency effect: one additional Azure call precedes the model call on each request that the check covers.
- Overlap: a single route can run Prompt Shield and Text Moderation together, which adds both waits in sequence unless your configuration runs them in parallel. Confirm this with the LiteLLM documentation.
- Best fit: employee or citizen-facing tools where input categories are defined by policy.
- Tuning: confirm the severity thresholds in your Azure resource, since they determine how many legitimate prompts are blocked.
Run a sample of realistic prompts through a test route to measure false positives before you put the check on production traffic.
Text Moderation on output runs in post_call mode, after the provider has returned a response. The model call has already been made and paid for by the time the check runs, so a block removes the content from the caller but does not reduce the provider charge. Its value is in catching harmful generated text that input screening cannot predict, and in producing evidence of what the gateway withheld.
- Cost effect: the model charge is incurred on every blocked response, so output screening does not lower spend.
- Latency effect: the check adds time after the model finishes, which is noticeable on long generations and streaming routes.
- Streaming limits: confirm how post_call screening behaves when responses stream, because content may reach the user before the check completes.
- Best fit: public-facing answers where the model could generate content that the organization must not publish.
- Logging: a blocked output still appears in gateway logs, so confirm what is stored and for how long.
Decide whether withheld output must be logged in full or only as a category, since that choice affects both privacy review and storage.
Most decisions come down to one question: is the cost of a wrong input or a wrong output higher than the cost of waiting for a check? Prompt Shield and input moderation protect spend and stop unwanted requests early, so they suit routes with untrusted users. Output moderation protects what the organization publishes, so it suits routes where generated text is the main exposure. Running both on a high-risk route gives the most coverage and adds the most latency, while a low-risk internal route may need neither or only the output check.
- Start from risk: list the routes, the user population for each, and the consequence of a harmful input or output.
- Set a latency budget: agree with product owners how much added time each route can absorb.
- Separate routes: apply stricter checks to public routes and lighter checks to internal tools, using per-key or per-team configuration where supported.
- Measure before rollout: test added latency under realistic load, since the figure depends on your region, Azure resource and route.
- Review over time: revisit the mix after logs show which checks block real traffic.
Before approving a combination, confirm the expected latency with your own load test and the Azure pricing for your region and tier.
Mapping LiteLLM request fields to Azure content categories
This table maps each part of a request to the Azure check that screens it and the LiteLLM mode that runs it, with the key or team scope to confirm. Prompt Shield runs only before the model call, while Text Moderation can run on input and output. Confirm field coverage for your endpoint type before relying on any row.
| Request part | Azure check and LiteLLM mode | Scope and what to confirm |
|---|---|---|
| User prompt | Prompt Shield and Text Moderation, both pre_call | Both checks run before the model call, so a blocked prompt never reaches the provider. Confirm which endpoint types each check reads. |
| System message | Coverage not confirmed in the Azure guardrail documentation | Test whether a system message is included in the text screened on your endpoint before assuming it is checked. |
| Tool output | Coverage not confirmed for either check | Send a tool-calling request through the gateway and confirm whether returned tool results are screened before relying on this path. |
| Model response | Text Moderation, post_call only | Output checks run after generation, so they can stop or mask a response but cannot prevent the model from producing it. |
| Input text moderation | Text Moderation, pre_call | Runs alongside Prompt Shield on the same prompt. Confirm the category thresholds your team set in the guardrail configuration. |
| Output text moderation | Text Moderation, post_call | Confirm how this check behaves with streamed responses on your endpoint type before enabling it for chat clients. |
| Key or team scope | Guardrail attached to selected keys, teams or models | Team-level guardrails are an LiteLLM Enterprise feature. Confirm your edition supports the scope you need before designing policies around it. |
Securing the Azure credentials and the screening path
The Prompt Shield and text moderation checks are only as trustworthy as the path that carries them. The Azure key, the network route from the gateway to Azure, the master key that administers the gateway, the logs that record screened content, and the behavior when Azure cannot be reached all decide whether the screening control holds up under review.
Keep the Azure key out of config and logs
The Azure Content Safety key and endpoint belong in a secret manager that the gateway reads at runtime, not in the LiteLLM configuration file or in a repository. Check that the key does not appear in container environment dumps, startup logs, debug output or exported configuration. Rotate the key on a schedule you can document, and confirm that rotation does not require a gateway restart you have not planned. Ask your team which identity reads the secret and who else can read it.
Azure guardrail docsRestrict the Azure resource to the gateway
Azure AI Content Safety should accept calls only from the gateway's network path. Use the resource's network restrictions, private endpoints or a firewall rule that limits traffic to the egress addresses of your gateway. Confirm that application users and developer machines cannot call the Content Safety resource directly with the same key, because a leaked key would then bypass the gateway's logging and policy. Test the restriction from a host outside the gateway network.
Protect the master key
The LiteLLM master key administers virtual keys, budgets and guardrail settings. Its value must start with sk- and be stored in a secret manager, not in a values file or a shell history. Limit who can read it, use virtual keys for every application and person, and avoid handing the master key to pipelines. Treat any exposure of the master key as a reason to rotate it and review which guardrail settings changed while it was exposed.
Review guardrail logs for sensitive content
Guardrail logs and request traces can record the prompts that Prompt Shield or text moderation flagged, which may include personal data or secrets. Decide what the logs keep, who can view them, and how long they are retained, and confirm that the logging settings match the data handling rules you have agreed. Sample flagged entries regularly to check whether blocked content is being stored in plain text where you did not intend it.
Decide what happens when Azure is unreachable
If the Content Safety call times out or fails, the gateway either lets the request through unscreened or rejects it. Choose the behavior per use case, document the reason, and test it by blocking the Azure endpoint in a non-production environment. Confirm the error the caller receives, whether the failure appears in logs and alerts, and how the decision changes for high-risk applications. Do not assume the default matches your policy.
Treat Prompt Shield as one screening layer
Prompt Shield detects jailbreak attempts in the request before the model call. It does not replace access control on models and tools, and it does not perform data loss prevention on what users send or what models return. Pair it with virtual key restrictions, model allowlists and data controls, and test it with your own attack samples so the team knows what it misses.
Common failures in Azure guardrail setups
This table lists the failures teams most often hit when wiring Azure AI Content Safety into LiteLLM, with the likely cause and the fix for each. Read it before go-live, and use it as a checklist when a guardrail blocks traffic it should not, or fails to block traffic it should.
| Failure | Likely cause | Fix |
|---|---|---|
| Prompt Shield attached in post_call and not running | Prompt Shield only runs in pre_call mode, so a post_call configuration does not screen jailbreak attempts as intended | Set Prompt Shield to pre_call. Keep Text Moderation for pre_call or post_call if you need output checks, and confirm the mode in the gateway config. |
| Requests fail against the wrong endpoint or region | The Content Safety endpoint or region in the guardrail settings does not match the Azure resource that holds the key | Copy the endpoint from the Azure resource itself, confirm the region, and test the guardrail with one known-bad prompt before routing live traffic. |
| Authentication errors after a key change | The key was rotated or expired in Azure, or the value was pasted into a config file instead of read from a secret manager | Reference the key through your secret manager, rotate it on a planned schedule, and update the gateway secret rather than editing config files by hand. |
| Added latency on every call | A slow or distant Content Safety endpoint sits in the request path, and pre_call checks delay the model call | Place the Azure resource in the same region as the gateway, measure added latency with and without the guardrail, and set timeouts so a slow check cannot stall callers. |
| Benign prompts blocked | Prompt Shield or moderation thresholds flag normal business text, such as security training, fiction or quoted instructions | Review blocked request logs, adjust thresholds or categories where your policy allows, and route borderline teams to a narrower guardrail rather than disabling checks. |
| Guardrail not applied to the calling key | The guardrail was defined but never attached to the key, team or model that sends the traffic | Attach the guardrail to the key or team in the admin settings, then send a test request with that key and confirm the guardrail appears in its logs. |
Questions buyers ask before setting up Azure Content Safety with LiteLLM
Can our own platform team set up Azure Content Safety with LiteLLM without a partner?
Yes, if your team already runs the LiteLLM proxy, has Azure administration skills and can test guardrail behavior against its own traffic. The LiteLLM Azure Content Safety guardrail is configured in the proxy's configuration, so the work is mostly Azure resource setup, guardrail configuration, and a test plan that shows what gets blocked and what passes. Teams new to guardrails often underestimate the testing: they need prompts that should be blocked, prompts that should pass, and a decision on what happens when the Azure call fails. A partner is useful when that testing needs to be documented for a security review or when several teams need different settings.
What drives the cost of this work?
Cost has three components. Azure consumption is the first: Content Safety is a metered service, so spend depends on how many requests are screened and which features are called. The second is LiteLLM Enterprise, which you need only if you want team-level guardrails, so that Prompt Shield applies to some teams or keys and not others. Open source covers the global guardrail case. The third is the platform team's time for setup, testing, change approval and ongoing review. Ask any quote to separate the one-time setup work from recurring items such as retesting after upgrades and Azure usage reviews, and to state which Azure features are in scope.
How long does configuration and testing take?
The duration depends on scope. A single global guardrail for one proxy, tested against a short list of prompts, is the smallest case. Adding per-team or per-model settings, connecting to a secret manager for the Azure key, running the guardrail in both pre_call and post_call modes, and documenting the test results for a security review each add work. Your environment also matters: existing change windows, network rules for reaching the Azure endpoint, and how many LiteLLM instances run behind the load balancer. Ask for a written schedule that lists the configuration steps, the test cases and the approval points, rather than a single total.
What do we need to provide before the work starts?
You need four things. First, Azure access: an Azure subscription where your team can create a Content Safety resource, plus a way to issue the endpoint and key to the proxy. Second, a running LiteLLM proxy that the work can reach in a test environment. Third, a test plan: the prompts that should be blocked, the prompts that should pass, and the expected behavior for each. Fourth, change approval, because guardrails change what reaches model providers and most organizations require a review before production. Your security team should also confirm how a failed Azure call should be handled, because that choice decides whether requests are blocked or allowed through during an outage.
Does Prompt Shield run before or after the model call?
Prompt Shield runs only before the model call. LiteLLM supports Azure Content Safety Prompt Shield in pre_call mode only, which means it checks the incoming prompt for jailbreak attempts before the request reaches a provider. Text Moderation is different: it can run before the call and after the response, so you can screen both input and output for harmful content categories. Because of this split, a design that expects Prompt Shield to check model output will not work. Plan for Text Moderation on the output side if you need response screening. The configuration reference is in the LiteLLM Azure Content Safety docs.
What goes wrong most often in this setup?
The most common problems are a wrong endpoint or key in the proxy configuration, network rules that block the proxy from reaching Azure, and a guardrail mode that does not match the design. Teams also set thresholds too strictly, which blocks legitimate business prompts, or too loosely, which lets attempts through. Another frequent issue is confusing the check points: a team expects output screening from Prompt Shield and finds it is not applied after the response. When something fails, collect the LiteLLM proxy logs for the request, the Azure resource and region, the guardrail configuration, and the exact error returned, before changing settings.
What does a compliance review expect to see from this control?
A reviewer usually wants to know what is screened, where the check runs, what happens on a block or a failure, who can change the setting, and how the test results were recorded. Document the guardrail configuration, the test cases with expected and actual results, the fail behavior, and the change approval record. Keep in mind that DeployOpen prepares these systems, controls and evidence, but independent auditors and certification bodies decide whether the control meets a given requirement. Ask your assessor which evidence format they accept before the testing starts.
Testing Prompt Shield and moderation before production
Test Prompt Shield and text moderation as two separate controls with a written test plan, because they fail in different ways. Prompt Shield runs only in pre_call mode, so its tests must confirm that a flagged prompt never reaches the model provider, while Text Moderation can run pre_call and post_call, so its tests must cover what the caller receives back. Build the plan with four sets: benign prompts that represent normal use across each team and model group, a controlled set of known jailbreak patterns kept in your security team's repository, sample model outputs that should be moderated, and streaming and non-streaming requests. Run each set against the exact guardrail configuration that will ship, including the severity thresholds and the action set for each category.
Measure two things during the test run: false positives on benign traffic and the latency the guardrail adds to each request. Count every benign prompt that is blocked or modified, and record which category and threshold caused it, because the fix is often a threshold or an allowlisted use case rather than a new control. Time the same prompts with the guardrail enabled and disabled, using the gateway's own logs and your load test tooling, and confirm the added latency is acceptable for the applications that will call the gateway. Ask your Azure administrator to confirm the Content Safety resource region, quota and key handling, since these affect both the latency numbers and the test environment.
Record every result in a form the security review can reproduce: the LiteLLM and guardrail configuration version, the test set version, the date, each test case with its expected and actual outcome, the false positive list with reasons, and the latency figures with the method used. Keep the jailbreak set out of general developer access and store results in the same evidence location as your other AI gateway controls. Before go-live, agree in writing which failures block release, who approves exceptions, and when the test set is rerun after threshold changes, a LiteLLM upgrade or a change to the model list, since each can change the outcome.
How DeployOpen scopes and delivers this integration
DeployOpen plans and implements Azure AI Content Safety at your LiteLLM gateway inside your own infrastructure, with Prompt Shield and text moderation configured for the models and teams you approve. The work is agreed in a written, fixed scope before build starts, and every control is documented so your security and compliance teams can review it.
How we scope
- We confirm which models, keys, teams and endpoints the guardrail will cover in the written scope.
- We agree whether Prompt Shield runs before the model call and whether text moderation also checks responses.
- We record the Azure Content Safety resource, region and credential handling your team will provide.
- We define block, mask or log-only behavior and who decides the moderation thresholds for each category.
How we build
- We configure the Azure Content Safety guardrail in LiteLLM config, with keys held in your secret manager.
- We attach the guardrail to the agreed teams, keys or models rather than applying it globally by default.
- We test jailbreak attempts against Prompt Shield and check that blocked requests return the expected error.
- We verify that moderation on input and output logs what your audit requirements need, without storing unneeded prompt text.
How we hand over
- You receive the guardrail configuration, the scope record and the test cases with expected results.
- We document the fallback behavior if the Azure service is unavailable, so your team knows what callers see.
- We walk your platform and security staff through the monitoring signals and the steps for tuning thresholds.
- Deliverables are written so that an independent auditor can trace each control to its evidence.
How we support
- Ongoing support, upgrades and continuous testing are available as a retainer after handover.
- A retainer can cover re-testing after LiteLLM version upgrades, since supported release lines change over time.
- We can rerun Prompt Shield test cases when new models or endpoints are added to the gateway.
- Quotes follow from the written scope, so ask for the scope, deliverables and timeline in writing before you decide.

