From bb7d787425ee35c9530296c8aee10e2a30e08d7d Mon Sep 17 00:00:00 2001 From: yujonglee Date: Thu, 3 Sep 2026 10:35:01 -0700 Subject: [PATCH] Merge pull request #39571 from BerriAI/codex/team-id-empty-field fix(team): generate team IDs for blank input --- litellm/proxy/_types.py | 7 +++++++ .../proxy/management_endpoints/test_team_endpoints.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index c6ecb0be8b9..97f5f59d2dc 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -1930,6 +1930,13 @@ class NewTeamRequest(TeamBase): model_config = ConfigDict(protected_namespaces=()) + @field_validator("team_id", mode="before") + @classmethod + def treat_blank_team_id_as_unset(cls, v: object) -> object: + if isinstance(v, str) and not v.strip(): + return None + return v + class GlobalEndUsersSpend(LiteLLMPydanticObjectBase): api_key: str | None = None diff --git a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py index 30b2ab86b9a..088e82b370f 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_team_endpoints.py @@ -11083,6 +11083,14 @@ async def test_new_team_rejects_reserved_ui_session_team_id(): mock_prisma.get_data.assert_not_called() +@pytest.mark.parametrize("team_id", ["", " "]) +def test_new_team_request_blank_team_id_is_unset(team_id: str) -> None: + from litellm.proxy._types import NewTeamRequest + + assert NewTeamRequest(team_alias="t", team_id=team_id).team_id is None + assert NewTeamRequest(team_id="custom").team_id == "custom" + + # --------------------------------------------------------------------------- # PATCH /team/{team_id} — RFC 7386 JSON Merge Patch #