Skip to content

[BUG] LLM Returns Empty Response When Input Is Too Long #3454

@phuihock

Description

@phuihock

Description

When using Qwen/Qwen3-235B-A22B-Instruct-2507 by DeepInfra , I hit this error:

"Invalid response from LLM call - None or empty."

The root cause is that LLMs hosted on DeepInfra respond with an empty message when the input messages exceed the model’s context window.

Agent executor doesn’t proactively check message length before calling the model—it only handles it after an exception is thrown

except Exception as e:
if e.__class__.__module__.startswith("litellm"):
# Do not retry on litellm errors
raise e
if is_context_length_exceeded(e):
handle_context_length(
respect_context_window=self.respect_context_window,

This is problematic because different providers handle overflows differently—some return structured errors, others fail silently.

Related to #2990

Steps to Reproduce

  1. Create an agent with llm=Qwen/Qwen3-235B-A22B-Instruct-2507 by DeepInfra
  2. Give it a very long input of >40K characters
  3. Kickoff the crew

Expected behavior

It should summarize the messages prior to calling the LLM

Screenshots/Code snippets

None

Operating System

Ubuntu 20.04

Python Version

3.10

crewAI Version

0.177.0

crewAI Tools Version

0.69.0

Virtual Environment

Venv

Evidence

  File "/home/phuihock/github/fxml/.venv/lib/python3.11/site-packages/crewai/agents/crew_agent_executor.py", line 153, in _invoke_loop
    answer = get_llm_response(
             ^^^^^^^^^^^^^^^^^
  File "/home/phuihock/github/fxml/.venv/lib/python3.11/site-packages/crewai/utilities/agent_utils.py", line 167, in get_llm_response
    raise ValueError("Invalid response from LLM call - None or empty.")

Possible Solution

I suggest handling message length earlier in the flow (call handle_context_length right before get_llm_response

enforce_rpm_limit(self.request_within_rpm_limit)
answer = get_llm_response(
llm=self.llm,
messages=self.messages,
callbacks=self.callbacks,
printer=self._printer,
from_task=self.task,
)

Additional context

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions