langflow-ai / langflow

⛓️ Langflow is a visual framework for building multi-agent and RAG applications. It's open-source, Python-powered, fully customizable, model and vector store agnostic.

Home Page:http://www.langflow.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Update deprecated langchin output parser to maintained imports

msmygit opened this issue · comments

Describe the bug
Currently within the dev branch, we are leveraging deprecated output parsers package from langchain. We need to update to use the community and supported version.

Browser and Version
n/a

To Reproduce
Steps to reproduce the behavior:

  1. Install and just start langflow run to see the deprecation warnings as below,
% python -m langflow run --env-file ~/langflow/.env
/Users/madhavan/.pyenv/versions/langflow/lib/python3.10/site-packages/langchain/_api/module_import.py:87: LangChainDeprecationWarning: Importing GuardrailsOutputParser from langchain.output_parsers is deprecated. Please replace the import with the following:
from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser
  warnings.warn(
/Users/madhavan/.pyenv/versions/langflow/lib/python3.10/site-packages/langchain/_api/module_import.py:87: LangChainDeprecationWarning: Importing JsonSpec from langchain.tools.json is deprecated. Please replace the import with the following:
from langchain_community.tools.json.tool import JsonSpec
  warnings.warn(
Starting Langflow v1.0.0a29...
╭───────────────────────────────────────────────────╮
│ Welcome to ⛓ Langflow                             │
│                                                   │
│                                                   │
│ Collaborate, and contribute at our GitHub Repo 🚀 │
│                                                   │
│ Access http://127.0.0.1:7860                      │
╰───────────────────────────────────────────────────╯

Screenshots
n/a

Additional context
n/a

To address the deprecation warnings and update your project to use the langchain_community package, follow these steps:

  1. Change Import Paths: Update your import statements to use langchain_community instead of langchain. For instance, replace:
from langchain.output_parsers import GuardrailsOutputParser

with:

from langchain_community.output_parsers.rail_parser import GuardrailsOutputParser

And:

from langchain.tools.json import JsonSpec

with:

from langchain_community.tools.json.tool import JsonSpec
  1. Review Dynamic Imports: If your project dynamically imports modules, ensure the import strings reflect the new langchain_community package name.

  2. Handle Mixed Imports Carefully: If your project uses both langchain and langchain_community, update only the deprecated parts to langchain_community. Keep imports from langchain that don't have equivalents in the new package as they are.

  3. Test Your Application: After making these changes, thoroughly test your application to ensure all functionalities work as expected without introducing new issues.

By following these steps, you'll migrate away from deprecated langchain imports to the supported langchain_community package, aligning your project with the latest standards and avoiding deprecation warnings.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@dosu

I have the same issue but this warning appear when I import PydanticOutputParser

from langchain.output_parsers import PydanticOutputParser

when I'tried change it on GuardrailsOutputParser it was completly different class.

Do you have any idea how to fix it this warning?

@dosu I don't know why I did not import that package but still get the same warnning
image

I am getting the same issue, and nowhere in my code I import the GuardrailsOutputParser package. This must be something imported by some other langchain module.

I am getting the same issue, and nowhere in my code I import the GuardrailsOutputParser package. This must be something imported by some other langchain module.

I had to revert to this version to not get that warning
image

Tried changing to @dongtandung2001 versions did not work for me.

Tried @dosu (bot) suggestion to use from langchain_community.output_parsers instead of what I have below also did not work:

from langchain_community.llms import Ollama
from langchain.prompts import ChatPromptTemplate, PromptTemplate, HumanMessagePromptTemplate
from langchain_core.messages import SystemMessage
from langchain.output_parsers import ResponseSchema, StructuredOutputParser

Guessing its something to do with the StructuredOutputParser import, but have not had time to dig any further into it.

Hey all

This should be related to the some of the LangchainTypeCreators that are being fazed out soon.

pip install langchain==0.1.19 solved it for me. This Stack Overflow discussion has some info.