langchain - 💡(How to fix) Fix A bug in learn-langgraph-SQL-agent

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Subject: SQL Agent docs: interrupt branch is unreachable with stream_mode="values" because messages is present in interrupt step

Hi LangGraph team,

I think there may be an issue in the SQL agent tutorial code here:

https://docs.langchain.com/oss/python/langgraph/sql-agent#4-define-application-steps

The current example uses:

for step in agent.stream(
    {"messages": [{"role": "user", "content": question}]},
    config,
    stream_mode="values",
):
    if "messages" in step:
        step["messages"][-1].pretty_print()
    elif "__interrupt__" in step:
        action = step["__interrupt__"][0]
        print("INTERRUPTED:")
        for request in action.value:
            print(json.dumps(request, indent=2))
    else:
        pass

However, in my local run, when the graph reaches the interrupt, the streamed step contains both messages and __interrupt__:

{
    "messages": [...],
    "__interrupt__": (
        Interrupt(
            value=[
                {
                    "action": "sql_db_query",
                    "args": {"query": "SELECT ..."},
                    "description": "Please review the tool call"
                }
            ],
            id="..."
        ),
    )
}

Because messages is present, the first branch always runs:

if "messages" in step:

As a result, the elif "__interrupt__" in step: branch is never reached, and the tutorial does not print the expected:

INTERRUPTED:
{
  "action": "sql_db_query",
  "args": {
    "query": "..."
  },
  "description": "Please review the tool call"
}

A more robust version would be to check for __interrupt__ first:

for step in agent.stream(
    {"messages": [{"role": "user", "content": question}]},
    config,
    stream_mode="values",
):
    if "__interrupt__" in step:
        action = step["__interrupt__"][0]
        print("INTERRUPTED:")
        for request in action.value:
            print(json.dumps(request, indent=2))
        break

    if "messages" in step:
        step["messages"][-1].pretty_print()

Or alternatively track newly added messages, since stream_mode="values" returns the current full state and messages may be present even when the important event is an interrupt.

Environment notes:

stream_mode="values"
LangGraph SQL agent tutorial
Local model changed to DeepSeek, but the issue appears to be about the streamed step structure rather than model output.

Please let me know if this is expected behavior or if the documentation example should be updated.

Error Message

Error Message and Stack Trace (if applicable)

Root Cause

Subject: SQL Agent docs: interrupt branch is unreachable with stream_mode="values" because messages is present in interrupt step

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Other Dependencies

aiohttp: 3.13.5 dataclasses-json: 0.6.7 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.1.10 numpy: 2.4.3 openai: 2.35.1 orjson: 3.11.9 packaging: 26.0 pydantic: 2.13.2 pydantic-settings: 2.14.0 pyyaml: 6.0.3 PyYAML: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 SQLAlchemy: 2.0.49 sqlalchemy: 2.0.49 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 xxhash: 3.7.0 zstandard: 0.25.0

Code Example

import json

config = {"configurable": {"thread_id": "1"}}

question = "Which genre on average has the longest tracks?"

for step in agent.stream(
    {"messages": [{"role": "user", "content": question}]},
    config,
    stream_mode="values",
):
    if "messages" in step:
        step["messages"][-1].pretty_print()
    elif "__interrupt__" in step:
        action = step["__interrupt__"][0]
        print("INTERRUPTED:")
        for request in action.value:
            print(json.dumps(request, indent=2))
    else:
        pass

---



---

for step in agent.stream(
    {"messages": [{"role": "user", "content": question}]},
    config,
    stream_mode="values",
):
    if "messages" in step:
        step["messages"][-1].pretty_print()
    elif "__interrupt__" in step:
        action = step["__interrupt__"][0]
        print("INTERRUPTED:")
        for request in action.value:
            print(json.dumps(request, indent=2))
    else:
        pass

---

{
    "messages": [...],
    "__interrupt__": (
        Interrupt(
            value=[
                {
                    "action": "sql_db_query",
                    "args": {"query": "SELECT ..."},
                    "description": "Please review the tool call"
                }
            ],
            id="..."
        ),
    )
}

---

if "messages" in step:

---

INTERRUPTED:
{
  "action": "sql_db_query",
  "args": {
    "query": "..."
  },
  "description": "Please review the tool call"
}

---

for step in agent.stream(
    {"messages": [{"role": "user", "content": question}]},
    config,
    stream_mode="values",
):
    if "__interrupt__" in step:
        action = step["__interrupt__"][0]
        print("INTERRUPTED:")
        for request in action.value:
            print(json.dumps(request, indent=2))
        break

    if "messages" in step:
        step["messages"][-1].pretty_print()

---

stream_mode="values"
LangGraph SQL agent tutorial
Local model changed to DeepSeek, but the issue appears to be about the streamed step structure rather than model output.
RAW_BUFFERClick to expand / collapse

Submission checklist

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

No response

Reproduction Steps / Example Code (Python)

import json

config = {"configurable": {"thread_id": "1"}}

question = "Which genre on average has the longest tracks?"

for step in agent.stream(
    {"messages": [{"role": "user", "content": question}]},
    config,
    stream_mode="values",
):
    if "messages" in step:
        step["messages"][-1].pretty_print()
    elif "__interrupt__" in step:
        action = step["__interrupt__"][0]
        print("INTERRUPTED:")
        for request in action.value:
            print(json.dumps(request, indent=2))
    else:
        pass

Error Message and Stack Trace (if applicable)

Description

Subject: SQL Agent docs: interrupt branch is unreachable with stream_mode="values" because messages is present in interrupt step

Hi LangGraph team,

I think there may be an issue in the SQL agent tutorial code here:

https://docs.langchain.com/oss/python/langgraph/sql-agent#4-define-application-steps

The current example uses:

for step in agent.stream(
    {"messages": [{"role": "user", "content": question}]},
    config,
    stream_mode="values",
):
    if "messages" in step:
        step["messages"][-1].pretty_print()
    elif "__interrupt__" in step:
        action = step["__interrupt__"][0]
        print("INTERRUPTED:")
        for request in action.value:
            print(json.dumps(request, indent=2))
    else:
        pass

However, in my local run, when the graph reaches the interrupt, the streamed step contains both messages and __interrupt__:

{
    "messages": [...],
    "__interrupt__": (
        Interrupt(
            value=[
                {
                    "action": "sql_db_query",
                    "args": {"query": "SELECT ..."},
                    "description": "Please review the tool call"
                }
            ],
            id="..."
        ),
    )
}

Because messages is present, the first branch always runs:

if "messages" in step:

As a result, the elif "__interrupt__" in step: branch is never reached, and the tutorial does not print the expected:

INTERRUPTED:
{
  "action": "sql_db_query",
  "args": {
    "query": "..."
  },
  "description": "Please review the tool call"
}

A more robust version would be to check for __interrupt__ first:

for step in agent.stream(
    {"messages": [{"role": "user", "content": question}]},
    config,
    stream_mode="values",
):
    if "__interrupt__" in step:
        action = step["__interrupt__"][0]
        print("INTERRUPTED:")
        for request in action.value:
            print(json.dumps(request, indent=2))
        break

    if "messages" in step:
        step["messages"][-1].pretty_print()

Or alternatively track newly added messages, since stream_mode="values" returns the current full state and messages may be present even when the important event is an interrupt.

Environment notes:

stream_mode="values"
LangGraph SQL agent tutorial
Local model changed to DeepSeek, but the issue appears to be about the streamed step structure rather than model output.

Please let me know if this is expected behavior or if the documentation example should be updated.

System Info

System Information

OS: Windows OS Version: 10.0.26200 Python Version: 3.13.13 | packaged by conda-forge | (main, Apr 8 2026, 01:56:49) [MSC v.1944 64 bit (AMD64)]

Package Information

langchain_core: 1.3.3 langchain: 1.2.17 langchain_community: 0.4.1 langsmith: 0.8.2 langchain_classic: 1.0.7 langchain_deepseek: 1.0.1 langchain_openai: 1.2.1 langchain_protocol: 0.0.15 langchain_text_splitters: 1.1.2 langgraph_sdk: 0.3.14

Optional packages not installed

deepagents deepagents-cli

Other Dependencies

aiohttp: 3.13.5 dataclasses-json: 0.6.7 httpx: 0.28.1 httpx-sse: 0.4.3 jsonpatch: 1.33 langgraph: 1.1.10 numpy: 2.4.3 openai: 2.35.1 orjson: 3.11.9 packaging: 26.0 pydantic: 2.13.2 pydantic-settings: 2.14.0 pyyaml: 6.0.3 PyYAML: 6.0.3 requests: 2.32.5 requests-toolbelt: 1.0.0 SQLAlchemy: 2.0.49 sqlalchemy: 2.0.49 tenacity: 9.1.4 tiktoken: 0.12.0 typing-extensions: 4.15.0 uuid-utils: 0.14.1 xxhash: 3.7.0 zstandard: 0.25.0

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - 💡(How to fix) Fix A bug in learn-langgraph-SQL-agent