Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

πŸ€– Artificial Intelligence
☁️ Cloud and Infrastructure
πŸ’Ύ Data and Databases
πŸ’Ό Professional Skills
🎯 Programming and Development
πŸ”’ Security and Networking
πŸ“š Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 0
0/5 XP
GitHub
Β© 2026 CheatGridβ„’. All rights reserved.
Privacy PolicyTerms of UseAboutContact

LangChain Cheat Sheet

LangChain Cheat Sheet

Back to Generative AI
Updated 2026-04-28
Next Topic: LangGraph Cheat Sheet

LangChain is a comprehensive framework for building applications powered by large language models (LLMs), transforming simple prompts into production-ready AI agents. With the v1.0 release in October 2025, it has been streamlined around three pillars: create_agent (the new standard agent builder), middleware (composable hooks for customization), and standard content blocks (provider-agnostic message content). LangChain abstracts the complexity of chaining LLM calls, managing memory, integrating tools, and orchestrating retrieval-augmented generation (RAG) pipelines, while LangGraph (stateful graph workflows) and LangSmith (observability) complete the ecosystem. A critical mental model: every component implements the Runnable interface (invoke, stream, batch), and legacy functionality now lives in the separate langchain-classic package.

What This Cheat Sheet Covers

This topic spans 22 focused tables and 169 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1: Core ComponentsTable 2: LCEL (LangChain Expression Language)Table 3: Memory TypesTable 4: Agent TypesTable 5: Agent Middleware (v1.0)Table 6: Tools and Tool CallingTable 7: Retrieval (RAG Components)Table 8: Advanced RAG PatternsTable 9: Chains (Composing Operations)Table 10: LangGraph (Stateful Workflows)Table 11: Callbacks and ObservabilityTable 12: Streaming and AsyncTable 13: Error Handling and RetriesTable 14: CachingTable 15: Prompt EngineeringTable 16: Document TransformersTable 17: IntegrationsTable 18: Structured OutputTable 19: Advanced Agent PatternsTable 20: Testing and EvaluationTable 21: Production Best PracticesTable 22: Debugging and Troubleshooting

Table 1: Core Components

ComponentExampleDescription
Chat Models
ChatOpenAI(model="gpt-4o")
ChatAnthropic(model="claude-3-5-sonnet")
β€’ Unified wrappers for conversational LLMs from OpenAI, Anthropic, Google, and more
β€’ returns structured AIMessage objects with metadata
init_chat_model
from langchain.chat_models import init_chat_model
llm = init_chat_model("openai:gpt-4o")
llm = init_chat_model("anthropic:claude-3-5-sonnet")
β€’ Unified model initialization via provider:model string β€” no provider-specific import needed
β€’ supports fully configurable runtime model selection via config["configurable"]
β€’ recommended v1.0 pattern for provider-agnostic code
Embeddings
OpenAIEmbeddings()
HuggingFaceEmbeddings()
β€’ Convert text to vectors for semantic search
β€’ used with vector stores; supports batch processing for efficiency
Prompts
PromptTemplate(template="Answer: {question}")
ChatPromptTemplate.from_messages([...])
β€’ Templating system for dynamic prompt construction
β€’ supports f-string syntax, Jinja2, and chat message formatting
Output Parsers
JsonOutputParser()
PydanticOutputParser(pydantic_object=MyModel)
β€’ Extract structured data from LLM text responses
β€’ handles JSON, Pydantic models, lists, and custom formats with validation
Runnable Interface
chain.invoke(input)
chain.stream(input)
chain.batch([inputs])
β€’ Unified execution protocol for all LangChain components
β€’ enables invoke (single), stream (tokens), batch (multiple), and async variants

More in Generative AI

  • Knowledge Distillation Cheat Sheet
  • LangGraph Cheat Sheet
  • Advanced RAG Patterns and Optimization Cheat Sheet
  • Chain-of-Thought Reasoning Cheat Sheet
  • LangSmith Cheat Sheet
  • Multimodal AI Cheat Sheet
View all 77 topics in Generative AI