BerriAI/litellm · error · LangFlowError
Could not extract a message from the LangFlow response…
Error message
Could not extract a message from the LangFlow response; ensure the flow ends in a Chat Output component
What it means
After a successful JSON parse, _extract_content_from_response walks outputs[0].outputs[0].results.message.text (with a fallback over outputs values). If no message text is found it returns None and transform_response raises LangFlowError(500). It means the flow executed but its result shape contains no Chat Output message, so litellm refuses to return a raw JSON blob as the assistant answer.
Solutions
- Open the flow in LangFlow and make the final component a Chat Output component
- Run the same input in the LangFlow UI playground and confirm the response JSON contains outputs[0].outputs[0].results.message.text
- Match output_type to the flow (chat vs text) via the optional param if the flow was built for text
- Check the LangFlow server logs for an in-flow error that produced empty outputs
Example fix
# before: flow ends in Text output -> no message.text -> LangFlowError 500
# fix in LangFlow UI: delete Text Output, add Chat Output, reconnect, save, then:
resp = litellm.completion(
model="langflow/my-flow",
messages=[{"role": "user", "content": "hi"}],
)
print(resp.choices[0].message.content) Defensive patterns
Strategy: try-catch
Validate before calling
import httpx
# smoke-test the flow's output shape before wiring it into litellm
def langflow_flow_emits_chat_output(base: str, flow_id: str, api_key: str | None) -> bool:
r = httpx.post(
f"{base.rstrip('/')}/api/v1/run/{flow_id}",
headers={"x-api-key": api_key} if api_key else {},
json={"input_value": "ping", "input_type": "chat", "output_type": "chat"},
timeout=30,
)
body = r.json()
try:
return bool(body["outputs"][0]["outputs"][0]["results"]["message"]["text"])
except (KeyError, IndexError, TypeError):
return False Try / catch
from litellm.llms.langflow.chat.transformation import LangFlowError
try:
resp = litellm.completion(model="langflow/<flow_id>", messages=msgs, api_base=base)
except LangFlowError as e:
if "Could not extract a message" in e.message:
raise FlowConfigError("Flow must end in a Chat Output component") from e
raise Prevention
- Verify every flow ends in a Chat Output component before registering it with a langflow/ model name
- Add an integration test that runs one prompt per flow and asserts non-empty choices[0].message.content
- Pin the LangFlow version so response schemas do not drift under you
When it happens
Trigger: The LangFlow flow's final component is a Text or Data output instead of Chat Output; the flow errored internally and returned outputs without message text; output_type in the payload (default 'chat') does not match how the flow was built; a LangFlow version whose run response schema differs.
Common situations: Exporting a flow template built around text components; renaming/replacing the output component after wiring; flow works in the LangFlow UI playground but its endpoint output shape changed after edits.
Related errors
- AgentCore: Failed to read/parse JSON response body
- api_base is required for LangFlow. Set it via…
- Cisco AI Defense API returned a non-JSON response
- error - , Received response - , Type of response
- Error in response object format
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/8c5c5b421ffdc6c4.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/langflow/chat/transformation.py:242
optional_params: dict,
litellm_params: dict,
encoding: Any,
api_key: str | None = None,
json_mode: bool | None = None,
) -> ModelResponse:
try:
response_json: Final = raw_response.json()
except Exception as e:
raise LangFlowError(
message=f"LangFlow returned a non-JSON response: {e}",
status_code=raw_response.status_code,
)
verbose_logger.debug("LangFlow response: %s", response_json)
content: Final = self._extract_content_from_response(response_json)
if content is None:
raise LangFlowError(
message=(
"Could not extract a message from the LangFlow response; "
"ensure the flow ends in a Chat Output component"
),
status_code=500,
)
message: Final = Message(content=content, role="assistant")
choice: Final = Choices(finish_reason="stop", index=0, message=message)
model_response.choices = [choice]
model_response.model = model
try:
from litellm.utils import token_counter
prompt_tokens: Final = token_counter(model=model, messages=messages)
completion_tokens: Final = token_counter(model=model, text=content, count_response_tokens=True)View on GitHub (pinned to 77b7c6c40c)