Machine Learning & AI

langchain

The duct tape and wiring that turns a chatbot API into an assistant that can look things up and act.

Install it: pip install langchain

What does it do?

LangChain helps developers wire large language models like GPT or Claude together with other things they need to be genuinely useful, a company’s documents, a search engine, a calculator, a database. On its own, an AI language model just predicts text; it can’t browse the web or remember your last conversation unless something builds that scaffolding around it. LangChain provides ready-made pieces for that scaffolding, for retrieving relevant documents, chaining multiple AI calls together, or letting the AI decide which tool to use next. It became the default starting point for the wave of AI assistant apps that appeared after ChatGPT’s launch.

See it in action

This code connects to an AI chat model, asks it a simple question, and prints the answer it sends back.

from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

llm = ChatOpenAI(api_key="your_api_key_here", model="gpt-4o-mini")
response = llm.invoke([HumanMessage(content="What is the capital of France?")])
print(response.content)

Why would a non-developer care?

Almost every AI-powered product feature you’ve seen since 2023, a chatbot that answers questions about a company’s own documents, an assistant that can search and summarize, relies on exactly this kind of connective tissue between a raw language model and real data. It matters because it turned building those features from a months-long engineering project into something a small team could ship in weeks.

Real-world examples

It surged in popularity through 2023 as the default toolkit for the sudden wave of startups building on OpenAI’s and Anthropic’s APIs, appearing in countless demos and production apps for tasks like document Q&A and customer support bots. Without a framework like it, teams would need to hand-build the retrieval and orchestration logic that connects a chatbot to real company data.

Who uses it

Developers and startups building chatbots, AI assistants, or document question-answering tools on top of large language models.

How it compares to alternatives

LangChain competes with newer, sometimes leaner frameworks like LlamaIndex, which focuses more narrowly on connecting language models to documents, and with simpler hand-rolled approaches using the OpenAI or Anthropic SDKs directly. Critics argue it adds more complexity than many projects need, fueling a small industry of do-you-even-need-LangChain blog posts.

Fun fact

LangChain was created by Harrison Chase and released in late 2022, right before ChatGPT’s public launch, timing that turned it almost overnight from a niche side project into one of the fastest-growing open-source projects in software history.

New to Python and want to actually try libraries like this yourself?

Find a beginner-friendly course

Related libraries