mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-05 08:07:05 +00:00
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> |
||
|---|---|---|
| .. | ||
| guardrail_hooks | ||
| test_guardrail_endpoints.py | ||
| test_guardrail_registry.py | ||
| test_init_guardrails.py | ||
| test_pillar_guardrails.py | ||
| test_prompt_security_guardrails.py | ||