address review: NotRequired[Optional[str]] for AgenticLoopParams + narrow test exception

- types/utils.py: api_key/api_base now typed as NotRequired[Optional[str]] to match docstring intent and the 'only set when not None' handler logic.
- test handler: replace broad try/except (ValueError, TypeError, AttributeError) with explicit pytest.raises(Exception) so a future refactor that raises before agentic_loop_params is set will fail loudly instead of vacuously.
This commit is contained in:
skgandikota 2026-04-27 23:01:39 +01:00 committed by skgandikota
parent a8e76594d0
commit 049df78c11
No known key found for this signature in database
GPG key ID: 9C8C0949390E528F
2 changed files with 5 additions and 9 deletions

View file

@ -40,7 +40,7 @@ from pydantic import (
field_validator,
model_validator,
)
from typing_extensions import Required, TypedDict
from typing_extensions import NotRequired, Required, TypedDict
from litellm._uuid import uuid
from litellm.types.llms.base import (
@ -164,7 +164,7 @@ class AgenticLoopParams(TypedDict, total=False):
custom_llm_provider: str
"""The LLM provider name (e.g., 'bedrock', 'anthropic')"""
api_key: str
api_key: NotRequired[Optional[str]]
"""Deployment-specific API key resolved by get_llm_provider() (optional).
Stored so agentic follow-up calls (e.g. websearch interception) reuse the
@ -172,7 +172,7 @@ class AgenticLoopParams(TypedDict, total=False):
provider env vars.
"""
api_base: str
api_base: NotRequired[Optional[str]]
"""Deployment-specific API base URL resolved by get_llm_provider() (optional)."""

View file

@ -530,7 +530,7 @@ def test_agentic_loop_params_preserves_dynamic_api_key_and_api_base():
),
patch("litellm.completion", return_value="test-response"),
):
try:
with pytest.raises(Exception):
anthropic_messages_handler(
max_tokens=100,
messages=[{"role": "user", "content": "hi"}],
@ -540,8 +540,6 @@ def test_agentic_loop_params_preserves_dynamic_api_key_and_api_base():
api_base="https://my-proxy.example.com/v1",
litellm_logging_obj=logging_obj,
)
except (ValueError, TypeError, AttributeError):
pass
agentic_loop_params = logging_obj.model_call_details.get("agentic_loop_params")
assert agentic_loop_params is not None
@ -572,7 +570,7 @@ def test_agentic_loop_params_omits_keys_when_dynamic_values_are_none():
),
patch("litellm.completion", return_value="test-response"),
):
try:
with pytest.raises(Exception):
anthropic_messages_handler(
max_tokens=100,
messages=[{"role": "user", "content": "hi"}],
@ -580,8 +578,6 @@ def test_agentic_loop_params_omits_keys_when_dynamic_values_are_none():
custom_llm_provider="anthropic",
litellm_logging_obj=logging_obj,
)
except (ValueError, TypeError, AttributeError):
pass
agentic_loop_params = logging_obj.model_call_details.get("agentic_loop_params")
assert agentic_loop_params is not None