AI Hints
Home›LangChain Tutorial›The Bigger Picture
LangChain · Lesson 117 of 120

Cheat Sheet: Core

Models, prompts, chains.

⏱ 2 min read▶ Video at 2:13:25🎓 Free
Watch this lesson in the LangChain courseWatch on YouTube ↗Full LangChain course

Here's a one page reminder of the core of LangChain. Models, prompts, parsers, and chains. Pause the video, and keep it handy.

Cheat Sheet: Core
From the video: Cheat Sheet: Core
  • One-page reminder
  • Models to chains
  • Pause and keep it

Core cheat sheet

Init chat model creates any model, and invoke, stream, and batch call it. Chat prompt template fills in the blanks. The pipe joins steps into a chain. Str output parser returns plain text. And with structured output returns Pydantic objects.

cheatsheet_core.pypython
from langchain.chat_models import init_chat_model
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

model = init_chat_model("google_genai:gemini-flash-lite-latest", temperature=0)
model.invoke("Hi")   # .stream(...)  .batch([...])  .ainvoke(...)

prompt = ChatPromptTemplate.from_messages([("system", "You help {shop}."), ("human", "{q}")])
chain = prompt | model | StrOutputParser()
chain.invoke({"shop": "Riverside Books", "q": "Hello"})

structured = model.with_structured_output(MyPydanticModel)

Remember

A few more core ideas worth remembering. Runnables all share invoke, batch, and stream. Runnable passthrough copies input forward. Dictionaries in a chain run in parallel. And set LLM cache saves repeated calls.

keyvalue
Runnablesinvoke, batch, stream
Passthroughcopy input forward
Dictsrun in parallel
Cacheset_llm_cache

Summary

The core is models, prompts, parsers, and chains joined with the pipe. Next, a cheat sheet for agents, and RAG.

Key takeaways
  • init_chat_model
  • prompt | model | parser
  • with_structured_output
Next up: Cheat Sheet: Agents and RAG — tools, agents, retrieval