litellm/tests/unit/proxy/management_endpoints
Agung Besti c482013a8a
fix(guardrails): log requests that a guardrail blocks on /apply_guardrail (#51014)
* fix(guardrails): record the guardrail verdict on a request dict that starts empty

The Bedrock guardrail and the shared `log_guardrail_information` wrapper both picked the request dict with `or {}`. An empty dict is falsy, so a caller that passed one had the verdict written to a throwaway dict. /apply_guardrail passes an empty dict for a request that carries no messages and no metadata, so nothing downstream could see what the guardrail decided. The verdict now goes to the dict the caller passed, and only a missing dict falls back to a new one.

* fix(guardrails): log requests that a guardrail blocks on /apply_guardrail

A request a guardrail blocked on /apply_guardrail was missing from the logs. The endpoint skipped the failure handlers for an HTTPException, the spend log failure hook wrote no row because the route is not an LLM API route, and the guardrail's verdict stayed on a request dict no logger reads.

The endpoint now runs the failure handlers for every exception and copies the verdict onto the logged request, so allowed and blocked requests both carry it along with the guardrail's cost. It marks the failure of a request it had set up with a sentinel, and the spend log failure hook writes its row for that mark. A request rejected before setup, such as one with a bad key or an unknown guardrail, is still not logged. Guardrail records a caller sends in metadata are dropped for both response formats so a verdict cannot be forged in the logs.

* fix(guardrails): keep Presidio and Gray Swan verdicts on empty request data

Presidio's text-only path and Gray Swan's API-failure path replaced an empty request dict with a throwaway one, so the verdict never reached the logged request. The apply_guardrail logging tests now run the real request setup and read what a logging callback receives.

* test(guardrails): cover the endpoint failure row, the sync decorator, and an unreachable Gray Swan without real sockets

* fix(logging): redact prompt text in guardrail records when message logging is off

* fix(logging): redact the failure payload when message logging is off

* fix(logging): keep guardrail details for other callbacks when one opts out of message logging

* fix(logging): redact failure events per callback and keep guardrail compression stats

A callback that turns off message logging now gets the same redacted copy on failure events as on success events, so a blocked /apply_guardrail call no longer hands it the raw prompt and verdict

Guardrail redaction keeps the numeric compression stats (tokens saved, compression ratio) that spend tracking reads, through one helper shared with the spend-log sanitizer

* fix(policy): test each batch input on its own copy of the request data

The guardrail logging decorator now records a verdict on an empty request dict instead of dropping it. The policy test endpoint shared one request dict across every input and merged it into the agent call, so each later input and agent request carried the earlier inputs' verdicts. Each input now gets its own copy, which keeps the caller's request data unchanged

* test(policy): look up the counting guardrail through the real registry

The batch isolation test now registers its guardrail as a litellm callback, so the endpoint finds it through the real guardrail registry instead of a mocked one, and its apply_guardrail override carries the same concrete types as the base class

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-16 15:18:08 -08:00
..
management_v1 fix(proxy): batch customer organization cascade deletion (#51969) 2026-11-16 08:03:45 +08:00
policy_endpoints refactor(types): replace Any with proven types in 14 files (#48928) 2026-10-29 07:26:07 -07:00
scim fix(scim): skip groups with no team so a PATCH or PUT still deactivates the user (#51829) 2026-11-14 12:06:52 -05:00
search_endpoints feat(search): add Microsoft Web IQ provider (#50883) 2026-11-10 22:43:36 +00:00
sso ci(unit): cut unit check time with cheaper per-test resets and fewer non-unit tests (#51864) 2026-11-14 15:41:30 -08:00
usage_endpoints feat(ui): unify gateway and usage assistance as Aria Agent (#48082) 2026-10-23 20:24:19 +00:00
__init__.py
jwt_key_mapping_doubles.py
test_access_group_endpoints.py feat(access-groups): name group vector stores and list them on team info (#51484) 2026-11-13 07:53:04 -08:00
test_access_group_management.py fix(budgets): invalidate customer hierarchy caches through stored team IDs (#51654) 2026-11-13 18:43:38 +00:00
test_activity_tenant_scoping.py
test_auto_router_endpoints.py feat(auto_router): report a session's whole spend and name why savings stay unestimated (#51066) 2026-11-10 17:07:11 -08:00
test_budget_endpoints.py fix(budgets): invalidate customer hierarchy caches through stored team IDs (#51654) 2026-11-13 18:43:38 +00:00
test_cache_settings_endpoints.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_callback_management_endpoints.py
test_common_daily_activity.py feat(spend): report guardrail spend separately in daily activity (#51010) 2026-11-10 13:02:26 -08:00
test_common_utils.py feat(proxy): per-model team member budgets with router fallback (#43887) 2026-10-10 20:33:55 +00:00
test_compliance_endpoints.py
test_config_override_endpoints.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_coordination_redis_endpoints.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_cost_estimate_endpoint.py refactor(router): move router callers onto the entry points and invert the proxy imports (#48847) 2026-10-29 17:26:33 +00:00
test_cost_tracking_settings.py fix(proxy): keep a cost settings update from being undone by an in-flight config reload (#51273) 2026-11-12 00:54:10 +00:00
test_credential_migration.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_customer_budget.py fix(proxy): /customer/new budgets reset on the same schedule as other budgets (#51689) 2026-11-13 19:22:14 +00:00
test_customer_endpoints.py feat(proxy): customer budget rollup, reset on the budget row's window, named templates, team overrides, multi-window limits and pause_allow_increase (#51582) 2026-11-13 16:05:35 +00:00
test_daily_activity_routes.py feat(ui): add Activity tabs to resource details (#50630) 2026-11-11 18:23:01 -08:00
test_delete_callbacks_endpoint.py
test_delete_verification_tokens_failed.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_encryption_endpoints.py test: migrate tests/proxy_behavior into integration and unit tiers (#45939) 2026-10-11 08:28:42 -07:00
test_entraid_app_roles.py
test_gateway_request_endpoints.py refactor(proxy): inject gateway activity through a typed repository (#49116) 2026-10-30 16:25:11 -07:00
test_id_jag_assertion_capture.py feat(sso): retain the SAML assertion at login as the saml2 subject token for oauth2_id_jag (#46745) 2026-10-16 12:16:56 -07:00
test_internal_user_endpoints.py fix(proxy)!: match the sign-in email fallback to the right user (#51897) 2026-11-15 19:13:38 -08:00
test_jwt_key_mapping.py
test_key_budget_change.py feat(proxy): customer budget rollup, reset on the budget row's window, named templates, team overrides, multi-window limits and pause_allow_increase (#51582) 2026-11-13 16:05:35 +00:00
test_key_generate_prisma.py test: remove dead skip-marked tests and rewrite the Redis buffer drain test (#52063) 2026-11-16 10:50:52 -08:00
test_key_management_endpoints.py feat(control_plane): dataplane registry, credential strategies and client (#49655) 2026-11-16 17:36:23 +00:00
test_management_route_coverage.py test: migrate tests/proxy_behavior into integration and unit tiers (#45939) 2026-10-11 08:28:42 -07:00
test_mcp_connector_import.py
test_mcp_management_endpoints.py refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) 2026-10-27 17:47:50 +00:00
test_mcp_servers.py refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) 2026-10-27 17:47:50 +00:00
test_model_deprecation_alerts.py feat(proxy): add model deprecation alerts with daily requests by key (#50022) 2026-11-05 04:03:42 +00:00
test_model_insights_endpoints.py feat(alerts): detect daily changes in recorded usage (#50666) 2026-11-11 18:23:02 -08:00
test_model_management_endpoints.py fix(proxy): preserve explicit model prices when metadata echoes null (#48746) 2026-11-16 08:33:45 -08:00
test_org_admin_team_access.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_organization_endpoints.py feat(budgets): add per-model tpm and rpm limit maps to budgets and customers (#50797) 2026-11-09 22:15:18 -08:00
test_password_endpoints.py feat(proxy): hash UI passwords with PBKDF2 in FIPS mode (#49874) 2026-11-06 01:31:59 -08:00
test_policy_endpoints.py fix(guardrails): log requests that a guardrail blocks on /apply_guardrail (#51014) 2026-11-16 15:18:08 -08:00
test_project_org_authz.py
test_prompt_cache_prediction.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_prompt_caching_requests.py fix(proxy): cancel the Admin UI's raw spend-log reads in Postgres after 30s (#49965) 2026-11-03 16:07:00 -08:00
test_ptu_consumption.py fix(router): serve a team's wildcard deployment before a proxy-wide wildcard (#48490) 2026-10-26 17:06:09 -07:00
test_ptu_model_settings.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
test_request_error_endpoints.py feat(proxy): track failed requests by HTTP status and caller (#45244) 2026-10-09 14:27:56 -07:00
test_roi_calculator_endpoints.py
test_router_settings_endpoints.py
test_saml_sso.py refactor(mcp): drop the experimental label from the MCP server and client paths (#48513) 2026-10-27 17:47:50 +00:00
test_session_endpoints.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_sso_helper_utils.py refactor(rust_bridge): route every Rust-to-Python call through host modules (#50822) 2026-11-11 01:57:54 +00:00
test_subscription_accounts.py feat(usage): show subscription-covered providers and account fees separately (#44772) 2026-10-30 03:58:36 -07:00
test_tag_management_endpoints.py feat(control_plane): dataplane registry, credential strategies and client (#49655) 2026-11-16 17:36:23 +00:00
test_team_admin_field_permissions.py feat(dynamic_rate_limiter): customer organizations and keys borrow idle model capacity and split class shares (#51705) 2026-11-15 12:05:58 -08:00
test_team_callback_endpoints.py feat(otel): let a team or key excluded_services override the global setting for its OTel v2 destination (#45880) 2026-10-12 19:25:52 -04:00
test_team_default_params.py feat(team): let default_team_params attach access_group_ids to every new team (#49908) 2026-11-05 19:58:51 -08:00
test_team_endpoints.py fix(proxy): reset members given default team member models on the team's budget window (#51960) 2026-11-15 16:00:44 -08:00
test_team_model_alias_merge.py refactor(proxy): expose public names for private proxy helpers (#45170) 2026-10-07 18:59:27 -07:00
test_tool_management_endpoints.py
test_ui_sso.py fix(proxy)!: match the sign-in email fallback to the right user (#51897) 2026-11-15 19:13:38 -08:00
test_user_agent_analytics_endpoints.py refactor(typing): clear about 1,100 basedpyright Any errors across 303 files (#49986) 2026-11-06 13:31:15 -08:00
test_workflow_management_endpoints.py feat(control_plane): dataplane registry, credential strategies and client (#49655) 2026-11-16 17:36:23 +00:00