A chain is a sequence of operations where the output of one step becomes the input to the next. For example, a RAG chain can be user query → retriever → context → prompt → LLM → answer. Chains are useful when the workflow is relatively fixed and deterministic. The important interview point is that LangChain provides abstractions to compose these individual steps without having to manually manage every model/API interaction.
LangChain provides prompt templates that allow us to create reusable prompts with dynamic variables. Instead of hardcoding a prompt every time, we can define something like a system instruction plus {context} and {question}, then inject the appropriate values at runtime. This makes prompts easier to reuse, version, maintain, and integrate into pipelines.
A retriever is an abstraction that takes a query and returns relevant documents or chunks. LangChain can connect to vector databases and other retrieval systems through a common retriever interface. In RAG, the typical flow is query → retriever → relevant documents → prompt → LLM, allowing the retrieval implementation to change without completely rewriting the application.
A tool is a function that an LLM/agent can invoke to interact with an external system. Examples include calling an API, querying a database, performing a calculation, or searching documents. LangChain provides abstractions for defining tools and their inputs/outputs, while the application remains responsible for permissions, validation, and safe execution.
A LangChain agent is an LLM-driven system that can decide which tools to use and what steps to take based on the task rather than following one completely fixed chain. For example, the agent might decide: search database → call fraud API → analyze result → generate report. This gives flexibility, but agents are harder to control and debug than deterministic chains, especially when workflows become complex.
Structured output allows the LLM to return information according to a predefined schema instead of arbitrary text. For example, a credit-analysis agent could return {risk_score, reasons, recommendation} with defined types. LangChain can integrate structured-output mechanisms so applications can validate and consume model responses programmatically, which is much safer for production workflows.
LangChain applications can maintain information across interactions by storing and supplying previous conversation or application state to the model. For example, a chatbot can remember earlier messages and use them in subsequent requests. However, memory is fundamentally an application-level state/context-management problem; we should not assume the LLM itself permanently remembers information just because a framework provides a memory abstraction.
LCEL (LangChain Expression Language) is LangChain's way of composing components using a pipeline-style syntax. Conceptually, you can connect components like prompt → model → parser and pass data between them. It also provides useful execution capabilities such as streaming and asynchronous execution. For an interview, remember: LCEL makes LangChain components composable into reusable execution pipelines.
A typical LangChain RAG implementation connects a document loader → text splitter → embedding model → vector store → retriever → prompt → LLM → output parser. At query time, the retriever finds relevant chunks, those chunks are inserted into the prompt, and the LLM generates an answer grounded in that context. LangChain mainly provides the orchestration abstractions; the actual embeddings, vector database, LLM, and retrieval strategy can come from different providers.