mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix: raise HTTPException(400) instead of CustomCodeExecutionError in apply_guardrail
Fixes #29436. When a custom code guardrail's execution fails (e.g. due to a policy violation raised inside user-provided code), the except clause wrapped the exception in CustomCodeExecutionError which is a plain Python Exception with no HTTP status mapping. The proxy's error handler therefore returned 500 instead of 400. Raising HTTPException(status_code=400) directly keeps the same informative error detail and is immediately handled by FastAPI, so the client receives the correct 400 response code.
This commit is contained in:
parent
a72414a061
commit
48c5596d83
1 changed files with 5 additions and 5 deletions
|
|
@ -257,11 +257,11 @@ class CustomCodeGuardrail(CustomGuardrail):
|
|||
verbose_proxy_logger.error(
|
||||
f"Custom code guardrail '{self.guardrail_name}' execution error: {e}"
|
||||
)
|
||||
raise CustomCodeExecutionError(
|
||||
f"Custom code guardrail execution failed: {e}",
|
||||
details={
|
||||
"guardrail_name": self.guardrail_name,
|
||||
"input_type": input_type,
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail={
|
||||
"error": f"Custom code guardrail execution failed: {e}",
|
||||
"guardrail": self.guardrail_name,
|
||||
},
|
||||
) from e
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue