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

Dataclass coercion #2530

Open
1 task done
eyurtsev opened this issue Nov 25, 2024 · 0 comments
Open
1 task done

Dataclass coercion #2530

eyurtsev opened this issue Nov 25, 2024 · 0 comments

Comments

@eyurtsev
Copy link
Contributor

eyurtsev commented Nov 25, 2024

Privileged issue

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

Issue Content

from dataclasses import dataclass
from typing import List

@dataclass
class Foo:
    """Represents an item with an index."""
    index: int

@dataclass
class State:
    foos: List[Foo]

def map_to_node(state: State):
    """Prepare all items in the state for processing."""
    return [describe_foo(foo) for foo in state.foos]

def describe_foo(foo: Foo): # <-- foo is a DICT here instead of a dataclass
    """Raise a TypeError if foo is not a dataclass instance."""
    raise TypeError(f"Expected Foo, got {type(foo).__name__}")  # Assume foo is a dict

System Information

OS: Linux
OS Version: #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2
Python Version: 3.11.4 (main, Sep 25 2023, 10:06:23) [GCC 11.4.0]

Package Information

langchain_core: 0.3.19
langsmith: 0.1.144
langchain_openai: 0.2.9
langgraph: 0.2.53

Optional packages not installed

langserve

Other Dependencies

httpx: 0.27.2
jsonpatch: 1.33
langgraph-checkpoint: 2.0.5
langgraph-sdk: 0.1.36
openai: 1.55.0
orjson: 3.10.11
packaging: 24.2
pydantic: 2.10.0
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.12.2

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