litellm - ✅(Solved) Fix [Bug]: Error happen on the log for the conversation using custom-code guardrail [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23439Fetched 2026-04-08 00:36:50
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
labeled ×2cross-referenced ×1referenced ×1

Error Message

6a1d474f77e2682d.js:1 Uncaught TypeError: e.guardrail_mode.replace is not a function at P (6a1d474f77e2682d.js:1:30562) at av (7f9e9c54ac262de2.js:1:63258) at oY (7f9e9c54ac262de2.js:1:83531) at io (7f9e9c54ac262de2.js:1:94963) at sc (7f9e9c54ac262de2.js:1:137984) at 7f9e9c54ac262de2.js:1:137829 at ss (7f9e9c54ac262de2.js:1:137837) at u9 (7f9e9c54ac262de2.js:1:133762) at sH (7f9e9c54ac262de2.js:1:159478) at sA (7f9e9c54ac262de2.js:1:157692) P @ 6a1d474f77e2682d.js:1 av @ 7f9e9c54ac262de2.js:1 oY @ 7f9e9c54ac262de2.js:1 io @ 7f9e9c54ac262de2.js:1 sc @ 7f9e9c54ac262de2.js:1 (匿名) @ 7f9e9c54ac262de2.js:1 ss @ 7f9e9c54ac262de2.js:1 u9 @ 7f9e9c54ac262de2.js:1 sH @ 7f9e9c54ac262de2.js:1 sA @ 7f9e9c54ac262de2.js:1 sU @ 7f9e9c54ac262de2.js:1 (匿名) @ 7f9e9c54ac262de2.js:1

Fix Action

Fixed

PR fix notes

PR #25105: fix(guardrails): infer event_type from input_type in log_guardrail_in…

Description (problem / solution / changelog)

…formation for apply_guardrail

When apply_guardrail is called with a Mode-based event_hook and event_type=None, the logged guardrail_mode was set to a GuardrailMode dict instead of a string. This caused the UI error 'guardrail_mode.replace is not a function' (issue #23439).

Fix: in the log_guardrail_information decorator, after inferring event_type from the function name, also check input_type kwarg when func.name == 'apply_guardrail':

  • input_type='request' → event_type = GuardrailEventHooks.pre_call
  • input_type='response' → event_type = GuardrailEventHooks.post_call

This ensures guardrail_mode is always logged as a plain string, not a dict.

Relevant issues

<!-- e.g. "Fixes #000" -->

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

<!-- Select the type of Pull Request --> <!-- Keep only the necessary ones -->

🆕 New Feature 🐛 Bug Fix 🧹 Refactoring 📖 Documentation 🚄 Infrastructure ✅ Test

Changes

Changed files

  • litellm/integrations/custom_guardrail.py (modified, +30/-2)
  • tests/test_litellm/integrations/test_custom_guardrail.py (modified, +126/-2)

Code Example

6a1d474f77e2682d.js:1 
 Uncaught TypeError: e.guardrail_mode.replace is not a function
    at P (6a1d474f77e2682d.js:1:30562)
    at av (7f9e9c54ac262de2.js:1:63258)
    at oY (7f9e9c54ac262de2.js:1:83531)
    at io (7f9e9c54ac262de2.js:1:94963)
    at sc (7f9e9c54ac262de2.js:1:137984)
    at 7f9e9c54ac262de2.js:1:137829
    at ss (7f9e9c54ac262de2.js:1:137837)
    at u9 (7f9e9c54ac262de2.js:1:133762)
    at sH (7f9e9c54ac262de2.js:1:159478)
    at sA (7f9e9c54ac262de2.js:1:157692)
P	@	6a1d474f77e2682d.js:1
av	@	7f9e9c54ac262de2.js:1
oY	@	7f9e9c54ac262de2.js:1
io	@	7f9e9c54ac262de2.js:1
sc	@	7f9e9c54ac262de2.js:1
(匿名)	@	7f9e9c54ac262de2.js:1
ss	@	7f9e9c54ac262de2.js:1
u9	@	7f9e9c54ac262de2.js:1
sH	@	7f9e9c54ac262de2.js:1
sA	@	7f9e9c54ac262de2.js:1
sU	@	7f9e9c54ac262de2.js:1
(匿名)	@	7f9e9c54ac262de2.js:1
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

Application error: a client-side exception has occurred while loading secproxyai.gopayqa.com.cn (see the browser console for more information).

Steps to Reproduce

  1. Create a custom-code guardrail (Such as Email Redact)
  2. Talk to your LLM with this guardrail.
  3. Check the log

Relevant log output

6a1d474f77e2682d.js:1 
 Uncaught TypeError: e.guardrail_mode.replace is not a function
    at P (6a1d474f77e2682d.js:1:30562)
    at av (7f9e9c54ac262de2.js:1:63258)
    at oY (7f9e9c54ac262de2.js:1:83531)
    at io (7f9e9c54ac262de2.js:1:94963)
    at sc (7f9e9c54ac262de2.js:1:137984)
    at 7f9e9c54ac262de2.js:1:137829
    at ss (7f9e9c54ac262de2.js:1:137837)
    at u9 (7f9e9c54ac262de2.js:1:133762)
    at sH (7f9e9c54ac262de2.js:1:159478)
    at sA (7f9e9c54ac262de2.js:1:157692)
P	@	6a1d474f77e2682d.js:1
av	@	7f9e9c54ac262de2.js:1
oY	@	7f9e9c54ac262de2.js:1
io	@	7f9e9c54ac262de2.js:1
sc	@	7f9e9c54ac262de2.js:1
(匿名)	@	7f9e9c54ac262de2.js:1
ss	@	7f9e9c54ac262de2.js:1
u9	@	7f9e9c54ac262de2.js:1
sH	@	7f9e9c54ac262de2.js:1
sA	@	7f9e9c54ac262de2.js:1
sU	@	7f9e9c54ac262de2.js:1
(匿名)	@	7f9e9c54ac262de2.js:1

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.81.14

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

The fix involves ensuring that e.guardrail_mode is a string before attempting to call the replace method on it.

  • Check the type of e.guardrail_mode before calling replace:
if (typeof e.guardrail_mode === 'string') {
  e.guardrail_mode = e.guardrail_mode.replace(...);
} else {
  // Handle the case where e.guardrail_mode is not a string
  console.error('e.guardrail_mode is not a string');
}
  • Alternatively, use the toString() method to ensure e.guardrail_mode is a string:
e.guardrail_mode = e.guardrail_mode.toString().replace(...);
  • If e.guardrail_mode is supposed to be a string, investigate why it's not being set correctly and fix the underlying issue.

Verification

To verify the fix, repeat the steps to reproduce the issue and check the browser console for any errors. The Uncaught TypeError should be resolved, and the application should function as expected.

Extra Tips

  • Always check the type of a variable before calling methods on it to avoid type-related errors.
  • Use console.log or a debugger to inspect the value of e.guardrail_mode and understand why it's not a string.
  • Consider adding input validation to ensure that e.guardrail_mode is always a string.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING