langchain-ai/langgraph · error · TypeError
Expected `model` to be a ChatModel or RunnableBinding (e.g…
Error message
Expected `model` to be a ChatModel or RunnableBinding (e.g. model.bind_tools(...)), got {type} What it means
Raised by _get_model() when the object passed as `model` to create_react_agent, after unwrapping RunnableBinding/RunnableSequence, is still not a BaseChatModel. The agent requires an actual chat model to bind tools to; passing a plain string, an arbitrary Runnable, or a non-chat wrapper triggers this guard.
Solutions
- Pass a chat model instance, e.g. `init_chat_model("openai:gpt-4o")` or `ChatOpenAI(model="gpt-4o")`
- If binding tools, pass `model.bind_tools(tools)` so the value is a RunnableBinding around a BaseChatModel
- If using a RunnableSequence, include the BaseChatModel step so it can be extracted
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py:236 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of langchain-ai/langgraph@38031739e5 (2026-08-26).
Data as JSON: /api/errors/c3d661465be917e5.
Report an issue: GitHub.
Appendix: source
Thrown at libs/prebuilt/langgraph/prebuilt/chat_agent_executor.py:236
def _get_model(model: LanguageModelLike) -> BaseChatModel:
"""Get the underlying model from a RunnableBinding or return the model itself."""
if isinstance(model, RunnableSequence):
model = next(
(
step
for step in model.steps
if isinstance(step, (RunnableBinding, BaseChatModel))
),
model,
)
if isinstance(model, RunnableBinding):
model = model.bound
if not isinstance(model, BaseChatModel):
raise TypeError(
f"Expected `model` to be a ChatModel or RunnableBinding (e.g. model.bind_tools(...)), got {type(model)}"
)
return model
def _validate_chat_history(
messages: Sequence[BaseMessage],
) -> None:
"""Validate that all tool calls in AIMessages have a corresponding ToolMessage."""
all_tool_calls = [
tool_call
for message in messages
if isinstance(message, AIMessage)
for tool_call in message.tool_calls
]
tool_call_ids_with_results = {
message.tool_call_id for message in messages if isinstance(message, ToolMessage)View on GitHub (pinned to 38031739e5)