Documents
Home>Documents>Dev>Backend

Django + LangChain SSE Streaming and Dependency Hell

5 min readSep 21, 2025Feb 22, 2026

Web Project Overview

I set out to build an agent-based backend using LangChain and Django.
After bumping the LangChain version for the first time in a while, I descended into dependency hell — writing this up to document what happened.

LangChain Dependency Hell

flowchart TD
    A[langchain 업데이트 시도] --> B{빌드 성공?}
    B -->|실패| C[langchain-core 버전 조정]
    C --> D{빌드 성공?}
    D -->|실패| E[langchain-community 버전 조정]
    E --> F{빌드 성공?}
    F -->|실패| G[pydantic 버전 조정]
    G --> H{빌드 성공?}
    H -->|실패| I[처음부터 다시...]
    B -->|성공| J[테스트]
    D -->|성공| J
    F -->|성공| J
    H -->|성공| J

Version combinations I actually tried:

langchain==0.3.0 + langchain-core==??? → failed
langchain-community==0.3.1 → failed
langchain-community==0.3.0 → failed
langchain-text-splitters==0.2.4 → failed
langchain-text-splitters==0.3.0 → succeeded...?
langchain-openai==0.3.0 → failed
langchain-openai==0.2.8 → succeeded!

SSE Streaming Implementation

SSE (Server-Sent Events) streaming for AI content generation:

class AIContentGenerateStreamView(View):
    def post(self, request):
        return StreamingHttpResponse(
            self._stream_response(request),
            content_type='text/event-stream'
        )

    def _stream_response(self, request):
        for chunk in llm.stream(prompt):
            yield f"data: {json.dumps({'content': chunk})}\n\n"

Docker Optimizations

  • Create static file / media directories
  • Set environment variables to optimize Python execution
  • Added conditional git clone logic, then removed it again

Looking Back…

  1. Pin LangChain versions — no exceptions: Specify every sub-package version explicitly in requirements.txt
  2. pydantic v1 vs v2 compatibility: Imports like BaseCache differ depending on the version
  3. Configure CORS from the start: Adding it later makes debugging a nightmare

Going Forward…

Now that LangChain has hit 1.0.0+, this is all somewhat moot — but for the project as a whole, standardizing on uv with a pyproject.toml-based setup, or just packaging everything as a library, seems like the right call.

Tags
DjangoLangChainSSEDependenciesDockerTroubleshooting