Skip to content

Fix/new org team validate against org - #17333

Merged
3 commits merged into
BerriAI:mainfrom
TKH-AI:fix/new_org_team_validate_against_org
Dec 2, 2025
Merged

Fix/new org team validate against org#17333
3 commits merged into
BerriAI:mainfrom
TKH-AI:fix/new_org_team_validate_against_org

Conversation

@rioiart

@rioiart rioiart commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Title

[new users are now automatically added to the associated SSO-synced teams](fix: org admin cannot create a Team due to budget and model checks against personal budget/models instead of org budget/models)

Relevant issues

fixes #17059

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix
🧹 Refactoring
✅ Test

Changes

litellm/proxy/management_endpoints/team_endpoints.py
tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py

This PR fixes validation logic for team budget and rate limits, ensuring proper enforcement based on team scope:

Key Changes:

  • Org-scoped teams (teams with organization_id) now validate TPM/RPM limits against the organization's limits instead of the creating user's personal limits
  • Standalone teams (teams without organization_id) continue to validate budget, models, TPM, and RPM against the user's limits
  • Added direct TPM/RPM comparison against organization limits in _check_org_team_limits()
  • Consolidated user limit validation into new _check_user_team_limits() helper function, reducing code duplication between new_team() and update_team()

Bug Fixed:

Previously, when creating/updating an org-scoped team, the user's personal TPM/RPM limits were incorrectly applied even though the team belongs to an organization with its own limits. This prevented org admins from creating teams with limits higher than their personal limits but within org limits.

Test Coverage:

Added 8 new tests covering:

  • Standalone team TPM/RPM validation against user limits
  • Org-scoped team TPM/RPM validation against org limits
  • Verification that org-scoped teams bypass user's personal limits when within org limits

Unit test results

Note: the warning were there before

$ poetry run pytest tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py
======================================================================================================================== test session starts =========================================================================================================================
platform linux -- Python 3.13.9, pytest-7.4.4, pluggy-1.6.0
rootdir: /home/rioiart/workspace/litellm
configfile: pyproject.toml
plugins: asyncio-0.21.2, xdist-3.8.0, mock-3.15.1, retry-1.6.3, requests-mock-1.12.1, anyio-4.11.0, respx-0.22.0
asyncio: mode=Mode.AUTO
collected 56 items                                                                                                                                                                                                                                                   

tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py ........................................................                                                                                                                                  [100%]

========================================================================================================================== warnings summary ==========================================================================================================================
litellm/types/llms/anthropic.py:531
  /home/rioiart/workspace/litellm/litellm/types/llms/anthropic.py:531: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.12/migration/
    class AnthropicResponseContentBlockToolUse(BaseModel):

litellm/types/rag.py:181
  /home/rioiart/workspace/litellm/litellm/types/rag.py:181: PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.12/migration/
    class RAGIngestRequest(BaseModel):

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================================================================================== 56 passed, 2 warnings in 2.87s ===================================================================================================================

When creating a team with organization_id, budget and model constraints
should be validated against the organization's limits, not the user's
personal limits. This allows org admins with restrictive personal
budgets to create teams within their organization's more generous limits.

Adds 4 unit tests to verify:
- Org-scoped teams bypass user budget validation
- Org-scoped teams bypass user model validation
- Standalone teams still validate against user limits
…team

- Add user-level budget and model validation to update_team endpoint for standalone teams,
  matching the existing pattern in new_team
- Org-scoped teams correctly bypass user validation and use organization limits instead
- Add 5 new comprehensive tests covering standalone/org team budget/model validation
…m limit checks

- Add direct TPM/RPM comparison against org limits in _check_org_team_limits()
- Consolidate budget/models/TPM/RPM user validation into _check_user_team_limits() helper
- Ensure user limits only apply to standalone teams (organization_id=None)
- Org-scoped teams now validate TPM/RPM against org limits (not user limits)
- Add 8 tests for TPM/RPM validation scenarios (org and user limits)
- Reduce code duplication between new_team() and update_team()
@vercel

vercel Bot commented Dec 1, 2025

Copy link
Copy Markdown

@rioiart is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

@ghost
ghost merged commit 70126d9 into BerriAI:main Dec 2, 2025
3 of 6 checks passed
@rioiart
rioiart deleted the fix/new_org_team_validate_against_org branch December 12, 2025 14:59
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
* fix: skip user budget/model validation for org-scoped teams

When creating a team with organization_id, budget and model constraints
should be validated against the organization's limits, not the user's
personal limits. This allows org admins with restrictive personal
budgets to create teams within their organization's more generous limits.

Adds 4 unit tests to verify:
- Org-scoped teams bypass user budget validation
- Org-scoped teams bypass user model validation
- Standalone teams still validate against user limits

* fix: enforce user budget/model limits for standalone teams in update_team

- Add user-level budget and model validation to update_team endpoint for standalone teams,
  matching the existing pattern in new_team
- Org-scoped teams correctly bypass user validation and use organization limits instead
- Add 5 new comprehensive tests covering standalone/org team budget/model validation

* fix: Add direct TPM/RPM org limit validation and consolidate user team limit checks

- Add direct TPM/RPM comparison against org limits in _check_org_team_limits()
- Consolidate budget/models/TPM/RPM user validation into _check_user_team_limits() helper
- Ensure user limits only apply to standalone teams (organization_id=None)
- Org-scoped teams now validate TPM/RPM against org limits (not user limits)
- Add 8 tests for TPM/RPM validation scenarios (org and user limits)
- Reduce code duplication between new_team() and update_team()
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: org admin cannot create a Team due to budget and model checks against personal budget/models instead of org budget/models

1 participant