langchain - ✅(Solved) Fix Chain.save() broken in 0.3.28: model_dump() doesn't inject _type [3 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#35665Fetched 2026-04-08 00:25:15
View on GitHub
Comments
1
Participants
2
Timeline
8
Reactions
0
Author
Assignees
Timeline (top)
labeled ×3cross-referenced ×2assigned ×1commented ×1
  • #33035 changed Chain.save() from self.dict() to self.model_dump().
  • dict() injects _type via _chain_type; model_dump() inherits from Pydantic BaseModel and never includes it.
  • save() now always hits "_type" not in chain_dict and raises NotImplementedError.
  • This is a regression from 0.3.27 -> 0.3.28.

Error Message

Traceback (most recent call last): File "<string>", line 9, in <module> File "langchain/chains/base.py", line 785, in save raise NotImplementedError(msg) NotImplementedError: Chain verbose=False prompt=PromptTemplate(input_variables=['input'], input_types={}, partial_variables={}, template='{input}') llm=FakeListLLM(responses=['hello']) output_parser=StrOutputParser() llm_kwargs={} does not support saving.

Root Cause

  • #33035 changed Chain.save() from self.dict() to self.model_dump().
  • dict() injects _type via _chain_type; model_dump() inherits from Pydantic BaseModel and never includes it.
  • save() now always hits "_type" not in chain_dict and raises NotImplementedError.
  • This is a regression from 0.3.27 -> 0.3.28.

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • 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).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

PR fix notes

PR #21474: Exclude langchain 0.3.28 from cross-version tests

Description (problem / solution / changelog)

langchain 0.3.28 broke Chain.save() by switching from self.dict() to self.model_dump() (upstream PR #33035), causing save() to always raise NotImplementedError since model_dump() doesn't inject the _type field. Tracked upstream at langchain-ai/langchain#35665.

  • Adds unsupported: ["== 0.3.28"] to the langchain models section in ml-package-versions.yml

Related Issues/PRs

Relates to https://github.com/langchain-ai/langchain/issues/35665

What changes are proposed in this pull request?

Add unsupported: ["== 0.3.28"] to the models section of the langchain entry in mlflow/ml-package-versions.yml to skip cross-version testing against the broken release.

How is this PR tested?

  • Existing unit/integration tests
  • New unit/integration tests
  • Manual tests

Does this PR require documentation update?

  • No. You can skip the rest of this section.

Does this PR require updating the MLflow Skills repository?

  • No. You can skip the rest of this section.

Release Notes

Is this a user-facing change?

  • No. You can skip the rest of this section.

What component(s), interfaces, languages, and integrations does this PR affect?

Components

  • area/build: Build and test infrastructure for MLflow

<a name="release-note-category"></a>

How should the PR be classified in the release notes? Choose one:

  • rn/none - No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" section

Should this PR be included in the next patch release?

  • Yes (this PR will be cherry-picked and included in the next patch release)
  • No (this PR will be included in the next minor release)
<!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary>

Handle langchain 0.3.28 Chain.save() regression

Created by Claude Code for handoff.

Patch release: No

Summary

langchain 0.3.28 (released March 6, 2026) broke Chain.save() by changing self.dict() to self.model_dump() in PR #33035. The dict() method injected _type via _chain_type; model_dump() (inherited from Pydantic BaseModel) does not, so save() always raises NotImplementedError.

Implementation Guide

Exclude 0.3.28 from cross-version tests

  • mlflow/ml-package-versions.yml:606-609 - Add unsupported: ["== 0.3.28"] to the models section of the langchain entry, with a comment linking to the upstream issue.

Success Criteria

  • langchain 0.3.28 excluded from cross-version tests via unsupported in ml-package-versions.yml
</details> <!-- START COPILOT CODING AGENT TIPS -->

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Changed files

  • mlflow/ml-package-versions.yml (modified, +4/-0)

PR #35667: fix(langchain-classic): fix Chain.save() regression from dict-to-model_dump migration

Description (problem / solution / changelog)

Fixes a regression introduced in #33035 where Chain.save() stopped working for all chain types (including LLMChain). The root cause is that #33035 updated save() to call self.model_dump() but forgot to rename the dict() method override to model_dump(). So the _type key was never being injected into the serialized output, and save() would always hit the "does not support saving" error path. Renamed the override from dict to model_dump to fix it. Pydantic v2's dict() already delegates to model_dump() under the hood, so nothing breaks.

Fixes: #35665

Changed files

  • libs/langchain/langchain_classic/chains/base.py (modified, +3/-3)
  • libs/langchain/tests/unit_tests/chains/test_base.py (modified, +57/-0)

Code Example

from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
from langchain_community.llms.fake import FakeListLLM

llm = FakeListLLM(responses=["hello"])
prompt = PromptTemplate(input_variables=["input"], template="{input}")
chain = LLMChain(llm=llm, prompt=prompt)
chain.save("/tmp/test_chain.yaml")  # Works on 0.3.27, fails on 0.3.28

---

Traceback (most recent call last):
  File "<string>", line 9, in <module>
  File "langchain/chains/base.py", line 785, in save
    raise NotImplementedError(msg)
NotImplementedError: Chain verbose=False prompt=PromptTemplate(input_variables=['input'], input_types={}, partial_variables={}, template='{input}') llm=FakeListLLM(responses=['hello']) output_parser=StrOutputParser() llm_kwargs={} does not support saving.

---

> langchain_core: 0.3.83
> langchain: 0.3.28
> langchain_community: 0.3.31
> Python Version: 3.10.17
> OS: Darwin
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • 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).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain

Related Issues / PRs

#33035

Reproduction Steps / Example Code (Python)

from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
from langchain_community.llms.fake import FakeListLLM

llm = FakeListLLM(responses=["hello"])
prompt = PromptTemplate(input_variables=["input"], template="{input}")
chain = LLMChain(llm=llm, prompt=prompt)
chain.save("/tmp/test_chain.yaml")  # Works on 0.3.27, fails on 0.3.28

Error Message and Stack Trace

Traceback (most recent call last):
  File "<string>", line 9, in <module>
  File "langchain/chains/base.py", line 785, in save
    raise NotImplementedError(msg)
NotImplementedError: Chain verbose=False prompt=PromptTemplate(input_variables=['input'], input_types={}, partial_variables={}, template='{input}') llm=FakeListLLM(responses=['hello']) output_parser=StrOutputParser() llm_kwargs={} does not support saving.

Description

  • #33035 changed Chain.save() from self.dict() to self.model_dump().
  • dict() injects _type via _chain_type; model_dump() inherits from Pydantic BaseModel and never includes it.
  • save() now always hits "_type" not in chain_dict and raises NotImplementedError.
  • This is a regression from 0.3.27 -> 0.3.28.

System Info

> langchain_core: 0.3.83
> langchain: 0.3.28
> langchain_community: 0.3.31
> Python Version: 3.10.17
> OS: Darwin

extent analysis

Fix Plan

Update Chain.save() to use self.dict() instead of self.model_dump()

To fix this regression, you can update the save() method in your code to use self.dict() instead of self.model_dump(). This is because dict() injects the _type attribute, which is required for saving the chain.

from langchain.chains import LLMChain
from langchain_core.prompts import PromptTemplate
from langchain_community.llms.fake import FakeListLLM

llm = FakeListLLM(responses=["hello"])
prompt = PromptTemplate(input_variables=["input"], template="{input}")
chain = LLMChain(llm=llm, prompt=prompt)
chain_dict = chain.dict()  # Use dict() instead of model_dump()
chain_dict.save("/tmp/test_chain.yaml")  # This should work

Alternatively, you can also update the LLMChain class to use self.dict() by default, like this:

class LLMChain:
    # ...

    def save(self, path):
        chain_dict = self.dict()
        chain_dict.save(path)

Update langchain to the latest version

If you're using an older version of langchain, you can update it to the latest version, which should include the fix for this regression.

pip install --upgrade langchain

Verification

To verify that the fix worked, you can run the same code as before and check that the chain is saved successfully.

chain_dict = chain.dict()
chain_dict.save("/tmp/test_chain.yaml")
print("Chain saved successfully!")

If you see the "Chain saved successfully!" message, it means that the fix worked.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix Chain.save() broken in 0.3.28: model_dump() doesn't inject _type [3 pull requests, 1 comments, 2 participants]