Skip to content

Snippet-inserted nodes get hyphenated IDs that the variable template regex cannot parse, so {{#nodeId.var#}} is sent to the LLM unsubstituted #43830

Closed

Description

@ligangya1314521-ux

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.17.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. Create a workflow; add a Document Extractor node and an LLM node by inserting a Snippet (not by dragging from the block panel).
  2. In the LLM system prompt, insert the extractor's text variable via the picker. The saved prompt contains {{#.text#}} where looks like 1791619342702-1791622662711-1.
  3. Run the workflow with any file.

✔️ Expected Behavior

the LLM receives the extracted text.

❌ Actual Behavior

the LLM receives the literal placeholder {{#1791619342702-1791622662711-1.text#}} and replies that it cannot read the content.

Image

Root cause:

  • web/app/components/workflow/block-selector/snippets/use-insert-snippet.ts (remapSnippetGraph) generates node IDs as ${node.id}-${Date.now()}-${index} — containing hyphens, unlike panel-created nodes which use pure ${Date.now()}.
  • The runtime template parser VARIABLE_PATTERN = r"{{#([a-zA-Z0-9_]{1,50}(?:.[a-zA-Z_][a-zA-Z0-9_]{0,29}){1,10})#}}" (core/prompt/utils/prompt_template_parser.py, and graphon.variables.template_resolution.convert_template used by the LLM node) only allows [a-zA-Z0-9_] in the node-ID segment, so hyphenated selectors never match and are passed through as plain text.

Minimal repro (backend):
VARIABLE_PATTERN.search("{{#1791619342702.text#}}") # matches
VARIABLE_PATTERN.search("{{#1791619342702-1791622662711-1.text#}}") # None → not substituted

Suggested fix (either or both):

  1. Generate hyphen-free IDs in use-insert-snippet.ts (e.g. ${Date.now()}${index}, keeping the existing collision loop but appending digits instead of -1).
  2. Widen the node-ID character class to [a-zA-Z0-9_-]{1,50} in the template regexes (note: several independent copies exist — prompt_template_parser, app_config variables manager, rag_pipeline, workflow generator).

Activity

  1. added
    🐞 bug
    on Oct 10, 2026
  2. added
    review: low
    on Oct 10, 2026
  3. dosubot commented on Oct 10, 2026

    @dosubot

    Hi @ligangya1314521-ux! I'm Dosu and I'm helping the Dify team.

    Your root cause matches the code. remapSnippetGraph builds each new ID as ${node.id}-${Date.now()}-${index}, and on a collision it appends -1 repeatedly, which adds more hyphens (use-insert-snippet.ts). The backend template patterns accept only [a-zA-Z0-9_] in the node-ID segment, for example the workflow variable reference validator and the app config variables manager. Dify's notes on variable resolution describe the same failure: hyphenated node IDs pass through unsubstituted as raw text.

    Fix 1 (hyphen-free IDs in the snippet insert path) looks preferable to widening the regex, for three reasons:

    • The workflow generator already treats [a-zA-Z0-9_] as the required ID format. Its comments say a hyphenated ID like node-1 does not match at run time, so the placeholder reaches the LLM prompt literally, and it rewrites hyphenated IDs defensively (runner.py).
    • The node-ID character class is copied in several places, such as WITH_VARIABLE_TMPL_REGEX in prompt_template_parser.py, plus the rag_pipeline and generator files. Widening all of them consistently is a larger, riskier change.
    • The ${nextId}-1 collision fallback must also change to append digits or an underscore, or it will reintroduce hyphens.

    A frontend-only fix will not repair nodes already inserted, since those keep their hyphenated IDs in the saved graph. I found no documented way to rename them. A likely (unverified) workaround is to re-add the affected nodes from the block panel and re-pick the variables.

    I did not read the graphon convert_template implementation because it lives in an external package, so I'm relying on your report that it uses the same pattern.

    To reply, just mention @dosu.


    Docs are dead. Just use Dosu.

    Leave Feedback Ask Dosu about dify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    review: low🐞 bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions