Gen-ai Interview Questions

LangChain & Frameworks Interview Questions

40 in-depth interview questions on LangChain, LangGraph, LlamaIndex, agents, tools, chains, memory, callbacks, and streaming.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

40 in-depth interview questions on LangChain, LangGraph, LlamaIndex, agents, tools, chains, memory, callbacks, and streaming. This interview-focused guide covers essential langchain & frameworks interview questions concepts for technical interviews.

LangChain & LLM Frameworks Interview Questions

LangChain and related frameworks are the backbone of production LLM applications. These 40 questions cover chains, agents, memory management, callback systems, LangGraph, and best practices for building robust LLM-powered apps.


1. What is LangChain?

LangChain is an open-source framework for building LLM-powered applications. It provides abstractions for:

  • Chains: Sequential/composable LLM calls
  • Agents: LLMs that use tools and make decisions
  • Memory: Conversation state management
  • Retrievers: Document retrieval for RAG
  • Callbacks: Logging, monitoring, streaming
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4", temperature=0)
template = "Write a {tone} email about {topic}"
prompt = PromptTemplate.from_template(template)
chain = LLMChain(llm=llm, prompt=prompt)
result = chain.run(tone="professional", topic="project delay")

2. What are the core components of LangChain?

  1. LLMs/Chat Models: Interface to language models
  2. Prompts: Templates with variables
  3. Chains: Linked LLM calls or LLM + utilities
  4. Indexes/Retrievers: Document loading, splitting, embedding, retrieval
  5. Agents & Tools: LLM decides which tool to use and when
  6. Memory: Storing conversation state
  7. Callbacks: Hooks into the execution pipeline

3. What is the difference between LLMChain and a simple LLM call?

An LLMChain combines prompt templating + LLM + optional output parser into a reusable pipeline. A plain LLM call just sends raw text. Chains add structure, validation, and composability.

4. What is a Chain in LangChain?

A Chain connects multiple components (LLMs, prompts, tools, other chains):

  • SimpleChain: Single LLM call with prompt
  • SequentialChain: Multiple chains run in sequence, sharing inputs/outputs
  • RouterChain: Routes input to different chains based on content
  • MapReduceChain: Process documents in chunks, then combine

5. What are LangChain Agents?

Agents use an LLM to decide which actions to take and in what order. The LLM reasons about the task, selects appropriate tools, processes results, and decides next steps.

from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType

tools = [
    Tool(name="Search", func=search_function, description="Search the web"),
    Tool(name="Calculator", func=calculator, description="Do math")
]
agent = initialize_agent(
    tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION
)
agent.run("What's the square root of the population of Tokyo?")

6. What are Tools in LangChain?

Tools are functions the agent can call:

  • Built-in: Google Search, Wikipedia, Python REPL, calculator
  • Custom: Any function with a name, description, and input schema
  • Tool description is crucial: the LLM uses it to decide which tool to use

7. What is the ReAct Agent?

ReAct (Reasoning + Acting) agents follow this cycle:

Thought: I need to find Tokyo's population
Action: Search("Tokyo population 2024")
Observation: 37.4 million
Thought: Now I need the square root
Action: Calculator("sqrt(37400000)")
Observation: 6115.5
Thought: I have the answer
Answer: 6115.5

8. What is LangGraph?

LangGraph is a framework for building stateful, multi-actor agent applications. Unlike linear chains, LangGraph models agent workflows as graphs (nodes + edges). Supports cycles, branching, and human-in-the-loop patterns.

from langgraph.graph import StateGraph

workflow = StateGraph(AgentState)
workflow.add_node("agent", agent_node)
workflow.add_node("tool_executor", tool_node)
workflow.add_edge("agent", "tool_executor")
workflow.add_edge("tool_executor", "agent")  # Cycles!
workflow.set_entry_point("agent")

9. What is LangChain Expression Language (LCEL)?

LCEL is a declarative syntax for composing chains using the | operator. Enables built-in streaming, async, batch, retries, and fallbacks.

from langchain_core.runnables import RunnablePassthrough

chain = (
    {"context": retriever, "question": RunnablePassthrough()}
    | prompt
    | llm
    | output_parser
)
result = chain.invoke("What is RAG?")

10. What is the difference between LangChain and LlamaIndex?

  • LangChain: General-purpose LLM app framework. Chains, agents, memory, tools. Wide scope.
  • LlamaIndex: Specialized in data indexing and retrieval. Superb at RAG, document parsing, query engines. Narrower, deeper focus.

Use both together: LlamaIndex for the ingestion/retrieval layer, LangChain for orchestration and agent logic.

11. What is Memory in LangChain?

Memory persists information across conversation turns:

  • ConversationBufferMemory: Stores full history
  • ConversationBufferWindowMemory: Last K exchanges
  • ConversationSummaryMemory: Summarizes history
  • ConversationTokenBufferMemory: Trims to token limit
  • VectorStoreRetrieverMemory: Semantic retrieval of relevant history

12. What are Callbacks in LangChain?

Callbacks hook into the execution pipeline for monitoring, logging, streaming:

  • on_llm_start, on_llm_end, on_llm_error
  • on_chain_start, on_chain_end
  • on_tool_start, on_tool_end
  • Used by LangSmith for tracing and evaluation

13. What is LangSmith?

LangSmith is LangChain's platform for debugging, testing, evaluating, and monitoring LLM applications. It provides:

  • Full execution traces
  • Latency and token analytics
  • Dataset management for testing
  • A/B comparison of prompt variants
  • Production monitoring

14. What is a VectorStore in LangChain?

VectorStore is an abstraction over vector databases. LangChain supports: Chroma, Pinecone, Weaviate, FAISS, Qdrant, Milvus, Redis, and more. Standardized interface: add_documents(), similarity_search(), max_marginal_relevance_search().

15. What is a Document Loader?

Document Loaders ingest data from various sources:

  • TextLoader, PDFLoader, CSVLoader
  • WebBaseLoader (web scraping)
  • NotionLoader, GoogleDriveLoader
  • Custom loaders for any data source

16. What is Text Splitting in LangChain?

Text Splitters break documents into chunks for embedding:

  • RecursiveCharacterTextSplitter: Splits by separators hierarchy (¶ → sentence → word)
  • TokenTextSplitter: Splits by token count
  • MarkdownHeaderTextSplitter: Splits by markdown headers
  • Chunk size + overlap are key parameters
from langchain.text_splitter import RecursiveCharacterTextSplitter

splitter = RecursiveCharacterTextSplitter(
    chunk_size=1000,
    chunk_overlap=200,
    separators=["\n\n", "\n", ".", " "]
)
docs = splitter.split_documents(raw_documents)

17. What is a Retriever in LangChain?

Retrievers find relevant documents from a store:

  • VectorStore retriever (semantic similarity)
  • MultiQuery retriever (generates multiple search queries)
  • Contextual Compression retriever (removes irrelevant content)
  • Ensemble retriever (combines multiple retrievers)
  • Self-query retriever (metadata filtering)

18. What is the difference between a Chain and an Agent?

  • Chain: Fixed, predetermined sequence of steps. No decision-making.
  • Agent: The LLM decides what to do dynamically. Uses tools as needed, loops, adapts.
  • Use chains for known workflows. Use agents for open-ended tasks.

19. What are the different Agent types in LangChain?

  • Zero-shot ReAct: Pure reasoning, no examples
  • Conversational ReAct: Maintains conversation history
  • OpenAI Functions: Uses native function calling
  • Structured Chat: Supports multi-input tools
  • Self-Ask with Search: Follow-up question decomposition

20. What is a Router Chain?

A Router Chain directs input to different sub-chains based on content: "Is this a math question? → MathChain. Is this a code question? → CodeChain." Uses LLM classification + routing logic.

21. What is the Map-Reduce Chain?

Map-Reduce processes documents:

  1. Map: Process each document independently (summarize, extract)
  2. Reduce: Combine individual results into final output Good for summarization of long documents that exceed context window.

22. What is the Refine Chain?

Refine processes documents sequentially, refining the output with each document. Better quality than map-reduce for summarization, but sequential (slower). Each step: "Given the current summary and new text, refine the summary."

23. What is a ConversationalRetrievalChain?

ConversationalRetrievalChain combines chat history with document retrieval. It reformulates the question based on conversation context, retrieves relevant docs, and generates an answer. Essential for building RAG chatbots.

24. How does LangChain handle streaming?

LCEL chains support .stream() for token-by-token output. Can also pass streaming=True to LLM constructors. Useful for real-time chat interfaces where users see output as it's generated.

for chunk in chain.stream({"question": "Explain RAG"}):
    print(chunk, end="", flush=True)

25. What are Runnables in LangChain?

Runnables (LangChain Core) provide a unified interface for all components:

  • .invoke(input) — single call
  • .batch(inputs) — batch processing
  • .stream(input) — streaming
  • .ainvoke(input) — async
  • .astream(input) — async streaming

26. What is Hugging Face Transformers integration?

LangChain integrates with Hugging Face models:

  • HuggingFacePipeline: local models via transformers pipeline
  • HuggingFaceEndpoint: Inference API for hosted models
  • HuggingFaceEmbeddings: For vector embeddings

27. What is the difference between LangChain Community and Core packages?

  • langchain-core: Base abstractions (Runnable, BaseLLM, BaseRetriever)
  • langchain-community: Third-party integrations (maintained by community)
  • langchain (umbrella): Chains, agents, higher-level constructs
  • langchain-openai / langchain-anthropic: Provider-specific packages

28. What is Output Parsing in LangChain?

Output Parsers convert raw LLM text into structured data:

  • StrOutputParser: Plain string
  • JsonOutputParser: JSON
  • PydanticOutputParser: Pydantic models
  • CommaSeparatedListOutputParser: List
  • StructuredOutputParser: Custom schemas

29. What is RetrievalQA Chain?

RetrievalQA answers questions using retrieved documents. Workflow:

  1. Embed user question
  2. Retrieve similar documents from VectorStore
  3. Pass documents as context to LLM
  4. Generate answer grounded in retrieved docs

30. What is the Parent Document Retriever?

Splits documents into small chunks for retrieval (better relevance) but returns the parent/larger document for context (more complete information). Balances retrieval quality with context completeness.

31. What is the MultiQuery Retriever?

MultiQueryRetriever generates multiple rephrased versions of the user's question, retrieves documents for each, and merges results. Catches different perspectives and phrasing variations.

32. What is Contextual Compression?

ContextualCompressionRetriever removes irrelevant content from retrieved documents. Passes each document through a compressor (LLM or embedding-based) that filters out text not relevant to the query.

33. How do you add custom Tools to LangChain?

from langchain.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get current weather for a city."""
    # API call logic
    return f"Weather in {city}: 72°F, sunny"

# Tool description is used by the agent to decide when to use it

34. What is tool error handling in LangChain?

Agents can handle tool errors with handle_parsing_errors=True and max_iterations. On tool failure, the error message is fed back to the agent, which can try alternative approaches.

35. What is the difference between synchronous and asynchronous chains?

  • Sync: .invoke(), .run(), .predict() — blocking
  • Async: .ainvoke(), .arun(), .apredict() — non-blocking, better performance for I/O-bound workloads

36. What is the role of RunnablePassthrough?

Passes input through unchanged. Used in LCEL chains when you need to pass the original input alongside transformed data to later steps.

37. What is the RunnableLambda?

Wraps a regular Python function to make it LCEL-compatible. Enables custom transformation logic within declarative chains.

38. What is the RunnableParallel?

Executes multiple runnables concurrently and merges results. Useful when you need to call multiple APIs or retrievers simultaneously.

39. How do you implement fallbacks in LangChain?

Using .with_fallbacks() on runnables. If the primary model/chain fails (API error, rate limit), automatically switches to a backup.

primary_chain = gpt4_chain.with_fallbacks([gpt35_chain])

40. What are best practices for building production LangChain apps?

  1. Use LCEL (declarative, streaming, async by default)
  2. Add LangSmith tracing for debugging
  3. Implement fallbacks and retries
  4. Cache LLM calls where possible
  5. Validate outputs with parsers
  6. Set reasonable timeouts and rate limits
  7. Version your prompts (LangSmith Hub)
  8. Test with diverse inputs, not just happy paths
PYTHON PLAYGROUND
⏳ Loading editor…

AI Mentor

Confused about "LangChain, LangGraph, LlamaIndex - chains, agents, memory, retrievers, streaming, callbacks, and LLM application frameworks"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 3

What is the primary difference between a Chain and an Agent in LangChain?

Chains use prompts, agents don't
Chains are fixed sequences; agents decide dynamically what to do
Agents are faster than chains
There is no difference