LangChain Expression Language crashes on pydantic v2 inputs
Hooked a simple chain into LEL:
from langchain_experimental.expression_language import chain
from pydantic import BaseModel
class Input(BaseModel):
q: str
result = chain("{q}").run(Input(q="hi"))
Traceback:
AttributeError: 'str' object has no attribute 'model_dump'
Python 3.12.1, langchain 0.3.0, expression-language 0.0.5, pydantic 2.8.2. Same code worked with pydantic 1.10.
Cause: LEL still calls model_dump() on BaseModel v1. In v2 the method is model_dump() but returns dict by default only if config set, otherwise raises.
Fix options:
- pin pydantic:
pip install 'pydantic<2' - or add
model_config = {"ser_json_tuples":True}to the class and access.model_dump()explicitly - PR #42 merged but not released; install nightly:
pip install git+https://github.com/langchain-ai/langchain@master#subdirectory=libs/expression_language
Went with the nightly; crash resolved.
If import still fails ensure langchain_experimental updated; older wheels pull expression‑language 0.0.4 which lacks the patch.
