[GH-ISSUE #1320] [langgraph]: Printing the wrong message !! #191

Closed
opened 2026-02-17 17:19:22 -05:00 by yindo · 1 comment
Owner

Originally created by @SijanMahmudAI on GitHub (Nov 6, 2025).
Original GitHub issue: https://github.com/langchain-ai/docs/issues/1320

Type of issue

issue / bug

Language

Python

Description

If you follow this link: https://docs.langchain.com/oss/python/langgraph/workflows-agents

You have to go to the "Prompt chaining" section , then you will find this Graph API code :

from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END
from IPython.display import Image, display


# Graph state
class State(TypedDict):
    topic: str
    joke: str
    improved_joke: str
    final_joke: str


# Nodes
def generate_joke(state: State):
    """First LLM call to generate initial joke"""

    msg = llm.invoke(f"Write a short joke about {state['topic']}")
    return {"joke": msg.content}


def check_punchline(state: State):
    """Gate function to check if the joke has a punchline"""

    # Simple check - does the joke contain "?" or "!"
    if "?" in state["joke"] or "!" in state["joke"]:
        return "Pass"
    return "Fail"


def improve_joke(state: State):
    """Second LLM call to improve the joke"""

    msg = llm.invoke(f"Make this joke funnier by adding wordplay: {state['joke']}")
    return {"improved_joke": msg.content}


def polish_joke(state: State):
    """Third LLM call for final polish"""
    msg = llm.invoke(f"Add a surprising twist to this joke: {state['improved_joke']}")
    return {"final_joke": msg.content}


# Build workflow
workflow = StateGraph(State)

# Add nodes
workflow.add_node("generate_joke", generate_joke)
workflow.add_node("improve_joke", improve_joke)
workflow.add_node("polish_joke", polish_joke)

# Add edges to connect nodes
workflow.add_edge(START, "generate_joke")
workflow.add_conditional_edges(
    "generate_joke", check_punchline, {"Fail": "improve_joke", "Pass": END}
)
workflow.add_edge("improve_joke", "polish_joke")
workflow.add_edge("polish_joke", END)

# Compile
chain = workflow.compile()

# Show workflow
display(Image(chain.get_graph().draw_mermaid_png()))

# Invoke
state = chain.invoke({"topic": "cats"})
print("Initial joke:")
print(state["joke"])
print("\n--- --- ---\n")
if "improved_joke" in state:
    print("Improved joke:")
    print(state["improved_joke"])
    print("\n--- --- ---\n")

    print("Final joke:")
    print(state["final_joke"])
else:
    print("Joke failed quality gate - no punchline detected!")

In the last line, the code is printing -> "Joke failed quality gate - no punchline detected!".
But it should be the opposite .
The code should be printing -> "Joke Passed the quality gate - punchline is detected."

Originally created by @SijanMahmudAI on GitHub (Nov 6, 2025). Original GitHub issue: https://github.com/langchain-ai/docs/issues/1320 ### Type of issue issue / bug ### Language Python ### Description If you follow this link: https://docs.langchain.com/oss/python/langgraph/workflows-agents You have to go to the "Prompt chaining" section , then you will find this Graph API code : ```python from typing_extensions import TypedDict from langgraph.graph import StateGraph, START, END from IPython.display import Image, display # Graph state class State(TypedDict): topic: str joke: str improved_joke: str final_joke: str # Nodes def generate_joke(state: State): """First LLM call to generate initial joke""" msg = llm.invoke(f"Write a short joke about {state['topic']}") return {"joke": msg.content} def check_punchline(state: State): """Gate function to check if the joke has a punchline""" # Simple check - does the joke contain "?" or "!" if "?" in state["joke"] or "!" in state["joke"]: return "Pass" return "Fail" def improve_joke(state: State): """Second LLM call to improve the joke""" msg = llm.invoke(f"Make this joke funnier by adding wordplay: {state['joke']}") return {"improved_joke": msg.content} def polish_joke(state: State): """Third LLM call for final polish""" msg = llm.invoke(f"Add a surprising twist to this joke: {state['improved_joke']}") return {"final_joke": msg.content} # Build workflow workflow = StateGraph(State) # Add nodes workflow.add_node("generate_joke", generate_joke) workflow.add_node("improve_joke", improve_joke) workflow.add_node("polish_joke", polish_joke) # Add edges to connect nodes workflow.add_edge(START, "generate_joke") workflow.add_conditional_edges( "generate_joke", check_punchline, {"Fail": "improve_joke", "Pass": END} ) workflow.add_edge("improve_joke", "polish_joke") workflow.add_edge("polish_joke", END) # Compile chain = workflow.compile() # Show workflow display(Image(chain.get_graph().draw_mermaid_png())) # Invoke state = chain.invoke({"topic": "cats"}) print("Initial joke:") print(state["joke"]) print("\n--- --- ---\n") if "improved_joke" in state: print("Improved joke:") print(state["improved_joke"]) print("\n--- --- ---\n") print("Final joke:") print(state["final_joke"]) else: print("Joke failed quality gate - no punchline detected!") ``` In the last line, the code is printing -> "Joke failed quality gate - no punchline detected!". But it should be the opposite . The code should be printing -> "Joke Passed the quality gate - punchline is detected."
yindo added the langgraph label 2026-02-17 17:19:22 -05:00
yindo closed this issue 2026-02-17 17:19:22 -05:00
Author
Owner

@BenHavis commented on GitHub (Nov 11, 2025):

I can take a look at this if helpful. The final printed message does not appear to match the workflow behavior, since jokes that pass the punchline check skip the improvement step and trigger that message. Let me know if a PR would be useful, I'd be happy to update.

@BenHavis commented on GitHub (Nov 11, 2025): I can take a look at this if helpful. The final printed message does not appear to match the workflow behavior, since jokes that pass the punchline check skip the improvement step and trigger that message. Let me know if a PR would be useful, I'd be happy to update.
yindo changed title from [langgraph]: Printing the wrong message !! to [GH-ISSUE #1320] [langgraph]: Printing the wrong message !! 2026-06-05 17:25:33 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/docs#191