fix(pass_through): log pre-call guardrail blocks at WARNING, not ERROR with a traceback - #31500
Conversation
…R with a traceback A pre-call guardrail block on a pass-through endpoint (e.g. OpenAI moderation flagging disallowed content) was logged at ERROR level with a full stack trace, even though the guardrail is working as designed and the client correctly receives the 4xx. The generic except in pass_through_request logged every exception via verbose_proxy_logger.exception(), so an intentional block produced scary traceback noise for operators tailing logs. Branch on the existing CustomGuardrail._is_guardrail_intervention classifier (the same predicate pipeline_executor already uses) so guardrail interventions log once at WARNING without a traceback while genuine failures keep their ERROR and traceback. This covers every guardrail that signals a block through the shared typed exceptions or an HTTPException 400, not just OpenAI moderation, and leaves the client-facing response unchanged. Resolves LIT-3538
|
|
Greptile SummaryThis PR updates pass-through endpoint logging for guardrail blocks. The main changes are:
Confidence Score: 4/5The change is narrowly scoped to pass-through logging behavior and preserves client-facing error handling. The updated branch uses the existing guardrail intervention classifier and includes regression coverage for both intentional guardrail blocks and unexpected failures, reducing risk around the logging behavior being changed. No files need follow-up attention based on the reviewed changes.
What T-Rex did
Reviews (1): Last reviewed commit: "fix(pass_through): log pre-call guardrai..." | Re-trigger Greptile |
Greptile SummaryThis PR changes passthrough endpoint logging for guardrail blocks. The main changes are:
Confidence Score: 5/5The change is narrowly scoped to passthrough guardrail logging behavior and preserves the existing client-facing error path. The implementation reuses the existing guardrail-intervention classifier and adds targeted tests for both intentional guardrail blocks and genuine unexpected failures.
What T-Rex did
Reviews (1): Last reviewed commit: "fix(pass_through): log pre-call guardrai..." | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
6349065
into
litellm_internal_staging
…R with a traceback (BerriAI#31500) A pre-call guardrail block on a pass-through endpoint (e.g. OpenAI moderation flagging disallowed content) was logged at ERROR level with a full stack trace, even though the guardrail is working as designed and the client correctly receives the 4xx. The generic except in pass_through_request logged every exception via verbose_proxy_logger.exception(), so an intentional block produced scary traceback noise for operators tailing logs. Branch on the existing CustomGuardrail._is_guardrail_intervention classifier (the same predicate pipeline_executor already uses) so guardrail interventions log once at WARNING without a traceback while genuine failures keep their ERROR and traceback. This covers every guardrail that signals a block through the shared typed exceptions or an HTTPException 400, not just OpenAI moderation, and leaves the client-facing response unchanged. Resolves LIT-3538
Relevant issues
Resolves LIT-3538
Linear ticket
LIT-3538
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewScreenshots / Proof of Fix
Run a proxy on a pass-through endpoint with a pre-call guardrail that blocks on a trigger word (a ~15-line
CustomGuardrailwhoseasync_pre_call_hookraises a plainfastapi.HTTPException(400), exactly like_check_moderation_resultinopenai/moderations.py)Blocked request (trigger word present), both before and after the fix, returns the same correct 400 to the client
Before the fix, the proxy log shows an ERROR with a full traceback for what is the guardrail working as designed
After the fix, the same block logs once at WARNING with no traceback, and the client still receives the identical 400
A normal request (no trigger word) still passes through to the real provider and returns 200
Type
🐛 Bug Fix
Changes
A pre-call guardrail block on a pass-through endpoint was logged at ERROR level with a full stack trace, even though the guardrail is working as designed and the client correctly receives the 4xx. The generic
except Exceptioninpass_through_requestlogged every exception viaverbose_proxy_logger.exception(...), so an intentional block produced misleading traceback noise for an operator tailing logsThis branches on the existing
CustomGuardrail._is_guardrail_interventionclassifier, the same predicatepipeline_executoralready uses to separate intentional blocks from genuine errors. Guardrail interventions now log once at WARNING without a traceback while real failures keep their ERROR and traceback. Because the classifier already recognizes the shared typed guardrail exceptions (GuardrailRaisedException,BlockedPiiEntityError,SensitiveDataRouteException,ModifyResponseException) and anHTTPExceptionwith status 400, this covers every guardrail that signals a block, not just OpenAI moderation, without string-matching the exception detailThe client-facing response is unchanged; only the log level and the absence of a traceback differ. Tests drive the real
pass_through_requestand assert that a guardrail block logs at WARNING and not viaexception(), that a genuine non-guardrail error still logs viaexception()with its traceback, and the block still re-raises as the correct status