Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

block input_examples in fucntion definition for non anthropic providers

Sameer Kankutecf6dda5e2907
diff --git a/litellm/main.py b/litellm/main.py
index 3e51785ac63..a02e465448b 100644
--- a/litellm/main.py
+++ b/litellm/main.py
@@ -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(
diff --git a/tests/test_litellm/test_main.py b/tests/test_litellm/test_main.py
index ade512d6f65..71ede0958f5 100644
--- a/tests/test_litellm/test_main.py
+++ b/tests/test_litellm/test_main.py
@@ -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