The Ollama Python library calls a local model directly, which is enough for a one-off script. LangChain adds a layer on top: its ChatOllama class presents the same local model through LangChain’s standard chat-model interface, so the code you write for one question can later grow into chains, retrieval, and agents without changing how you talk to the model. The integration lives in the langchain-ollama package, and LangChain’s own reference page shows the setup: install langchain-ollama and download any models you want to use from Ollama first.
Install the package and pull a model
Install the package and pull the model the script will call. The reference page’s own example pulls gpt-oss:20b; the script below uses the smaller llama3.2 instead, because the model name is simply the name of the Ollama model to use, and llama3.2 is already the small model used across these guides.
pip install -U langchain-ollama
ollama pull llama3.2
Write the script
Save this as langchain_ollama_chat.py. The messages and the model call follow LangChain’s reference example, which uses a system message and a human message and calls model.invoke(messages):
from langchain_ollama import ChatOllama
model = ChatOllama(model="llama3.2", temperature=0.8)
messages = [("system", "You are a helpful translator. Translate the user sentence to French."), ("human", "I love programming.")]
print(model.invoke(messages).content)
ChatOllama talks to the Ollama server and returns a normal LangChain AIMessage, whose .content holds the reply text. In the reference page’s own run, with the same two messages, the reply began with the French translation “J’adore le programmation.” — your reply will come from llama3.2, so the wording may differ, but it should be a French translation of “I love programming.”
Try it: three checks from install to reply
| Check | What you should see | What it means |
|---|---|---|
| Package installed | pip install -U langchain-ollama finishes without error |
The langchain_ollama package is available to import |
| Model ready | ollama pull llama3.2 reports the model is already there or downloads it |
The model name in the script matches a model Ollama has |
| Reply | python langchain_ollama_chat.py prints a French translation of “I love programming.” |
LangChain reached your local model through Ollama |
Expected result. We checked LangChain’s ChatOllama reference page, which gives the install command, the import, and the invoke example with the same two messages. We did not install langchain-ollama, pull a model, or run the script on this machine.
Limits
LangChain only wraps the call; the model still runs in Ollama, so a model that is not pulled cannot be used, and no API key is involved because the request stays on your own computer. The temperature value in the script is the reference example’s own setting, and changing it changes how varied the replies are. This guide covers one chat call only: streaming, JSON mode, and tool calling are shown on the same reference page, but they are separate tasks. We did not test any of this ourselves.
