liveBook · Manning

LangChain

As explained in LLMs in Production

LangChain is a software framework for building applications that combine language models with prompts, tools, data sources, and workflow logic.

LangChain helps build language-model applications without wiring every prompt, model call, parser, tool, and workflow step by hand. Its main abstraction, LangChain Expression Language (LCEL), composes basic components into reusable chains. section 7.3.1

A simple chain turns a prompt template into a model request and parses the result. That abstraction is excessive for a single f-string, but useful when a pipeline grows into retrieval, SQL, API calls, synthetic-data generation, or asynchronous branching. section 7.3.1

Listing 7.1 Example of creating a basic LangChain chain
import os
from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langchain.schema.output_parser import StrOutputParser

OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")


prompt = ChatPromptTemplate.from_template("Tell me a story about {topic}")
model = ChatOpenAI(model="gpt-3.5-turbo", openai_api_key=OPENAI_API_KEY)
output_parser = StrOutputParser()

chain = prompt | model | output_parser

chain.invoke("the printing press")

A minimal Python chain connects a chat prompt, an OpenAI model, and a string parser with the LCEL pipe operator. section 7.3.1

Use LangChain when the surrounding workflow matters as much as the model call:

  • Combine external data retrieval tools, such as web and YouTube search, with model-generated summaries. section 8.3
  • Add LangServe to host a chain as an API and LangSmith to trace how results change across its links. section 7.3.1
  • Treat chains as language-model data pipelines or DAGs rather than assuming every workflow is linear. section 7.3.1
  • Approach agents cautiously: Python and CSV agents can execute tools and inspect data, yet examples show parsing, import, and reasoning failures. section 8.3

From search tools to agents

A basic setup calls DuckDuckGo and YouTube search directly. A larger agent setup combines those tools with Python execution, mathematical tools, conversation memory, and a local Mistral model; the resulting behavior still requires skepticism and inspection. section 8.3

How LLMs in Production covers it

How deep it goes
Demonstrates basic chain composition and broader agents, while exposing practical failures without detailing framework internals.
Examples
Uses prompt-model-parser chains, web and YouTube search, Python execution, CSV analysis, conversation memory, and local Mistral agents.
What it assumes
Assumes Python and LLM application familiarity while illustrating prompt templates, model calls, output parsing, tools, and agents directly.
What you can do after
Builds chains and tool-using agents, hosts them through LangServe, and traces invocations with LangSmith.
How it connects
Connects prompts, LLMs, RAG, data pipelines, DAGs, tools, agents, APIs, LangServe, and LangSmith.

Also explained in

Compare how 19 books explain LangChain →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLMs in Production. The section links point to the parts of the book it draws on.