pythonwarningslangchain

Importing GuardrailsOutputParser from langchain.output_parsers is deprecated


I'm using langchain 0.1.17. I get this warning:

\venv\Lib\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(

even though my code doesn't import this package at all.

A code to trigger this warning:

from langchain.agents import create_openai_tools_agent

What gives?


Solution

  • It is an issue that appeared in langchain 0.1.17 when the developers left an import in the codebase which resulted in a spurious warning. This was fixed in this commit which is reflected in langchain 0.1.19.

    So pip install langchain==0.1.19 -U should fix the issue.

    If you can't upgrade yet, downgrading to langchain<=0.1.16 also fixes the issue.


    With that being said, if you actually have code that imports an output parser class from langchain.output_parsers, consider changing your code to make it import from langchain_community.output_parsers since the library is being restructured to make it so that langchain module itself would only contain functionalities related to building agents and chains and all other stuff such as document handling, prompting, output parsing etc. are being moved to different packages such as langchain_core, langchain_community etc.