feat: add LiteLLM guardrail adapter (DataFogGuardrail)#154
Merged
Conversation
Offline PII guardrail for the LiteLLM proxy: pre_call redacts or blocks PII in request messages before egress, post_call redacts model responses. In-process, ~31µs per request — no sidecar service. Blocks surface as HTTP 400 guardrail interventions; engine errors follow a configurable fail policy (open/closed) and never leak matched text into logs or exception chains.
… coverage job Installs litellm in the nlp-advanced CI profile so the DataFogGuardrail tests execute where coverage thresholds are enforced, instead of being skipped and dragging patch coverage to zero.
Base litellm does not include fastapi (it's in their proxy extra), so test collection failed with ModuleNotFoundError in CI. Proxy deployments always ship fastapi; CI now installs it alongside litellm and the test module skips gracefully without it. Adds edge-path tests (no-messages data, non-text content parts, opaque responses, observability failure) bringing the adapter to 100% line coverage.
This was referenced Jul 2, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
DataFogGuardrail— an offline PII guardrail for the LiteLLM proxy (DFPY-117, second artifact of the growth-surfaces track after #152). Coded and tested against litellm 1.90.2.jane@…→[EMAIL_1]) before the request leaves the gateway, or blocks the request (action: block) with HTTP 400fail_policy: open(default — a guardrail bug never takes down the gateway) orclosed(compliance deployments where unscanned egress is worse than downtime)Config is three lines of YAML — see examples/litellm_guardrail/.
Review findings addressed (python-reviewer agent, traced against litellm internals)
from None(no__cause__chain — litellm callstraceback.format_exc()for alerting, which prints chained causes) and log only the exception type, neverstr(exc). Regression tests assert no PII in the exception chain or log records.ValueErrorhas nostatus_code, so litellm mapped blocks to 500 and misclassified them as backend failures. Now raisesHTTPException(400), which_is_guardrail_interventionrecognizes as a policy intervention.mode: ["pre_call", "post_call"](a barepre_callnever fires the response hook); decisions are recorded into litellm's standard guardrail logging withmasked_entity_count; post_call in-place mutation documented as intentional.Notes
datafog.integrations.litellm_guardrail) — not imported by datafog core; no new core dependencies. Requireslitellmonly when used.datafogguardrail provider to BerriAI/litellm following their guardrail-provider tutorial, using this as the reference implementation.Test plan
tests/test_litellm_guardrail.py): redact/block paths, content-parts form, multi-message, entity config, fail-open/fail-closed, no-PII-in-exceptions/logs regression tests