Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surprising results when using pydantic for state schema #1977

Open
1 task done
eyurtsev opened this issue Oct 2, 2024 · 0 comments
Open
1 task done

Surprising results when using pydantic for state schema #1977

eyurtsev opened this issue Oct 2, 2024 · 0 comments

Comments

@eyurtsev
Copy link
Contributor

eyurtsev commented Oct 2, 2024

Privileged issue

  • I am a LangChain maintainer, or was asked directly by a LangChain maintainer to create an issue here.

Issue Content

Run time validation with pydantic schema does not work with output schema.

from langgraph.graph import StateGraph, START, END
from typing_extensions import TypedDict

from pydantic import BaseModel

# The overall state of the graph (this is the public state shared across nodes)
class OverallState(BaseModel):
    a: float

def node_1(state: OverallState) -> OverallState:
    return {
        "a": "foo"
    }

# Build the state graph
builder = StateGraph(OverallState, output=OverallState)
builder.add_node(node_1)  # node_1 is the first node
builder.add_edge(START, "node_1")  # Start the graph with node_1
builder.add_edge("node_1", END)  # End the graph after node_1
graph = builder.compile()

graph.invoke(
    {
        "a": 2.3
    }
)

Result

{'a': 'foo'}

This result does not match the output schema!

Expected

Expected a validation error

@eyurtsev eyurtsev changed the title Surprising results when using pydantic for state Surprising results when using pydantic for output state Oct 2, 2024
@eyurtsev eyurtsev changed the title Surprising results when using pydantic for output state Surprising results when using pydantic for state (output is not a pydantic instance) Oct 2, 2024
@eyurtsev eyurtsev changed the title Surprising results when using pydantic for state (output is not a pydantic instance) Surprising results when using pydantic for state schema Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant