Skip to content

Handle non-list LangServe /invoke output in langchain_serve generator#1916

Open
WatchTree-19 wants to merge 1 commit into
NVIDIA:mainfrom
WatchTree-19:fix-1915-langserve-string-output
Open

Handle non-list LangServe /invoke output in langchain_serve generator#1916
WatchTree-19 wants to merge 1 commit into
NVIDIA:mainfrom
WatchTree-19:fix-1915-langserve-string-output

Conversation

@WatchTree-19

Copy link
Copy Markdown

Description

LangChainServeLLMGenerator._call_model did Message(response_data.get("output")[0]), assuming LangServe's /invoke wraps the output in a list. LangServe returns the runnable's output directly under output:

  • string / LLM chain: {"output": "the text", ...} -> output[0] returns only "t" (first character)
  • chat model: {"output": {"content": "...", "type": "ai"}} -> output[0] raises KeyError, caught, so the response is silently dropped ([None])

Only a {"output": ["..."]} shape worked, which LangServe doesn't emit; the existing test used that fabricated shape so the bug went unnoticed.

Now handles the output by type: a string directly, a dict via its content, a list via its first element (backward compatible), guarding empty/None.

Fixes #1915.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Verification

Added test_langchain_serve_string_output and test_langchain_serve_message_dict_output (real LangServe shapes); the existing list-shape test still passes. tests/generators/test_langchain_serve.py passes (7). ruff clean on the changed lines (the two == True/False warnings are pre-existing in test_validate_uri).

  • DCO sign-off included
  • Unit tests added

LangServe returns the runnable output directly under `output` (a string for
LLM chains, a serialised message dict for chat models), not wrapped in a list.
The generator indexed `output[0]`, so a string response was truncated to its
first character and a chat-model dict response was silently dropped ([None]).

Handle the output by type: string directly, dict via its content, list via its
first element (backward compatible). Add tests for the string and dict shapes.

Fixes NVIDIA#1915

Signed-off-by: WatchTree-19 <119982314+WatchTree-19@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

langchain_serve generator returns only the first character of a string LangServe response

1 participant