Input Not Automatically Recognized in Playground #76

Closed
opened 2026-02-16 00:18:39 -05:00 by yindo · 2 comments
Owner

Originally created by @TomDarmon on GitHub (Dec 26, 2023).

Originally assigned to: @eyurtsev on GitHub.

Problem Description

I am currently working with LangChain and Langserve and have encountered an issue with the input recognition in the Langserve playground. I've constructed a query chain as follows:

query_chain = (
{"question": RunnablePassthrough()}
| RunnablePassthrough.assign(table_name=get_available_table)
| RunnablePassthrough.assign(schema=get_table_schema)
| prompt_for_query
| model
| StrOutputParser()
)

However, when I attempt to use the playground feature of Langserve, the input "question" is not automatically recognized. This is illustrated in the screenshot below:

Langserve Playground Issue

The chain functions correctly outside of the playground and or when requesting the API. The issue seems to be specific to the playground environment, where I am unable to specify the input.

Suspected Cause

I suspect the issue arises because prompt_for_query is not positioned as the first Runnable in the chain.

I changed the order of the chain with the prompt as the first Runnable and the "questions" input is recognized :

query_chain = (
prompt_for_query
| {"question": RunnablePassthrough()}
| RunnablePassthrough.assign(table_name=get_available_table)
| RunnablePassthrough.assign(schema=get_table_schema)
| model
| StrOutputParser()
)

But the chain fails because the order of Runnables is not viable anymore.

Questions

  • Is this a normal behavior for the Langserve playground?
  • Can I solve my issue while maintaining the necessary order of Runnables?

Any insights or solutions to this problem would be greatly appreciated, thanks !

Originally created by @TomDarmon on GitHub (Dec 26, 2023). Originally assigned to: @eyurtsev on GitHub. ### Problem Description I am currently working with LangChain and Langserve and have encountered an issue with the input recognition in the Langserve playground. I've constructed a query chain as follows: ```python query_chain = ( {"question": RunnablePassthrough()} | RunnablePassthrough.assign(table_name=get_available_table) | RunnablePassthrough.assign(schema=get_table_schema) | prompt_for_query | model | StrOutputParser() ) ``` However, when I attempt to use the playground feature of Langserve, the input "question" is not automatically recognized. This is illustrated in the screenshot below: ![Langserve Playground Issue](https://github.com/langchain-ai/langserve/assets/36815861/06b7ffdf-fa45-4c78-80b4-2513bc76da68) The chain functions correctly outside of the playground and or when requesting the API. The issue seems to be specific to the playground environment, where I am unable to specify the input. ### Suspected Cause I suspect the issue arises because `prompt_for_query` is not positioned as the first Runnable in the chain. I changed the order of the chain with the prompt as the first Runnable and the "questions" input is recognized : ```python query_chain = ( prompt_for_query | {"question": RunnablePassthrough()} | RunnablePassthrough.assign(table_name=get_available_table) | RunnablePassthrough.assign(schema=get_table_schema) | model | StrOutputParser() ) ``` But the chain fails because the order of Runnables is not viable anymore. ### Questions - Is this a normal behavior for the Langserve playground? - Can I solve my issue while maintaining the necessary order of Runnables? Any insights or solutions to this problem would be greatly appreciated, thanks !
yindo closed this issue 2026-02-16 00:18:39 -05:00
Author
Owner

@TomDarmon commented on GitHub (Dec 27, 2023):

I have found a workaround as the input_type is not recognized, we can specify the input schema using a pydantic model using the with_types method of the chain.

There is the trick, the pydantic model needs to inherit from a custom model from langserve and not the default BaseModel, else it won't be recognized. The working code for my use case is as follow:

from langserve import CustomUserType
...
class Question(CustomUserType):
    question: str

query_chain = (
prompt_for_query
| {"question": RunnablePassthrough()}
| RunnablePassthrough.assign(table_name=get_available_table)
| RunnablePassthrough.assign(schema=get_table_schema)
| model
| StrOutputParser()
).with_types(input_type=Question)

Edit: I am not closing the issue on purpose, as this behavior is not optimal and documentation is hard to found :(

@TomDarmon commented on GitHub (Dec 27, 2023): I have found a workaround as the input_type is not recognized, we can specify the input schema using a pydantic model using the `with_types` method of the chain. There is the trick, the pydantic model needs to inherit from a custom model from langserve and not the default `BaseModel`, else it won't be recognized. The working code for my use case is as follow: ```python from langserve import CustomUserType ... class Question(CustomUserType): question: str query_chain = ( prompt_for_query | {"question": RunnablePassthrough()} | RunnablePassthrough.assign(table_name=get_available_table) | RunnablePassthrough.assign(schema=get_table_schema) | model | StrOutputParser() ).with_types(input_type=Question) ``` Edit: I am not closing the issue on purpose, as this behavior is not optimal and documentation is hard to found :(
Author
Owner

@eyurtsev commented on GitHub (Dec 28, 2023):

Thanks for reporting!

Our type inference isn't clever enough to determine what the type of the input should be if using RunnablePassthrough. So whenever you use RunnablePassthrough define an input type explicitly.

BaseModel should work fine. If you're able to include a minimally reproducible script that shows otherwise, I'll be able to investigate further, but I wasn't able to reproduce any issues with BaseModel.

@eyurtsev commented on GitHub (Dec 28, 2023): Thanks for reporting! Our type inference isn't clever enough to determine what the type of the input should be if using RunnablePassthrough. So whenever you use RunnablePassthrough define an input type explicitly. `BaseModel` should work fine. If you're able to include a minimally reproducible script that shows otherwise, I'll be able to investigate further, but I wasn't able to reproduce any issues with BaseModel.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langserve#76