LangChain Essentials Cheat Sheet

LangChain framework for LLM applications — chains, agents, tools, memory, retrieval, and the LangChain Expression Language (LCEL) for composable pipelines.

Last Updated: May 1, 2025

Core Components

ItemDescription
LLMs/Chat ModelsInterface to any model — OpenAI, Anthropic, HuggingFace, local via Ollama
Prompt TemplatesParameterized prompts with input variables — reuse and compose
ChainsSequence of calls — prompt → LLM → parser → output. LCEL: prompt | llm | parser
RetrieversFetch relevant documents from vector stores — RAG backbone
AgentsLLM decides which tool to use and when — ReAct, OpenAI functions, structured chat
MemoryPersist conversation state — buffer, summary, vector-store backed

LCEL (Expression Language)

chain = prompt | llm | StrOutputParser()
Basic chain: template → generate → parse string
chain = prompt | llm | JsonOutputParser()
JSON output chain — LLM returns structured data
chain = {'context': retriever, 'question': RunnablePassthrough()} | prompt | llm
RAG chain — retrieves + passes context
chain.with_config(run_name='MyChain')
Name for tracing in LangSmith
chain.stream(input)
Stream response token-by-token
chain.batch([input1, input2])
Process multiple inputs in parallel

Retrieval (RAG) Patterns

ItemDescription
Document LoadersLoad from 100+ sources: PDF, web, database, Notion, GitHub
Text SplittersRecursiveCharacterTextSplitter — chunk by paragraph/sentence with overlap
EmbeddingsOpenAI, Cohere, HuggingFace — convert text to vectors
Vector StoresChroma (local), Pinecone (cloud), Weaviate, Qdrant, FAISS
RetrievalQAQuestion-answering over documents with source attribution
ConversationalRetrievalRAG with chat history — rephrase question using history then retrieve

Ecosystem

ItemDescription
LangSmithObservability platform — traces, evals, datasets, prompt hub
LangServeDeploy chains as REST APIs — FastAPI + chain = production endpoint
LangGraphStateful multi-actor applications — graph-based agent workflows
LangChain HubCommunity prompt templates — import, fork, customize
Pro Tip: Use LCEL (LangChain Expression Language) for all new chains — it's more composable, supports streaming, and is easier to debug than the legacy Chain classes.