Prev Next

AI / LangGraph LangChain Interview questions II

What are common pitfalls in LangChain/LangGraph development?

Developers new to LangChain and LangGraph frequently encounter the same set of issues. Knowing them in advance saves significant debugging time:

  • Context window overflow — injecting the full conversation history into every prompt causes failures on long conversations. Fix: use ConversationBufferWindowMemory, summarisation memory, or LangGraph's message trimming.
  • Agent infinite loops — an agent can keep calling tools indefinitely if it never reaches a satisfying answer. Fix: always set max_iterations in AgentExecutor or add a loop count check in LangGraph conditional edges.
  • Prompt injection from user inputs — if raw user text is inserted into system-level prompts, attackers can override your instructions. Fix: sanitise inputs, use structured message roles, never directly concatenate user text into the system message.
  • Over-engineering with agents — using a 5-step agent for a task that a single RAG call handles. Agents are slower, more expensive, and less predictable. Fix: start with the simplest approach and only add agent complexity when necessary.
  • Ignoring async in high-concurrency servers — using invoke() instead of ainvoke() in FastAPI handlers blocks the event loop and degrades performance under load.
  • Hallucinated tool calls — ReAct agents can sometimes hallucinate tool calls or their inputs. Fix: use structured output (OpenAI Tools Agent) instead of text-parsed ReAct, and add input validation to tool functions.
  • Pinning package versions — LangChain releases frequently; unpinned dependencies in production cause unexpected breaking changes. Always use a lockfile.
How do you prevent LangChain agents from running indefinitely?
Why is using invoke() instead of ainvoke() a pitfall in FastAPI-based LangChain servers?

More Related questions...

Show more question and Answers...


Comments & Discussions