Skip to content

Commit 5c61444

Browse files
fix(llm): handle LiteLLM supports_response_schema introspection failure gracefully (#6412)
1 parent ce739e2 commit 5c61444

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

lib/crewai/src/crewai/llm.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2384,16 +2384,25 @@ def _validate_call_params(self) -> None:
23842384
Note: This validation only applies to the litellm fallback path.
23852385
Native providers have their own validation.
23862386
"""
2387+
if self.response_format is None:
2388+
return
2389+
23872390
if not _ensure_litellm() or supports_response_schema is None:
23882391
# When litellm is not available, skip validation
23892392
# (this path should only be reached for litellm fallback models)
23902393
return
23912394

23922395
provider = self._get_custom_llm_provider()
2393-
if self.response_format is not None and not supports_response_schema(
2394-
model=self.model,
2395-
custom_llm_provider=provider,
2396-
):
2396+
try:
2397+
is_supported = supports_response_schema(
2398+
model=self.model,
2399+
custom_llm_provider=provider,
2400+
)
2401+
except Exception as e:
2402+
logger.debug(f"LiteLLM supports_response_schema check failed: {e!s}")
2403+
is_supported = True
2404+
2405+
if not is_supported:
23972406
raise ValueError(
23982407
f"The model {self.model} does not support response_format for provider '{provider}'. "
23992408
"Please remove response_format or use a supported model."

lib/crewai/tests/test_llm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,3 +1177,13 @@ async def _ret(*args, **kwargs):
11771177
assert isinstance(result, list)
11781178
assert len(result) == 1
11791179
assert result[0].function.name == "search"
1180+
1181+
1182+
def test_validate_call_params_handles_introspection_error():
1183+
"""Verify that _validate_call_params gracefully handles LiteLLM introspection errors without crashing."""
1184+
llm = LLM(model="custom/unsupported-model", is_litellm=True, response_format={"type": "json_object"})
1185+
1186+
with patch("crewai.llm.supports_response_schema", side_effect=Exception("Introspection error")):
1187+
# Should not raise exception
1188+
llm._validate_call_params()
1189+

0 commit comments

Comments
 (0)