Dify - Workflow Variable Binding

Site: dify|https://dify.ai/

Get plain text:

curl -H "Accept: text/plain" https://jugoya.ai/guides/dify/variable-binding

Overview

Guide for configuring Dify workflow variables correctly for API access.

Adding Input Variables to START Node

  1. Click the START node (User Input) in the workflow
  2. In the settings panel, find "Input Field" section
  3. Click the "+" button to add a new field
  4. Configure the field:
    • Field Type: Short Text (for string inputs)
    • Variable Name: e.g., query
    • Label Name: e.g., query
    • Required: Enable if the field is mandatory
  5. Click "Save"

The START node label will update to show the new variable (e.g., "START User Input query required").

Using Variables in LLM Node

Important: Do NOT manually type variable syntax like {{query}}. This will be treated as literal text.

Correct Method

  1. Click the LLM node to open settings
  2. In the USER message textbox, type { (single curly brace)
  3. A variable picker dropdown will appear showing:
    • User Input variables (e.g., query)
    • SYSTEM variables (user_id, app_id, etc.)
  4. Click the desired variable (e.g., "query" under User Input)
  5. The variable will be inserted as a proper reference

Common Mistake

  • Typing {{query}} or {{#sys.query#}} manually
  • These are NOT recognized as variable references
  • The LLM will receive the literal text instead of the resolved value

Configuring Output Node Variables

  1. Click the Output node
  2. Find "Set variable" section
  3. Click the "+" button to add a variable slot
  4. Click the text area (not the trash icon on the right)
  5. A "Search variable" dropdown appears with autocomplete
  6. Select the source variable (e.g., LLM → text)
  7. The variable name will be set automatically

API Request Format

After publishing, call the workflow API:

POST /v1/workflows/run
Headers:
  Authorization: Bearer {API_KEY}
  Content-Type: application/json

Body:
{
  "inputs": {"query": "your question here"},
  "response_mode": "blocking",
  "user": "user-id"
}

The inputs object keys must match the variable names defined in the START node.

Troubleshooting

SymptomCauseSolution
LLM receives literal {{query}}Manual text entryUse variable picker with { trigger
API returns "variable not found"Missing START node variableAdd input field in START node settings
Output is emptyOutput variable not configuredSelect LLM/text in Output node