block input_examples in fucntion definition for non anthropic providers

This commit is contained in:
Sameer Kankute 2025-11-27 22:46:28 +05:30
parent c12305ac3c
commit cf6dda5e29
2 changed files with 62 additions and 0 deletions

View file

@ -938,6 +938,37 @@ def responses_api_bridge_check(
return model_info, model
def _should_allow_input_examples(custom_llm_provider: Optional[str], model: str) -> bool:
if custom_llm_provider == "anthropic":
return True
if custom_llm_provider == "azure_ai" or custom_llm_provider == "bedrock" or custom_llm_provider == "vertex_ai":
return "claude" in model.lower()
return False
def _drop_input_examples_from_tool(tool: dict) -> dict:
tool_copy = tool.copy()
tool_copy.pop("input_examples", None)
function = tool_copy.get("function")
if isinstance(function, dict):
function = function.copy()
function.pop("input_examples", None)
tool_copy["function"] = function
return tool_copy
def _drop_input_examples_from_tools(tools: Optional[List[dict]]) -> Optional[List[dict]]:
if tools is None:
return None
cleaned_tools: List[dict] = []
for tool in tools:
if isinstance(tool, dict):
cleaned_tools.append(_drop_input_examples_from_tool(tool))
else:
cleaned_tools.append(tool)
return cleaned_tools
@tracer.wrap()
@client
def completion( # type: ignore # noqa: PLR0915
@ -1183,6 +1214,11 @@ def completion( # type: ignore # noqa: PLR0915
api_key=api_key,
)
if not _should_allow_input_examples(
custom_llm_provider=custom_llm_provider, model=model
):
tools = _drop_input_examples_from_tools(tools=tools)
if provider_specific_header is not None:
headers.update(
ProviderSpecificHeaderUtils.get_provider_specific_headers(

View file

@ -16,6 +16,8 @@ from unittest.mock import MagicMock, patch
import litellm
from litellm import main as litellm_main
@pytest.fixture(autouse=True)
def add_api_keys_to_env(monkeypatch):
@ -293,6 +295,30 @@ def test_bedrock_latency_optimized_inference():
assert json_data["performanceConfig"]["latency"] == "optimized"
def test_strip_input_examples_for_non_anthropic_providers():
tools = [
{
"type": "function",
"name": "example_tool",
"input_examples": [{"foo": "bar"}],
"function": {
"name": "example_tool",
"input_examples": [{"foo": "bar"}],
},
}
]
assert not litellm_main._should_allow_input_examples(
custom_llm_provider="openai", model="gpt-4o-mini"
)
cleaned = litellm_main._drop_input_examples_from_tools(tools=tools)
assert isinstance(cleaned, list)
assert "input_examples" not in cleaned[0]
assert "input_examples" not in cleaned[0]["function"]
def test_custom_provider_with_extra_headers():
from litellm.llms.custom_httpx.http_handler import HTTPHandler