Langchain-Classic: ImportError Messages For Moved REPL Tools Contain Dead Links And Missing Spaces
The ImportError messages raised when importing moved REPL tools/agents in langchain-classic contain outdated and dead links to SECURITY.md and a GitHub discussion, and have missing spaces causing link concatenation. This leads users to 404 pages or broken links, reducing safety guidance.
When these tools were moved to langchain_experimental, the hardcoded ImportError messages were not updated to reflect the new security documentation location, and a dead discussion link was left in, along with a missing space after the discussion URL.
Run `from langchain_classic.agents.agent_toolkits import create_pandas_dataframe_agent` in a Python environment with langchain-classic 1.0.8 installed. Observe the ImportError message containing the dead links and concatenated text.
Fixing Code Block
import re
from pathlib import Path
base = Path("libs/langchain/langchain_classic")
files = [
"tools/__init__.py",
"tools/python/__init__.py",
"agents/__init__.py",
"agents/agent_toolkits/__init__.py",
"agents/agent_toolkits/python/__init__.py",
"agents/agent_toolkits/csv/__init__.py",
"agents/agent_toolkits/pandas/__init__.py",
"agents/agent_toolkits/spark/__init__.py",
"agents/agent_toolkits/xorbits/__init__.py",
]
for rel in files:
path = base / rel
text = path.read_text()
# Remove dead SECURITY.md link and dead discussion link, replace with docs security policy.
text = re.sub(
r"Read https://github\.com/langchain-ai/langchain/blob/master/SECURITY\.md and https://github\.com/langchain-ai/langchain/discussions/11680",
"Read https://docs.langchain.com/oss/python/security-policy",
text,
)
# Ensure there is a period and space after the security-policy link if the next char is not a space or period.
text = re.sub(r"(security-policy)(?=\S)", r"\1. ", text)
# If there is already a period but no space, add a space.
text = re.sub(r"(security-policy\.)(?=\S)", r"\1 ", text)
path.write_text(text)
The script iterates over the affected __init__.py files, replaces the exact dead link pattern with the new docs security-policy URL, and ensures a period and space are added after the link to avoid concatenation. It is idempotent and can be run from the repository root.
Edge Case Audit
This hotfix assumes the current file structure and message text; if the repo layout changes or messages are refactored, the regex may not match. Running it on files with non-ASCII encoding could cause UnicodeDecodeError if not handled, though these files are ASCII. Always make a backup or use version control before running. The new docs link may also change in the future; consider a centralized constant for such URLs. Rollback: revert the changes via git checkout or restore from backup.