dify icon indicating copy to clipboard operation
dify copied to clipboard

Parameter extraction node error: Invalid number of parameters

Open CrabSAMA opened this issue 1 month ago • 2 comments

Self Checks

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

Dify version

1.9.2

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. add parameter extraction node
  2. prompt add some enum will increase bug reproduce probability
  3. run workflow will face the question

reproduce.yml

Also can refer this DSL.

✔️ Expected Behavior

Parameter extract success.

❌ Actual Behavior

Parameter extraction node output: Invalid number of parameters

{
  "__is_success": 0,
  "__reason": "Invalid number of parameters",
  "__usage": {
    "prompt_tokens": 508,
    "prompt_unit_price": "0",
    "prompt_price_unit": "0",
    "prompt_price": "0",
    "completion_tokens": 589,
    "completion_unit_price": "0",
    "completion_price_unit": "0",
    "completion_price": "0",
    "total_tokens": 1097,
    "total_price": "0",
    "currency": "USD",
    "latency": 28.06555001193192
  },
  "car": [],
  "area": ""
}

CrabSAMA avatar Nov 14 '25 10:11 CrabSAMA

The "Invalid number of parameters" error in the parameter extraction node happens when the number of parameters extracted doesn't match the number defined in the node configuration. This is enforced by the validation logic in the code, which compares the expected and actual parameter counts and raises this error if they differ. Enum (select) parameters are also validated to ensure their values match allowed options, and any mismatch or missing required parameter can trigger this error as well. This issue is more likely when using enums in prompts, as the extraction process may not always return the expected structure or count of parameters, especially if the prompt or model output is ambiguous or incomplete. You can review the relevant validation logic here.

Recent pull requests have addressed related bugs in parameter extraction, including fixes for prompt template handling and configuration access, but there is no direct fix for this specific error in v1.9.2. If you are able to upgrade, newer versions may include improvements in prompt handling and parameter extraction reliability. For now, double-check that your enum parameter definitions and prompts are clear and match the expected schema, and ensure the model output includes all required parameters with valid enum values.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Nov 14 '25 10:11 dosubot[bot]

@dosu Here is my research:

this line actually incorrect: https://github.com/langgenius/dify/blob/9843fec3931ba791b09a3805e44fbe6636191996/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py#L543

If parameter extraction node have some non-required parameter, because of result field is extract by model, and prompt did not have any handler about non-required parameter, so len(result) length is likely that it will not be equal to len(data.parameters), InvalidNumberOfParametersError will have high probability raise.


Additionally, I found another issue that can also cause this error. _extract_complete_json_response maybe also have some bug: https://github.com/langgenius/dify/blob/9843fec3931ba791b09a3805e44fbe6636191996/api/core/workflow/nodes/parameter_extractor/parameter_extractor_node.py#L654-L667

For example, if reasoning model return thinking text have some json text, or normal model return text have some json unrelated to the final result, _extract_complete_json_response just extract the first json data, IMO it will cause some problem. It also will cause InvalidNumberOfParametersError.

We can compare success and fail log:

fail:

prompt:
<think>\n\nIn this task, I need to extract specific information from the text and format it according to the given JSON structure. Let me analyze what's required:\n\nThe JSON structure has:\n1. `driver_vehicle_type_list`: An array of strings representing the driver's vehicle types\n2. `big_area`: A string representing the business area\n\nThe instructions specify:\n- Driver vehicle type enum values: 微面包车,小面包车,中面包车,微货车,小货车,中货车,3米8\n- Business area enum values: 华南,华东,华北,华中,西南,东北\n- If multiple areas, separate with commas\n- If multiple vehicle types, split into multiple elements in the list\n- If vehicle type not explicitly specified, default to all enum values\n\nThe text provided is empty: `<text></text>`\n\nSince there's no text to analyze:\n1. There's no specified driver vehicle type, so according to the requirements, I should default to all enum values: [\"微面包车\", \"小面包车\", \"中面包车\", \"微货车\", \"小货车\", \"中货车\", \"3米8\"]\n2. There's no specified business area, so this should be an empty string\n\nLet me create the JSON object accordingly.\n</think>\n```json\n{\n  \"driver_vehicle_type_list\": [\"微面包车\", \"小面包车\", \"中面包车\", \"微货车\", \"小货车\", \"中货车\", \"3米8\"],\n  \"big_area\": \"\"\n}\n```

2025-11-07 08:36:56,17 INFO [_client.py:1038] f417761346 HTTP Request: POST http://127.0.0.1:5002/plugin/b7df5634-8029-4c6d-969f-c39e9f7ae646/dispatch/llm/invoke "HTTP/1.1 200 OK"
json_str: ["微面包车", "小面包车", "中面包车", "微货车", "小货车", "中货车", "3米8"]
result: ['微面包车', '小面包车', '中面包车', '微货车', '小货车', '中货车', '3米8']
data: title='参数提取器' desc=None version='1' error_strategy=None default_value=None retry_config=RetryConfig(max_retries=0, retry_interval=0, retry_enabled=False) model=ModelConfig(provider='langgenius/zhipuai/zhipuai', name='glm-4.5-flash', mode=<LLMMode.CHAT: 'chat'>, completion_params={'temperature': 0.7}) query=[] parameters=[ParameterConfig(name='big_area', type=<SegmentType.STRING: 'string'>, options=None, description='业务大区', required=False), ParameterConfig(name='driver_vehicle_type_list', type=<SegmentType.ARRAY_STRING: 'array[string]'>, options=None, description='司机的汽车类型列表', required=True)] instruction='司机的汽车类型名称枚举值为:微面包车,小面包车,中面包车,微货车,小货车,中货车,3米8\n业务大区的枚举值为:华南,华东,华北,华中,西南,东北\n请根据用户输入问题,精准匹配以上枚举,抽取出对应的司机汽车类型,业务大区参数。\n\n##要求\n1. 如包含多个大区值,用,将值隔开。\n2. 如包含多个司机汽车类型,拆分成多个元素存入列表\n3. 未明确说明司机汽车类型时,默认为全部的枚举值' memory=None reasoning_mode='prompt' vision=VisionConfig(enabled=False, configs=VisionConfigOptions(variable_selector=['sys', 'files'], detail=<DETAIL.HIGH: 'high'>))
len(data.parameters): 2
len(result): 7

reasoning content have json, it will introduce problem.

success:

prompt:
<think>\nWe are given an empty text. According to the instructions, we need to extract the driver's vehicle type and the business big area from the user input.\n However, the text is empty, so there is no input to extract from.\n\n According to the instructions:\n 1. If the business big area is not specified, we should not include it? But note the required field is only \"driver_vehicle_type_list\".\n 2. For driver_vehicle_type_list: if not explicitly stated, the default is all the enumerated values.\n\n The enumerated driver vehicle types are: \n   \"微面包车\", \"小面包车\", \"中面包车\", \"微货车\", \"小货车\", \"中货车\", \"3米8\"\n\n Since the text is empty, we must use the default for driver_vehicle_type_list (all enumerated values) and not include big_area because it's not mentioned.\n\n The structure requires:\n   - driver_vehicle_type_list: array of strings (required)\n   - big_area: string (optional, so we can omit if not provided)\n\n Therefore, we output:\n   {\n     \"driver_vehicle_type_list\": [\"微面包车\", \"小面包车\", \"中面包车\", \"微货车\", \"小货车\", \"中货车\", \"3米8\"]\n   }\n\n Note: We do not include \"big_area\" because it's not mentioned and the instructions don't require it.\n</think>\n```json\n{\n  \"driver_vehicle_type_list\": [\"微面包车\", \"小面包车\", \"中面包车\", \"微货车\", \"小货车\", \"中货车\", \"3米8\"]\n}\n```

2025-11-07 08:28:16,294 INFO [_client.py:1038] ce0f9cc594 HTTP Request: POST http://127.0.0.1:5002/plugin/b7df5634-8029-4c6d-969f-c39e9f7ae646/dispatch/llm/invoke "HTTP/1.1 200 OK"
json_str: {
     "driver_vehicle_type_list": ["微面包车", "小面包车", "中面包车", "微货车", "小货车", "中货车", "3米8"]
   }
result: {'driver_vehicle_type_list': ['微面包车', '小面包车', '中面包车', '微货车', '小货车', '中货车', '3米8']}
data: title='参数提取器' desc=None version='1' error_strategy=None default_value=None retry_config=RetryConfig(max_retries=0, retry_interval=0, retry_enabled=False) model=ModelConfig(provider='langgenius/zhipuai/zhipuai', name='glm-4.5-flash', mode=<LLMMode.CHAT: 'chat'>, completion_params={'temperature': 0.7}) query=[] parameters=[ParameterConfig(name='big_area', type=<SegmentType.STRING: 'string'>, options=None, description='业务大区', required=False), ParameterConfig(name='driver_vehicle_type_list', type=<SegmentType.ARRAY_STRING: 'array[string]'>, options=None, description='司机的汽车类型列表', required=True)] instruction='司机的汽车类型名称枚举值为:微面包车,小面包车,中面包车,微货车,小货车,中货车,3米8\n业务大区的枚举值为:华南,华东,华北,华中,西南,东北\n请根据用户输入问题,精准匹配以上枚举,抽取出对应的司机汽车类型,业务大区参数。\n\n##要求\n1. 如包含多个大区值,用,将值隔开。\n2. 如包含多个司机汽车类型,拆分成多个元素存入列表\n3. 未明确说明司机汽车类型时,默认为全部的枚举值' memory=None reasoning_mode='prompt' vision=VisionConfig(enabled=False, configs=VisionConfigOptions(variable_selector=['sys', 'files'], detail=<DETAIL.HIGH: 'high'>))

https://github.com/langgenius/dify/issues/16152#issuecomment-2757328158 As you said, the reasoning model is not good at extracting parameters, but non-reasoning model maybe also have cause problem.

CrabSAMA avatar Nov 14 '25 10:11 CrabSAMA