Skip to content

fix(nodes): keep every key of an AND group in parentheses - #1161

Open
MohammadHijjawi97 wants to merge 1 commit into
ScrapeGraphAI:pre/betafrom
MohammadHijjawi97:fix/input-keys-and-in-parentheses
Open

MohammadHijjawi97 wants to merge 1 commit into
ScrapeGraphAI:pre/betafrom
MohammadHijjawi97:fix/input-keys-and-in-parentheses

Conversation

@MohammadHijjawi97

Copy link
Copy Markdown

Summary

Node input expressions are resolved by BaseNode._parse_input_keys: parenthesised groups are evaluated first, and their keys are spliced back into the expression. The keys were joined with |, which turns an AND group into an OR, so required keys are silently dropped:

state = {"a": 1, "b": 2, "c": 3}
# input="a & (b & c)"  -> before: ['a', 'b']   after: ['a', 'b', 'c']
# input="(a & b) & c"  -> before: ['a']        after: ['a', 'b', 'c']
# input="(a & b) | c"  -> before: ['a']        after: ['a', 'b']

Changes

  • Join the keys of an evaluated group with &, so they remain required together. Groups that resolve to a single key behave exactly as before, e.g. user_prompt & (relevant_chunks | parsed_doc | doc) used by the built-in graphs.
  • The standalone utils.parse_state_keys.parse_expression helper duplicates this logic, so it gets the same one-line fix.
  • Added tests/nodes/base_node_test.py and a case in tests/utils/parse_state_keys_test.py.

Testing

  • pytest tests/nodes/base_node_test.py tests/utils/parse_state_keys_test.py: 4 of the new cases fail on pre/beta, and all 6 pass with the fix.
  • pytest tests/graphs/abstract_graph_test.py: 24 passed. test_llm_missing_tokens fails identically on unmodified pre/beta and is unrelated.
  • ruff check on the changed files; black --check / isort --check-only on the test files.

When a node input expression contains a parenthesised group, the group
is evaluated first and its result is spliced back into the expression.
The keys were joined with "|", which turns an AND group into an OR:
"a & (b & c)" became "a&b|c" and resolved to ["a", "b"], and
"(a & b) & c" resolved to just ["a"], so required keys were silently
dropped from the node's input.

Join the group's keys with "&" so they stay required together. Groups
that resolve to a single key (all built-in graph inputs) are unaffected.
The same fix is applied to the standalone parse_expression helper.

This branch has not been deployed

No deployments
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.

1 participant