litellm/litellm/proxy/guardrails
Hi120ki c9757cd0d7 fix(guardrails): populate applied_guardrails when Model Armor blocks content (#20034)
Previously, when Model Armor guardrail blocked a request/response,
the `applied_guardrails` field was not populated in the logs because
`add_guardrail_to_applied_guardrails_header()` was called after the
HTTPException was raised.

This fix moves the `add_guardrail_to_applied_guardrails_header()` call
to before the blocking check in all hooks:
- async_pre_call_hook (pre_call mode)
- async_moderation_hook (during_call mode)
- async_post_call_success_hook (post_call mode)
- async_post_call_streaming_iterator_hook (streaming)

This ensures that even when a guardrail blocks content, the guardrail
name is properly recorded in the logs for observability.

Added regression tests to verify applied_guardrails is populated when
content is blocked.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-02 18:21:44 +05:30
..
guardrail_hooks fix(guardrails): populate applied_guardrails when Model Armor blocks content (#20034) 2026-02-02 18:21:44 +05:30
guardrail_endpoints.py Guardrails - add built in guardrails for harmful content, bias, etc. (#18029) 2025-12-18 16:28:58 +05:30
guardrail_helpers.py build(pyproject.toml): add new dev dependencies - for type checking (#9631) 2025-03-29 11:02:13 -07:00
guardrail_initializers.py feat(panw_prisma_airs): add custom violation message support 2026-01-17 17:52:25 +05:30
guardrail_registry.py fix: properly handle custom guardrails parameters (#18978) 2026-01-14 03:23:54 +05:30
init_guardrails.py [Feat] Guardrails Load Balancing - Allow Platform admins to load balance between guardrails (#18181) 2025-12-19 00:08:03 +05:30