Skip to content

Instantly share code, notes, and snippets.

@bgriffi
bgriffi / reasoning_with_structured_output_langchain.py
Created September 26, 2025 14:34 — forked from Andrey862/reasoning_with_structured_output_langchain.py
Example of using reasoning model with structured output with langchain
# ollama library version here: https://gist.github.com/Andrey862/94c5760d79fe3674f4294a26bab5fdfb
from typing import cast
from langchain_core.messages.ai import AIMessage
from langchain_core.messages.base import BaseMessage
from langchain_core.messages.system import SystemMessage
from langchain_ollama.chat_models import ChatOllama
from pydantic import BaseModel
model = ChatOllama(model="qwen3:8b", temperature=0.1, top_k=2)