LiteLLM guardrail modes: pre_call, during_call and post_call

LiteLLM guardrail modes decide when a check runs relative to the model call, which sets how much latency, cost and blocking certainty you get. This page explains each mode and how to choose.

On this page

Choosing when LiteLLM guardrails run: LiteLLM guardrail modes explained

A security or platform lead screening prompts and responses on a shared gateway needs to decide one thing first: when in the request the check runs relative to the model call. In LiteLLM, the guardrail mode sets that timing. A pre_call check runs before the request reaches the provider and can block it, during_call runs alongside the model call so the provider's response time is not added to the check, and post_call inspects the model's response before it returns to the caller. LiteLLM is both a Python SDK and a proxy server that calls more than 100 providers using the OpenAI request format, and guardrails attach to the proxy, so every application that routes through the gateway inherits the same check without changing its code.

The mode is a per-guardrail setting, so one gateway can run a blocking check on prompts and a logging-only check on responses at the same time. Pick pre_call when a leaked secret or a disallowed prompt must never reach an external provider, accepting the added latency of the check on every request. Pick during_call when latency matters more and a short window of parallel processing is acceptable, keeping in mind that a request blocked late may already have been sent. Pick post_call when the risk sits in what the model returns, and plan how the gateway handles a response that has already been generated and paid for. Logging-only modes suit a rollout where teams need evidence of what would have been blocked before enforcement starts.

The exact mode names, which modes each guardrail supports, and whether a logging-only or default-on option exists all depend on the guardrail integration. Confirm these in the LiteLLM documentation for the specific guardrail and in a test deployment, using your own sample prompts and a deliberately unsafe payload, before writing enforcement rules. Check the LiteLLM docs: Enterprise page as well, since some guardrail controls are tied to the edition you run.

How pre_call, during_call and post_call differ in latency, blocking and cost

A pre_call guardrail runs before LiteLLM sends the request to the model provider. It inspects the messages and any tool definitions the caller supplied, and it is the placement that can stop a request before the provider sees any of it. Because the request waits for the verdict, the check time sits in front of the model call for every request, including the ones that pass.

  • Blocking: a failed check returns an error to the caller and no provider call is made, so the provider does not bill for that request.
  • Latency pattern: the full duration of the check is added before the model starts, on every request, so the cost of a slow check is paid on all traffic.
  • Cost of a blocked request: the gateway pays for the check itself, the provider charge is zero, but the calling application must handle the error and may retry.
  • Best fit: prompt injection screening, stopping secrets or regulated identifiers from leaving your network, and policies where any provider exposure is unacceptable.

Confirm in the LiteLLM documentation for your release which guardrail integrations support pre_call and exactly how a block is returned to the calling application.

Guardrail options and when each fits

This table compares the ways a LiteLLM guardrail can run: before the model call, alongside it, after the response, in monitor mode, and as a default for all traffic. Read each row for what it protects against and what it adds to latency and spend. Attaching guardrails to specific teams, keys or models is covered on the policies page. Confirm mode names and behavior against the LiteLLM version you run before writing policy.

OptionWhat it doesLatency and cost effectWhen it fits
pre_callChecks the request before the model is called and can block or modify it. Stops prompt injection, secrets and personal data before a provider receives them.Adds the guardrail's full response time to every request. Blocked prompts spend no provider tokens.Data that must never reach a provider, such as regulated records or credentials.
during_callRuns in parallel with the model call, so the check and generation overlap. Catches the same input risks as pre_call.Little added wall-clock time if the check is faster than the model. Blocked requests may still incur token charges.Latency-sensitive routes where some wasted provider spend on blocked requests is acceptable.
post_callChecks the model's response before it returns to the caller. Catches leaked data, unsafe output and risky tool-call content the input check missed.Adds latency after generation finishes. The provider has already billed for the output.Output risks such as data leakage in answers, or a second layer after pre_call.
Logging-only or monitor modeRuns the check and records matches without blocking or changing traffic. Shows false positives and match volume before enforcement.Little user-facing latency beyond the check itself, plus added log storage.Rollout and tuning, before a guardrail is switched to blocking.
default_onApplies a guardrail to every request, including keys and teams that did not attach it. Closes gaps where new keys skip screening.Adds check cost and latency to all traffic, including low-risk routes.Organization-wide baseline controls that every team must inherit.

A pre_call check can stop a request before the provider sees it

The request starts at the calling application, crosses into the LiteLLM gateway, and reaches the pre_call check, which can block it before any provider call. A passing request goes to the provider while a during_call check runs alongside it, and that check can stop the call if it fails. The provider's response returns to the gateway, where the post_call check reviews it before the answer goes back to the caller. A logging-only path records results without blocking. Confirm which zone each provider endpoint sits in, since only the gateway zone is in your infrastructure.

Trust boundaries and the point where each guardrail mode runs.

How to configure guardrail modes in a self-hosted LiteLLM proxy

This sequence turns a running LiteLLM proxy into one where each guardrail mode is defined, attached to the right traffic, tested with clean and flagged requests and confirmed in logs. The output is a dated record showing that every mode behaves as the security team specified on the release in use.

  1. Confirm the proxy version and database

    The platform engineer records the LiteLLM version in use and compares it with the GitHub releases page, which lists v1.105.1 as published October 14, 2026. Guardrail config keys can change between releases, so the team reads the release notes for its own version before editing anything. Virtual keys require PostgreSQL, so confirm that database is running and that LITELLM_MASTER_KEY is stored in a secret manager. Done when the version, database and secret reference are written into the change record.

  2. Enable guardrails in the config file

    The platform engineer adds a guardrails section to the proxy config.yaml and restarts the proxy with the updated file. Key names and accepted values for this block must be confirmed against the release in use, since a mismatch here is the most common reason a guardrail silently fails to load. Confirm that the proxy starts without configuration errors and that the startup log or admin UI lists the guardrails as loaded. Done when the health check passes and the reviewed config file is committed to version control.

  3. Define each guardrail with its mode

    The security engineer writes one guardrail entry per check and assigns its mode. pre_call runs before the model call and can stop the request, during_call runs alongside the call, and post_call inspects the model's response before the caller receives it. A logging-only option, where the release offers one, records matches without changing the response, so confirm its exact name in the release notes. Pre_call adds its check time to every request, while during_call keeps that wait off the path before the call but can still incur provider cost for a request that is later blocked. Done when each guardrail appears under its own name with the mode the policy requires.

  4. Attach guardrails with default_on or per key

    The platform engineer sets the scope for each guardrail. default_on applies it to all traffic through the proxy, while attaching it to a specific virtual key limits it to that key's callers. Start with a dedicated test key and a non-production model group so that a broad default does not block production teams during setup. Confirm how the release resolves a key that has its own guardrail list alongside a default. Done when a request made with the test key shows the guardrail as attached, and a request from a key outside the scope does not.

  5. Test a clean request in each mode

    The tester sends a benign prompt through each guardrail mode using the test key and records the status code, response content and latency. The expected result is a normal completion from the model, with each guardrail recorded as passed. Compare the latency with a baseline call that has no guardrail attached, so the team can see what each mode adds in its own environment. Done when a clean request succeeds in every mode and the baseline timings are saved with the test record.

  6. Send a flagged request in each mode

    The security tester sends an input the guardrail is configured to catch, agreed in advance with the security owner, and records the result for each mode. For example, an illustrative dummy card-number pattern in the prompt should trigger the card-number check. A pre_call guardrail should stop the request before any provider call, a during_call guardrail should block or mask according to the release's behavior, and a post_call guardrail should withhold a flagged response. Confirm the actual behavior for your release by reviewing the test output and the provider-side log. Done when each mode returns the blocked or masked result the policy requires.

  7. Check logs record each outcome

    The operations engineer searches request logs for the clean and flagged test calls and confirms that each entry names the guardrail, its mode, the outcome and the key used. The team also checks whether the stored log contains prompt or response text, since that depends on logging settings and affects privacy review. Confirm the log destination and retention period with the team that owns that system. Done when every test call has a matching log entry with a traceable outcome, and the findings are filed alongside the configuration version.

What adding a guardrail mode costs in latency, spend and reliability

Latency depends on where the check sits in the request. A pre_call check blocks the request until the guardrail returns, so its full response time is added before the provider call starts. A during_call check runs alongside the provider call, so its time overlaps with generation and is only exposed when it finishes after the model does. A post_call check adds its full time after the model has already generated the answer, and the caller waits for both. The practical question for your team is which of these waits your users can tolerate on the path they use most, and whether a streaming response can be checked before the first token is returned. Confirm that behavior for your LiteLLM version in the official guardrail documentation before you set expectations.

Spend has several sources, and only some of them are visible on the LiteLLM bill. External guardrail services usually charge per request, per character or per call, so the cost scales with every screened prompt and response, including the ones that are later blocked. LLM-based checks add a model call per screened message, which means extra tokens billed by your provider on top of the application's own traffic. Retries add cost too: if a guardrail call times out and LiteLLM retries it, or if your fail-open or fail-closed setting causes repeated calls, the same request is paid for more than once. Ask each guardrail vendor for its pricing unit, its free tier limits and what counts as one screened request, and compare that with the request volume your gateway logs show for the same keys and models.

Reliability is the cost that does not appear on an invoice. A pre_call guardrail that is slow or unavailable can stall every request routed through it, so the timeout and the behavior on failure belong in the design review, not after the first outage. A post_call check can hold a response the model has already spent money generating. Get figures from the guardrail vendor's published service levels and from a load test in your own environment, using your real prompt sizes, concurrency and key-level traffic. Treat any number from a vendor page or a blog post as a starting point to verify, not a planning baseline.

Security risks of fail-open modes and logging-only guardrails

A guardrail that is configured but does not block is easy to mistake for protection. The cards below cover the places where LiteLLM guardrail modes can pass sensitive traffic through, and the checks that show whether a given setup actually enforces what the team intended.

Logging-only mode blocks nothing

A guardrail in logging-only or monitor mode records matches but never stops a request. Teams often enable it to measure false positives, then forget to switch it to a blocking mode before production use. Before go-live, confirm for each guardrail whether it blocks, masks or only logs, and check the mode on the gateway itself rather than in the design document.

Production guide

Fail-open passes traffic when unavailable

If an external guardrail service times out or returns an error, a fail-open setting lets the request continue to the model unscreened. This trades availability for control, and the trade is rarely made on purpose. Ask the owner of each guardrail which behavior applies to outages, and test it by stopping the guardrail service during a staging run.

Post_call cannot stop sent data

A post_call guardrail inspects the model response after the provider has already received the prompt. Any personal data, secret or regulated record in the request has left the gateway by the time the check runs, so post_call cannot undo that exposure. Use it for output checks, and place input screening in pre_call or during_call where the data is still inside your control.

Default_on can miss keys or teams

A guardrail set to run by default applies to every request only if the gateway loads that default for each key, team and model path. Keys created through other paths, service accounts or newly added models can fall outside the intended scope. Review which keys and teams actually receive the guardrail and test one request from each group.

Guardrail configuration needs admin control

Guardrail settings decide what data is screened, so an unreviewed edit can silently weaken a control. Limit who can create, change or disable guardrails to named administrators, and record each change with a reason and an approver. Confirm which role model your edition supports, since team-level guardrail controls are documented under Enterprise.

Flagged logs may hold sensitive data

Logs of blocked or flagged requests often contain the exact prompt text that triggered the guardrail, which may include the personal data or secret the control was meant to protect. Decide what content is stored, who can read it, and how long it is kept, and set a retention period in your log store that matches your privacy obligations.

Questions teams ask before setting LiteLLM guardrail modes

What does a partner charge for a LiteLLM guardrail rollout?

A partner's fee follows from a written scope, so no standard price applies. DeployOpen does not publish a price list and provides a quote once scope, deliverables and timelines are agreed in writing. The main cost components are discovery of which teams, keys and models need screening, gateway configuration and database and cache setup, the guardrail integration itself, testing against your own traffic, and handover documentation. Upgrades and continuous testing can be contracted as a retainer. Ask any quote to separate one-time build work from recurring support, and to state which guardrail services are included and which must be licensed separately.

How long does a LiteLLM guardrail rollout take?

Duration depends on how much the gateway must screen and how quickly your organization can make decisions. The largest factors are the number of teams, keys and models that need different guardrails, whether an external guardrail service needs procurement or security review, whether you need Enterprise team-level guardrails, and how quickly you can supply a test corpus and sign off on block behavior. Each of these should be confirmed in the written scope. Ask the partner to name the phases, the decisions each phase depends on, and which of your teams must be available for review.

What must our team provide for a LiteLLM guardrail project?

Three inputs usually decide whether the project moves on schedule. First, provider access: credentials and endpoints for each model provider and for any external guardrail service, with the region settings they require. Second, a test corpus: representative prompts, responses and tool outputs from your use cases, including examples that should be blocked, masked or allowed. Third, a log destination: where request logs, guardrail decisions and alerts should go, along with retention rules. The gateway also needs PostgreSQL for virtual keys, and Redis 7.0 or newer once more than one proxy instance runs. Check the LiteLLM production guide for current requirements.

Can an in-house team set up LiteLLM guardrails alone?

Yes, if the team already runs Kubernetes or similar infrastructure, operates PostgreSQL and Redis, and can edit gateway configuration as code. Built-in checks and external guardrail services are configured in the proxy, so the technical work is within reach of a platform team. The harder parts are policy decisions: which content is blocked, which is masked, which teams are exempt, and what happens when a guardrail service is unavailable. Team-level guardrails and their logging are part of LiteLLM Enterprise, so confirm the edition you need before designing per-team policies. Many teams keep ownership of policy and bring in a partner for the build and testing.

Which LiteLLM guardrail mode should we start with?

Start in a monitoring or logging-only setup on a limited set of keys, then move to blocking once you know the false-positive rate for your traffic. Pre-call checks run before the model call, so they can stop a request before any provider receives it, but they add their processing time to every request. During-call checks run in parallel with the model call, which reduces added latency, but a response may already be in progress when a block decision arrives. Post-call checks inspect the response, so the prompt has already reached the provider. Confirm the exact behavior of each mode in the release you run, and document which risks each mode accepts.

How do we test that LiteLLM guardrail blocking works?

Test blocking with the same corpus you use for false positives, and check the outcome at each layer. For a test prompt that should be blocked, confirm that the caller receives the expected error, that the provider's own logs show no forwarded prompt for pre-call configurations, and that the gateway records the decision with the key, team and model. Repeat the tests for streaming responses, tool calls and each model route, because a policy may cover one endpoint but not another. Simulate an unavailable guardrail service to confirm whether the gateway fails open or closed, and rerun the suite after each upgrade. An illustrative test matrix might list each team, key and model against each expected outcome.

How much latency does a LiteLLM guardrail add?

The added time depends on where the check runs, how long the guardrail takes, and whether an external service is called over the network. Pre-call checks add their full processing time before the model call starts. During-call checks overlap with the model call, so their added time is smaller for successful requests, but blocked requests still need a clean cancellation path. Post-call checks add time after the response is generated. No general figure applies to your setup, so ask the partner to measure a baseline with and without each guardrail under a load test that resembles your production traffic, then record latency at the percentiles your users feel.

What DeployOpen confirms before a guardrail rollout

Before any guardrail is switched on, DeployOpen puts the mode decisions in writing for your self-hosted LiteLLM deployment. The working document maps each data class you handle (for example, payment identifiers, health information, credentials, employee records or customer contact details) to a guardrail mode: blocking before the model call in pre_call, parallel checking in during_call, response checking in post_call, or logging only. Each mapping names the guardrail, the endpoints and routes it applies to, the keys, teams or models it is attached to, and who approves a change. Confirm with your security team which data classes count as blocking-grade and which may be logged for tuning, because that decision drives the latency and cost trade-off more than any setting.

Each mode then gets its own test cases, run against the gateway inside your infrastructure. For pre_call, tests confirm that a blocked request never reaches the upstream provider and that the caller receives a clear rejection. For during_call, tests confirm the model call is not delayed by the check beyond what you accepted, and that a late block is handled as you specified. For post_call, tests confirm what happens to a response that fails the check, including whether the content has already been returned. Tests also cover default_on behavior for keys that were created before the policy existed, and logging-only mode, where tests confirm that matched content is recorded and that the record is handled under your retention rules. Confirm with the engineering team which of these behaviors your LiteLLM release version supports, since mode names and semantics change between releases.

The output for security reviewers is a dated decision record, the test results for each mode, the configuration as code, and the logs that show a blocked or flagged request from start to finish. DeployOpen prepares these artifacts and the control evidence they support, but it does not issue audit reports or certifications; your assessors and certification bodies draw their own conclusions. Ask for the record format before the engagement starts, and agree on who signs off each mode decision and how often the mapping is reviewed.

How DeployOpen scopes, delivers and supports LiteLLM guardrail rollouts

DeployOpen starts by mapping which requests, tool calls and responses need screening, and at which point of the LiteLLM request lifecycle each check should run. The work is then built, tested and handed over in your own infrastructure, with pre_call, during_call and post_call behavior documented per team, key and model.

How we scope

  • Inventory the endpoints, teams, keys and models that will pass through the gateway and the data classes they may carry.
  • Decide per guardrail whether it blocks before the model call, runs in parallel with it, or checks the response afterward.
  • Agree in writing which latency budget, logging-only periods and default_on coverage apply, before any build starts.

How we build

  • Configure guardrails in the LiteLLM proxy configuration and attach them to the agreed keys, teams and models.
  • Test blocking, masking and logging-only behavior with representative prompts, including responses and tool call payloads.
  • Measure added latency at each mode on your own deployment and record the results alongside the configuration.

How we hand over

  • Deliver the written configuration, a mode decision record and a test report showing expected and observed outcomes.
  • Document the runbook for changing a guardrail's mode, rolling back to logging-only and reviewing blocked-request logs.
  • Walk your platform, security and compliance teams through the evidence they will need for their own reviews.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer, including retesting after LiteLLM upgrades.
  • Ask any quote to separate one-time build effort from recurring support, and to name the LiteLLM release line it covers.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.