Skip to content

issue-4: added validation func, test case, updated README - #87

Open
AnimeshRajwar wants to merge 2 commits into
CodeGraphContext:mainfrom
AnimeshRajwar:issue-4
Open

issue-4: added validation func, test case, updated README#87
AnimeshRajwar wants to merge 2 commits into
CodeGraphContext:mainfrom
AnimeshRajwar:issue-4

Conversation

@AnimeshRajwar

Copy link
Copy Markdown

Closes #4

added:

  • validation func
  • test case
  • updated README
ss

the error raised on unknown node, mentions source and bad node.

@AnimeshRajwar

Copy link
Copy Markdown
Author

@Shashankss1205

@Shashankss1205

Copy link
Copy Markdown
Collaborator

Thanks for this — the intent is right, and #4 is a real gap. But as written this PR removes two guarantees that are currently in main, so I can't merge it in this shape. Both are concrete and both are testable.

1. It deletes the runtime safety net.

-        self._check_mapping(source, router, mapping)
-        self._graph.add_conditional_edges(
-            source, self._checked_router(source, router, mapping), mapping
-        )
+        self._validate_conditional_edge(source, router, mapping)
+        self._graph.add_conditional_edges(source, router, mapping)

_checked_router is what turns a router returning an unmapped key into GraphRoutingError naming the node, the key and the keys that existed, instead of a bare KeyError out of LangGraph's branch machinery. Declaration-time validation cannot replace it: a router that declares no return annotation is only known when it returns something. The README change in this PR deletes that documented guarantee too, which is the tell — the sentence had to go because the behaviour did.

2. The Literal check silently never fires.

_validate_conditional_edge reads inspect.signature(router).return_annotation. Under from __future__ import annotations — which grapharc/runtime/graph.py itself uses, and which is increasingly the default in user code — annotations are strings at runtime:

from __future__ import annotations
import inspect
from typing import Literal, get_origin, get_type_hints

def router(state) -> Literal["a", "b"]: ...

inspect.signature(router).return_annotation   # "Literal['a', 'b']"  -> get_origin(...) is Literal: False
get_type_hints(router).get("return")          # typing.Literal['a', 'b'] -> get_origin(...) is Literal: True

So the Literal/Enum arm falls through to return and validates nothing. main uses get_type_hints at graph.py:303 for exactly this reason.

3. The declaration-time checks already exist. _check_mapping (graph.py:536) already refuses an empty mapping and a target that is neither a node nor END.

The PR is also DIRTY against current main.

What would land happily: the test file. tests/test_add_conditional_edge.py pins behaviour that is worth pinning, and if there is a case in it that _check_mapping does not already cover, that is the actual bug in #4 and I would very much like the failing case. Could you rebase on main, drop the graph.py and README.md changes, and keep the tests? If one of them fails against main, that is the fix worth making — and I will take it.

🤖 Generated with Claude Code

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

Successfully merging this pull request may close these issues.

runtime: validate conditional-edge mappings when the edge is added, not mid-run

2 participants