fix: filter internal _-prefixed flags for non-OpenAI providers too

The else branch (non-OpenAI/Azure providers) in
add_provider_specific_params_to_optional_params was not filtering
underscore-prefixed internal flags, only the if branch (OpenAI/Azure)
was. Added the same `not k.startswith("_")` guard and a test with
custom_llm_provider="anthropic" to cover this path.

Addresses greptile review concern about missing non-OpenAI provider
test coverage.
This commit is contained in:
Terrajlz 2026-05-22 13:56:24 -04:00
parent 59f3bb6b22
commit 287bea4240
2 changed files with 26 additions and 1 deletions

View file

@ -4869,7 +4869,11 @@ def add_provider_specific_params_to_optional_params(
)
else:
for k in passed_params.keys():
if k not in openai_params and passed_params[k] is not None:
if (
k not in openai_params
and passed_params[k] is not None
and not k.startswith("_")
):
if _should_drop_param(
k=k, additional_drop_params=additional_drop_params
):

View file

@ -103,6 +103,27 @@ class TestInternalFlagsNotInExtraBody:
assert "_websearch_interception_converted_stream" not in extra_body
assert extra_body.get("custom_param") == "value"
def test_non_openai_provider_flags_excluded(self):
"""Internal flags should also be filtered for non-OpenAI providers (else branch)."""
passed_params = {
"_websearch_interception_converted_stream": True,
"_other_internal": "skip",
"custom_param": "keep",
}
optional_params = {}
openai_params = ["model", "messages"]
result = add_provider_specific_params_to_optional_params(
optional_params=optional_params,
passed_params=passed_params,
custom_llm_provider="anthropic",
openai_params=openai_params,
)
assert "_websearch_interception_converted_stream" not in result
assert "_other_internal" not in result
assert result.get("custom_param") == "keep"
def test_no_extra_body_when_only_internal_flags(self):
"""If only internal flags exist (besides openai params), extra_body should be empty."""
passed_params = {