Skip to content

fix: replace deprecated langchain_classic imports with modern LCEL - #198

Open
Artibar wants to merge 1 commit into
c2siorg:mainfrom
Artibar:fix/deprecated-langchain-imports
Open

fix: replace deprecated langchain_classic imports with modern LCEL#198
Artibar wants to merge 1 commit into
c2siorg:mainfrom
Artibar:fix/deprecated-langchain-imports

Conversation

@Artibar

@Artibar Artibar commented Apr 25, 2026

Copy link
Copy Markdown

Summary

  • Remove unused PromptTemplate import from app.py
  • Replace LLMChain + PromptTemplate in NewsService.py with modern LCEL syntax (prompt | llm | StrOutputParser())
  • Update openai==0.27.8 to openai>=1.0.0 in requirements.txt

app.py used invalid import, however NewsService.py used deprecated
import from langchain_classic and requirements.txt pins openai==0.27.8 (2023).
This causes runtime errors and prevents running the app locally.

Description

app.py — removed invalid PromptTemplate import

  • services/NewsService.py — replaced LLMChain + PromptTemplate
    from langchain_classic with modern LCEL syntax:
    chain = prompt | self.llm | StrOutputParser()
  • requirements.txt — updated openai==0.27.8 to openai>=1.0.0

Related Issue

Fixes #197

Reference

Official LLMChain deprecation notice:
https://reference.langchain.com/python/langchain-classic/chains/llm/LLMChain
Assisted-By: Claude (syntax reference)

Motivation and Context

change is required due to deprecated import cause error and need to maintain up to date latest version

How Has This Been Tested?

  • Cloned the repository fresh on Windows 11 with Python 3.11
  • Ran pip install -r requirements.txt successfully after fix
  • Ran python app.py — app starts without ImportError
  • Verified app loads at http://127.0.0.1:5000 successfully
  • Confirmed langchain_classic imports no longer present in
    source files using findstr /r "langchain_classic" app.py services\NewsService.py

Test environment:

  • OS: Windows 11
  • Python: 3.11.9
  • pip: 26.0.1

Screenshots (if appropriate):

  • Before fix — deprecated imports found:
Screenshot 2026-04-25 152710
  • After Fix — app reloads successfully without ImportError:
Screenshot 2026-04-25 152529

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

- Remove unused PromptTemplate import from app.py
- Replace LLMChain + PromptTemplate in NewsService.py
  with modern LCEL syntax (prompt | llm | StrOutputParser())
- Update openai==0.27.8 to openai>=1.0.0 in requirements.txt

Fixes c2siorg#197
Assisted-By: Claude (code review and suggestions)
@shahryarkhalid-cmd

Copy link
Copy Markdown

Hi @Artibar, I tested this PR locally against main and wanted to share results.

Confirmed working:

  • The unused PromptTemplate import removal in app.py is correct.
  • langchain_core.prompts.PromptTemplate, langchain_core.output_parsers.StrOutputParser, and langchain_community.llms.HuggingFaceEndpoint all import cleanly with this fix.
  • The chain = prompt | self.llm | StrOutputParser() LCEL pattern runs correctly and returns a plain string, which correctly resolves the old output['text'] mismatch since toJSON() expects a string input.

Found while testing — not fixed by this PR:
toJSON() still has a bug independent of this fix. It unconditionally does news_list_json.pop() at the end, which drops the last parsed item every time. I tested it with realistic LLM-style output:

  • 2 valid news items in → only 1 returned
  • 1 valid news item in → empty list returned

This means even after this PR's fix, the /news and /news_keywords endpoints will still lose at least one article, and single-result queries will return nothing.

Separately (not related to this PR): installing the full requirements.txt as-is triggers a long pip backtracking loop across unpinned langchain/langchain-community/sentence-transformers versions — looks like the same issue described in #211.

Would you like me to open a follow-up PR for the toJSON() fix, or would you prefer to fold it into this one? Happy to help either way — let me know if this PR is still active on your end.

@shahryarkhalid-cmd

Copy link
Copy Markdown

@Artibar @hardik1408

I tested this PR locally against main. The old code used deprecated langchain_classic imports that broke at runtime — this PR's LCEL fix resolves that correctly, confirmed the imports work and the chain runs.

While testing, I found a separate bug in toJSON() that's still present: it always drops the last parsed news item (news_list_json.pop() at the end runs unconditionally). Tested with 2 items → only 1 returned; tested with 1 item → empty list returned.

Happy to open a follow-up PR for the toJSON fix if useful, or fold it into this one — let me know what you'd prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Invalid import langchain_classic.prompts and langchain_classic.chains in app.py and NewsService.py cause error at runtime

2 participants