mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-09 03:08:09 +00:00
7e57b15de2
* fix(guardrails): apply team-level guardrails alongside global policy guardrails Two bugs prevented team-direct guardrails from being automatically applied when using a team-scoped API key: 1. Auth caching: `valid_token.team_metadata` was never refreshed from the freshly-fetched team object at the "Check 6" step in `_user_api_key_auth_builder`. Guardrails added to a team after the key was first cached were therefore invisible to `move_guardrails_to_metadata`. Fix: propagate `_team_obj.metadata` → `valid_token.team_metadata` after every "Check 6" team fetch (user_api_key_auth.py). 2. Guardrail execution: `get_guardrail_from_metadata` checked `data["litellm_metadata"]` before `data["metadata"]`. When a request carried a non-empty `litellm_metadata` without a "guardrails" key, the merged guardrail list written to `data["metadata"]` by `move_guardrails_to_metadata` was shadowed and the guardrail received an empty requested-guardrails list (custom_guardrail.py). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix merge conflict --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>