variable does not work #5319

Closed
opened 2026-02-21 18:10:23 -05:00 by yindo · 6 comments
Owner

Originally created by @HAL9KKK on GitHub (Aug 30, 2024).

Self Checks

  • 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 (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.7.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

after adding the variable to the prompt, the result of the execution show the variable has never been taken

image

✔️ Expected Behavior

execute the flow with the expected variable

Actual Behavior

the execution show the variable data is missing

Originally created by @HAL9KKK on GitHub (Aug 30, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.7.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce after adding the variable to the prompt, the result of the execution show the variable has never been taken ![image](https://github.com/user-attachments/assets/48048573-c160-41a9-b4cc-72d8513689ea) ### ✔️ Expected Behavior execute the flow with the expected variable ### ❌ Actual Behavior the execution show the variable data is missing
yindo added the 🐞 bug label 2026-02-21 18:10:23 -05:00
yindo closed this issue 2026-02-21 18:10:23 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 30, 2024):

The issue with the variable not working in the prompt execution in Dify version 0.7.2 when self-hosted with Docker is likely due to the Ollama service not being accessible from the Docker container. This happens because localhost usually refers to the container itself, not the host machine or other containers.

To resolve this, you need to expose the Ollama service to the network by connecting to host.docker.internal instead of localhost. Replace localhost with host.docker.internal in the service configuration:

http://host.docker.internal:11434

This change should allow the variable to be correctly accessed and used during prompt execution [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 30, 2024): <!-- Answer --> The issue with the variable not working in the prompt execution in Dify version 0.7.2 when self-hosted with Docker is likely due to the Ollama service not being accessible from the Docker container. This happens because `localhost` usually refers to the container itself, not the host machine or other containers. To resolve this, you need to expose the Ollama service to the network by connecting to `host.docker.internal` instead of `localhost`. Replace `localhost` with `host.docker.internal` in the service configuration: ```bash http://host.docker.internal:11434 ``` This change should allow the variable to be correctly accessed and used during prompt execution <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/guides/model-configuration/ollama.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@HAL9KKK commented on GitHub (Aug 30, 2024):

I am not using Ollama, the LLM is based on Azure OpenAI

@HAL9KKK commented on GitHub (Aug 30, 2024): I am not using Ollama, the LLM is based on Azure OpenAI
Author
Owner

@dosubot[bot] commented on GitHub (Aug 30, 2024):

The variable might not be working in the prompt execution in Dify version 0.7.2 when using Azure OpenAI for the LLM because the context variable needs to be properly associated and inserted into the prompt.

Ensure that you are correctly calling out the variable insertion menu and inserting the required variables into the prompt. In the prompt editor, you can call out the variable insertion menu by typing "/" or "{" to insert special variable blocks or upstream node variables into the prompt as context content.

Here is an example of how to insert a context variable:

{{ context_variable_name }}

Make sure that the variable context_variable_name is correctly defined and associated in the LLM node configuration [1].

Additionally, ensure that the credentials for Azure OpenAI are correctly set up in your environment. For example, the openai_api_base, openai_api_key, and base_model_name should be properly configured:

result = model.invoke(
    model="gpt-4v",
    credentials={
        "openai_api_base": os.environ.get("AZURE_OPENAI_API_BASE"),
        "openai_api_key": os.environ.get("AZURE_OPENAI_API_KEY"),
        "base_model_name": "gpt-4-vision-preview",
    },
    prompt_messages=[
        SystemPromptMessage(
            content="You are a helpful AI assistant.",
        ),
        UserPromptMessage(
            content=[
                TextPromptMessageContent(
                    data="Hello World!",
                ),
                ImagePromptMessageContent(
                # Additional content here
                )
            ],
        ),
    ],
)

Ensure that the environment variables AZURE_OPENAI_API_BASE, AZURE_OPENAI_API_KEY, and base_model_name are correctly set and accessible in your environment [2].

Finally, if you are using the Expert Mode in Dify, you have more control over the prompt design, including the ability to modify built-in prompts, rearrange the placement of Context and History, and set necessary parameters. This mode allows for more customized prompt engineering, which might help in resolving issues related to variable insertion and context handling [3].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 30, 2024): <!-- Answer --> The variable might not be working in the prompt execution in Dify version 0.7.2 when using Azure OpenAI for the LLM because the context variable needs to be properly associated and inserted into the prompt. Ensure that you are correctly calling out the variable insertion menu and inserting the required variables into the prompt. In the prompt editor, you can call out the **variable insertion menu** by typing **"/"** or **"{"** to insert **special variable blocks** or **upstream node variables** into the prompt as context content. Here is an example of how to insert a context variable: ```jinja {{ context_variable_name }} ``` Make sure that the variable `context_variable_name` is correctly defined and associated in the LLM node configuration <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/llm.md)</sup>. Additionally, ensure that the credentials for Azure OpenAI are correctly set up in your environment. For example, the `openai_api_base`, `openai_api_key`, and `base_model_name` should be properly configured: ```py result = model.invoke( model="gpt-4v", credentials={ "openai_api_base": os.environ.get("AZURE_OPENAI_API_BASE"), "openai_api_key": os.environ.get("AZURE_OPENAI_API_KEY"), "base_model_name": "gpt-4-vision-preview", }, prompt_messages=[ SystemPromptMessage( content="You are a helpful AI assistant.", ), UserPromptMessage( content=[ TextPromptMessageContent( data="Hello World!", ), ImagePromptMessageContent( # Additional content here ) ], ), ], ) ``` Ensure that the environment variables `AZURE_OPENAI_API_BASE`, `AZURE_OPENAI_API_KEY`, and `base_model_name` are correctly set and accessible in your environment <sup>[[2]](https://github.com/langgenius/dify/blob/main/api/tests/integration_tests/model_runtime/azure_openai/test_llm.py)</sup>. Finally, if you are using the **Expert Mode** in Dify, you have more control over the prompt design, including the ability to modify built-in prompts, rearrange the placement of `Context` and `History`, and set necessary parameters. This mode allows for more customized prompt engineering, which might help in resolving issues related to variable insertion and context handling <sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-orchestrate/prompt-engineering/prompt-engineering-expert-mode.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Aug 30, 2024):

What the type of the appliation?

@crazywoola commented on GitHub (Aug 30, 2024): What the type of the appliation?
Author
Owner

@crazywoola commented on GitHub (Aug 30, 2024):

WF.yml.zip
This should solve your problem, the Google Search return things in json not in text so you will get the result as empty string.

@crazywoola commented on GitHub (Aug 30, 2024): [WF.yml.zip](https://github.com/user-attachments/files/16816068/WF.yml.zip) This should solve your problem, the Google Search return things in json not in text so you will get the result as empty string.
Author
Owner

@HAL9KKK commented on GitHub (Aug 30, 2024):

Google search return both text and json, the problem seems to be the variable in text, never appear in the prompt even thought i set it up.
I have tried to change Googlesearch tool with Wikipediasearch tool and the text output variable of wikipedia is working fine!
So the proble is related to Googlesearch tool

@HAL9KKK commented on GitHub (Aug 30, 2024): Google search return both text and json, the problem seems to be the variable in text, never appear in the prompt even thought i set it up. I have tried to change Googlesearch tool with Wikipediasearch tool and the text output variable of wikipedia is working fine! So the proble is related to Googlesearch tool
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5319