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

Using Pydantic state with aliased fields #2555

Open
1 task done
eyurtsev opened this issue Nov 27, 2024 · 1 comment
Open
1 task done

Using Pydantic state with aliased fields #2555

eyurtsev opened this issue Nov 27, 2024 · 1 comment

Comments

@eyurtsev
Copy link
Contributor

Privileged issue

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

Issue Content

MRE

from pydantic import BaseModel, Field
from langgraph.graph import StateGraph

class Foo(BaseModel):
    foo: str = Field(alias='bar')

# Define a new graph
graph_builder = StateGraph(
    Foo
)


def node(foo: Foo):
    print(foo)
    return None

# Add the node to the graph
graph_builder.add_node("node", node)
# Set the entrypoint as `call_model`
graph_builder.add_edge("__start__", "node")

# Compile the workflow into an executable graph
graph = graph_builder.compile()


graph.invoke({'bar': 'hello'})

Expected behavior

The alias should be respected and the field foo should be only updateable by alias.

Observed behavior

Validation error.

Context

  • Mostly a problem for IO boundaries (since that's where I actually use pydantic models)
  • alias is needed in some cases to avoid name collisions (e.g., schema field is already taken by pydantic)
@FrancisGajitos
Copy link

Hi @eyurtsev,

I've looked into the issue and I'm interested in working on fixing it right away. Please let me know if there's anything further I should know about it.

Thanks!

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

2 participants