LangChain interview questions and answers
LangChain interview questions check whether you can build an LLM application with the framework and still reason about what it does underneath. Expect Runnables and the pipe syntax (LCEL), prompt templates, chat models and structured output, retrievers and text splitters for RAG, tools and agents, LangGraph for stateful workflows, tracing and evaluation, and when you would skip the framework entirely. The API moves fast, so interviewers value concepts over memorized imports.
By Evin JohnPublished 7 min read
How LangChain comes up in interviews
LangChain shows up when a job description lists it for AI engineer, generative AI or Python backend roles. Few loops are a pure framework quiz. More often you discuss a project you built with it, answer questions about its abstractions, and then defend your choices: why a chain rather than an agent, why LangGraph, why not call the model SDK directly. Because the library has been reorganized more than once, say which version you used and expect that some APIs you know have since moved or been deprecated.
- Project walkthroughExplain an app you built: components, data flow, how you evaluated it and what broke in production.
- Concept questionsRunnables, LCEL, memory, retrievers, tools, agents and LangGraph, each in a sentence or two with an example.
- Live codingBuild a small chain or a RAG step in Python, often with the model mocked or an API key provided.
- Design trade-offsChoose between a fixed chain, an agent and a graph for a workflow, and explain how you would trace and test it.
LangChain fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is LangChain and what problem does it solve? | Purpose | A Python and JavaScript framework of common interfaces for building LLM apps: chat models, prompts, retrievers, tools and agents behind consistent APIs, plus integrations with many model providers and vector stores. |
| How is the project split into packages? | Ecosystem | In recent releases, a core package holds the base abstractions and the Runnable interface, the main package holds higher-level chains and agents, partner packages hold provider integrations, and a community package holds third-party ones. Names and boundaries have shifted across versions. |
| What is a Runnable? | Core interface | The common interface most components implement: invoke for one input, batch for many, stream for incremental output, and async versions of each. Anything that is a Runnable can be composed with others. |
| What is LCEL? | Composition | The LangChain Expression Language: composing Runnables with the pipe operator, so the output of one step becomes the input of the next. The result is itself a Runnable with streaming, batching and tracing built in. |
| What does a prompt template do? | Prompts | It turns a dict of variables into chat messages or a string, keeping system instructions, few-shot examples and placeholders for history in one reusable object. |
| Chat model versus the older LLM interface? | Models | Chat models take a list of messages with roles and return a message object, which is how current providers work. The older text-in, text-out interface remains mainly for legacy completion models. |
| What is an output parser? | Parsing | A step that turns the model's message into something your code can use: a plain string, JSON or a typed object. Many chat models now support structured output directly from a schema, which is usually more reliable. |
| What is a document loader and a text splitter? | RAG plumbing | Loaders read sources such as PDFs, web pages or databases into Document objects with content and metadata. Splitters, such as the recursive character splitter, cut them into chunks that respect paragraphs and sentences where possible. |
| What is a retriever? | Retrieval | A Runnable that takes a query string and returns relevant Documents. A vector store can act as one, and others wrap keyword search, multiple queries or rerankers behind the same interface. |
| What are callbacks used for? | Observability | Hooks that fire on events such as a model start, a new token or a tool call. They power logging, streaming to a UI and tracing tools. |
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
prompt = ChatPromptTemplate.from_messages([
("system", "You answer questions about our refund policy in two sentences."),
("human", "{question}"),
])
llm = ... # any chat model integration, for example from a provider's partner package
chain = prompt | llm | StrOutputParser()
answer = chain.invoke({"question": "Can I return an opened item?"})
answers = chain.batch([{"question": "How long do refunds take?"}, {"question": "Do you refund shipping?"}])
for piece in chain.stream({"question": "Who pays return postage?"}):
print(piece, end="")If you are asked to explain what the pipe really does, a plain-Python model of it helps. This toy is not LangChain, but it captures the idea that every step shares one interface and composition returns another step.
class Step:
"""A toy stand-in for a LangChain Runnable: invoke() plus | composition."""
def __init__(self, fn):
self.fn = fn
def invoke(self, x):
return self.fn(x)
def __or__(self, other):
return Step(lambda x: other.invoke(self.invoke(x)))
def batch(self, xs):
return [self.invoke(x) for x in xs]
prompt = Step(lambda d: f"Summarize in one line: {d['text']}")
fake_llm = Step(lambda p: {"content": p.upper()}) # pretend model call
parser = Step(lambda msg: msg["content"].strip())
chain = prompt | fake_llm | parser
print(chain.invoke({"text": "hello"})) # SUMMARIZE IN ONE LINE: HELLO
print(len(chain.batch([{"text": "a"}, {"text": "b"}]))) # 2Intermediate questions: retrieval, memory and structure
- How do you build a RAG chain in LangChain? Load and split documents, embed them into a vector store, expose it as a retriever, then compose a chain that runs the retriever, formats the documents into the prompt and calls the model. A parallel step (RunnableParallel) can pass the question and the retrieved context side by side. The retrieval ideas themselves are in RAG interview questions.
- What does RunnablePassthrough do? It forwards its input unchanged, or adds computed keys to it with assign, so a later step can see both the original question and new values such as retrieved context.
- How do you keep conversation history? Store messages per session in a chat history backend and insert them into the prompt through a messages placeholder. Older memory classes were deprecated in favor of message history wrappers and, for agents, LangGraph's persisted state.
- How do you get reliable JSON out of a model? Define a schema (a Pydantic model or JSON schema) and use the chat model's structured output method where the provider supports it; otherwise use a parser with format instructions and validate, retrying on failure.
- How do you stream tokens to a web client? Call stream or astream on the chain and forward chunks through server-sent events or a WebSocket. Every step in the chain must support streaming for tokens to arrive early.
- How do retries and fallbacks work? Runnables can be wrapped with retry settings for transient errors and with fallbacks, such as a second model provider, used when the first one fails.
- Why would you run chains asynchronously? LLM calls are slow network waits, so async methods let a server handle many requests concurrently, and batch runs calls in parallel up to a concurrency limit.
- How do you test a chain without paying for model calls? Swap in a fake chat model that returns fixed responses for unit tests, and keep a smaller set of integration tests that hit the real model with evaluation checks.
Tools, agents and LangGraph questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| How do you define a tool? | Tools | A function with a clear name, description and typed arguments, often created with a decorator. The model sees the schema and description, so those are effectively part of the prompt and need care. |
| What happens in a tool-calling loop? | Agents | The model returns a request to call a tool with arguments, your code runs it and adds the result as a tool message, and the model continues until it answers without a tool call or a step limit is hit. |
| Chain or agent: how do you choose? | Design | Use a fixed chain when the steps are known in advance; it is cheaper, faster and easier to test. Use an agent when the next step depends on intermediate results, and bound it with step limits and narrow tools. |
| What is LangGraph and why use it? | LangGraph | A library from the same team for building workflows as graphs of nodes that read and update shared state, with conditional edges and loops. It suits agents that need explicit control flow, retries, persistence and human review steps. |
| What is a checkpointer in LangGraph? | Persistence | A store that saves graph state after steps, keyed by a thread id, so a conversation or workflow can resume, be inspected, or wait for human input and continue later. |
| How would you add human approval before an action? | Safety | Pause the graph before the node that performs the action (an interrupt), show the proposed action to a person, and resume with their decision stored in state. |
| How do you stop an agent from looping or running up costs? | Control | Set a recursion or step limit, give tools clear error messages, detect repeated identical calls, cap tokens per run, and trace runs to see where loops start. |
| What is LangSmith used for? | Tracing | A hosted platform from the LangChain team for tracing runs, inspecting each step's inputs and outputs, building datasets and running evaluations. Other tracing tools can be used instead through callbacks or OpenTelemetry-style integrations. |
Senior and scenario questions
Senior questions are about judgement: what the framework buys you, what it costs, and how you keep an app stable when both the library and the models underneath it change. The model behavior behind those changes is covered in large language model interview questions.
| Question | What it tests | What a strong answer shows |
|---|---|---|
| When would you not use LangChain? | Judgement | For a single model call or a small, stable pipeline, the provider SDK plus plain functions is easier to read, debug and upgrade. The framework pays off with many integrations, swapping providers, streaming across steps or agent orchestration. |
| A minor LangChain upgrade broke production. How do you prevent a repeat? | Maintenance | Pin versions, read changelogs and deprecation warnings, keep integration tests and an evaluation set that run on every upgrade, and upgrade in a branch with traces compared side by side. |
| Responses got slow after adding a retriever and a reranker. Where do you look? | Performance | Traces show the time per step. Look at embedding calls, network hops to the vector store, reranking too many candidates and sequential steps that could run in parallel. |
| How would you evaluate a LangChain app? | Evaluation | A dataset of real inputs with expected outputs or rubrics, automatic checks per step (retrieval recall, JSON validity) and graded final answers, run on every prompt, model or library change. |
| Your agent calls the wrong tool half the time. What do you change? | Tool design | Fewer tools with sharper names and descriptions, examples of when to use each, arguments that are hard to misuse, or a router step that picks a narrower toolset first. |
| How do you protect an agent that can send emails? | Security | Least privilege, allowlisted recipients, human approval for sending, treating retrieved content as untrusted to resist prompt injection, and an audit log of every tool call. |
Fictional example
- Interviewer
- Your résumé says you replaced an agent with a LangGraph workflow. Why?
- Candidate
- We had a ticket triage agent with six tools. In traces it often searched the knowledge base three or four times before classifying, which was slow and sometimes looped. The real process had a fixed shape: classify, look up the customer, search docs only for technical tickets, then draft a reply for an agent to approve. I rebuilt it as a graph with those nodes, a conditional edge for the docs search and an interrupt before the reply was saved. Steps per ticket dropped and became predictable, and the approval step gave support leads the control they asked for. We kept our evaluation set from the agent version, so I could show quality did not fall.
A ten-day LangChain practice plan
- Days 1 and 2: read the current docs for the version you will discuss and rebuild a basic chain with invoke, batch and stream. Note any imports that differ from older tutorials.
- Days 3 and 4: build a RAG chain over your own documents with a splitter, a vector store and a retriever, and return citations.
- Day 5: add structured output with a schema and validation, plus a fallback model.
- Days 6 and 7: build a small LangGraph workflow with two tools, a conditional edge, a checkpointer and a human approval step.
- Day 8: trace every run, then write unit tests with a fake model and a 20-item evaluation set.
- Days 9 and 10: rehearse your project story and the question "when would you not use LangChain?" until both are crisp.
Framework interviews drift into API trivia if you let them, so practise steering back to design decisions. Natively, an AI interview assistant for Mac and Windows, transcribes your mock interviews on your computer, which lets you check whether your project story explained why you chose a graph over an agent. In practice it can draft suggested answers, read a code exercise or a stack trace from a screenshot, and help with Python. With Pro or the free trial it can also work from your résumé and the job description you add, and it keeps the transcript and notes afterwards.
Questions people ask
What LangChain questions are asked in interviews?
What Runnables and LCEL are, prompt templates and chat models, output parsers and structured output, loaders, splitters and retrievers for RAG, conversation history, tools and agents, LangGraph, tracing and when not to use the framework.
What is LCEL in LangChain?
The LangChain Expression Language: composing components that share the Runnable interface with the pipe operator, so a prompt, a model and a parser become one chain that supports invoke, batch and stream.
What is the difference between LangChain and LangGraph?
LangChain provides the components and simple chains. LangGraph, from the same team, builds stateful workflows as graphs with loops, conditional edges, checkpoints and human approval steps, which suits more controlled agents.
Should I mention LangChain versions in an interview?
Yes. The library has been reorganized and many APIs deprecated over time, so say which version you used and show you know the concepts rather than one release's imports.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
