[X] I added a very descriptive title to this issue.
[X] I searched the LangChain documentation with the integrated search.
[X] I used the GitHub search to find a similar question and didn't find it.
[X] I am sure that this is a bug in LangChain rather than my code.
[X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
from typing import TypedDict
from langchain_core.runnables import RunnableParallel, RunnableLambda
class Foo(TypedDict):
foo: str
class InputData(Foo):
bar: str
def forward_foo(input_data: InputData):
return input_data["foo"]
def transform_input(input_data: InputData):
foo = input_data["foo"]
bar = input_data["bar"]
return {
"transformed": foo + bar
}
foo_runnable = RunnableLambda(forward_foo)
other_runnable = RunnableLambda(transform_input)
parallel = RunnableParallel(
foo=foo_runnable,
other=other_runnable,
)
repr(parallel.input_schema.validate({ "foo": "Y", "bar": "Z" }))
# 'RunnableParallel<foo,other>Input()'
# If we remove the type annotations on forward_foo and transform_input
# args, validate() gives us the right result:
# "RunnableParallel<foo,other>Input(foo='Y', bar='Z')"
Error Message and Stack Trace (if applicable)
No response
Description
When using TypedDict subclasses to annotate the arguments of a RunnableParallel children, the RunnableParallel schema isn't correctly inferred from the children's schemas.
The RunnableParallel schema is empty, i.e. parallel.input_schema.schema() outputs:
and parallel.input_schema.validate() returns an empty dict for any input.
This is problematic when exposing the RunnableParallel chain using Langserve, because Langserve passes the endpoint input through schema.validate(), which essentially clears any input as it returns an empty dict
The only workarounds we have found so far are either:
remove type annotations on the RunnableParallel children functions
pipe a RunnablePassthrough before the RunnableParallel : parallel = RunnablePassthrough() | RunnableParallel()
System Info
System Information
OS: Darwin
OS Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
Python Version: 3.10.13 (main, Aug 24 2023, 12:59:26) [Clang 15.0.0 (clang-1500.1.0.2.5)]
Checked other resources
Example Code
Error Message and Stack Trace (if applicable)
No response
Description
When using
TypedDict
subclasses to annotate the arguments of aRunnableParallel
children, theRunnableParallel
schema isn't correctly inferred from the children's schemas.The
RunnableParallel
schema is empty, i.e.parallel.input_schema.schema()
outputs:and
parallel.input_schema.validate()
returns an empty dict for any input.This is problematic when exposing the
RunnableParallel
chain using Langserve, because Langserve passes the endpoint input throughschema.validate()
, which essentially clears any input as it returns an emptydict
The only workarounds we have found so far are either:
RunnableParallel
children functionsRunnablePassthrough
before theRunnableParallel
:parallel = RunnablePassthrough() | RunnableParallel()
System Info
System Information
Package Information
Packages not installed (Not Necessarily a Problem)
The following packages were not found: