mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-16 23:41:43 +00:00
fix(guardrail-create): surface config validation errors on create instead of silently orphaning guardrail in DB
This commit is contained in:
parent
433fdc7df6
commit
a731d10f19
1 changed files with 13 additions and 0 deletions
|
|
@ -342,6 +342,19 @@ async def create_guardrail(
|
|||
verbose_proxy_logger.info(
|
||||
f"Immediate sync: Successfully initialized guardrail '{guardrail_name}' (ID: {guardrail_id})"
|
||||
)
|
||||
except (ValueError, TypeError) as init_error:
|
||||
# Configuration error — roll back the DB write so the guardrail isn't orphaned
|
||||
if prisma_client is not None:
|
||||
try:
|
||||
await prisma_client.db.litellm_guardrailstable.delete(
|
||||
where={"id": guardrail_id}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Guardrail configuration error: {init_error}",
|
||||
)
|
||||
except Exception as init_error:
|
||||
verbose_proxy_logger.warning(
|
||||
f"Immediate sync: Failed to initialize guardrail '{guardrail_name}' (ID: {guardrail_id}) in memory: {init_error}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue