Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RunnableAssign instantiation raises a pydantic validation error #26862

Closed
5 tasks done
B-Step62 opened this issue Sep 25, 2024 · 0 comments · Fixed by #26903
Closed
5 tasks done

RunnableAssign instantiation raises a pydantic validation error #26862

B-Step62 opened this issue Sep 25, 2024 · 0 comments · Fixed by #26903
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core investigate

Comments

@B-Step62
Copy link
Contributor

B-Step62 commented Sep 25, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

The official example from https://api.python.langchain.com/en/latest/runnables/langchain_core.runnables.passthrough.RunnableAssign.html

from typing import Dict
from langchain_core.runnables.passthrough import (
    RunnableAssign,
    RunnableParallel,
)
from langchain_core.runnables.base import RunnableLambda

def add_ten(x: Dict[str, int]) -> Dict[str, int]:
    return {"added": x["input"] + 10}

mapper = RunnableParallel(
    {"add_step": RunnableLambda(add_ten),}
)

runnable_assign = RunnableAssign(mapper)

Error Message and Stack Trace (if applicable)

ValidationError: 1 validation error for RunnableAssign
mapper
  Input should be a valid dictionary or instance of RunnableParallel[dict[str, Any]] [type=model_type, input_value={
  add_step: RunnableLambda(add_ten)
}, input_type=RunnableParallel]
    For further information visit https://errors.pydantic.dev/2.8/v/model_type
File <command-561754153254877>, line 15
      9     return {"added": x["input"] + 10}
     11 mapper = RunnableParallel(
     12     {"add_step": RunnableLambda(add_ten),}
     13 )
---> 15 runnable_assign = RunnableAssign(mapper)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-412fde62-9d54-4664-ab04-0a1aa6932e45/lib/python3.11/site-packages/langchain_core/runnables/passthrough.py:395, in RunnableAssign.__init__(self, mapper, **kwargs)
    394 def __init__(self, mapper: RunnableParallel[dict[str, Any]], **kwargs: Any) -> None:
--> 395     super().__init__(mapper=mapper, **kwargs)
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-412fde62-9d54-4664-ab04-0a1aa6932e45/lib/python3.11/site-packages/langchain_core/load/serializable.py:110, in Serializable.__init__(self, *args, **kwargs)
    108 def __init__(self, *args: Any, **kwargs: Any) -> None:
    109     """"""
--> 110     super().__init__(*args, **kwargs)
File /databricks/python/lib/python3.11/site-packages/pydantic/main.py:193, in BaseModel.__init__(self, **data)
    191 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    192 __tracebackhide__ = True
--> 193 self.__pydantic_validator__.validate_python(data, self_instance=self)

Description

With LangChain 0.3.x, RunnableAssign class cannot be instantiated due to a pydantic validation error. The official example in the class docstring does not work. The mapper argument seems to be correct type (RunnableParallel with dictionary).

System Info

System Information

OS: Linux
OS Version: #74~20.04.1-Ubuntu SMP Tue Aug 6 19:32:13 UTC 2024
Python Version: 3.11.0rc1 (main, Aug 12 2022, 10:02:14) [GCC 11.2.0]

Package Information

langchain_core: 0.3.5
langchain: 0.3.0
langsmith: 0.1.128
langchain_text_splitters: 0.3.0

Optional packages not installed

langgraph
langserve

Other Dependencies

aiohttp: 3.8.5
async-timeout: 4.0.2
httpx: 0.27.0
jsonpatch: 1.33
numpy: 1.24.3
orjson: 3.10.7
packaging: 23.2
pydantic: 2.8.2
PyYAML: 6.0
requests: 2.32.2
SQLAlchemy: 1.4.39
tenacity: 8.2.2
typing-extensions: 4.11.0

@langcarl langcarl bot added the investigate label Sep 25, 2024
@dosubot dosubot bot added Ɑ: core Related to langchain-core 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Sep 25, 2024
@ccurme ccurme closed this as completed in 9d10151 Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core investigate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant