The 'create_json_message(self, json: Mapping | list)' method can only input 'dict'. If 'list' is input, it will be automatically ignored as null #69

Open
opened 2026-02-15 21:15:32 -05:00 by yindo · 0 comments
Owner

Originally created by @xuming9 on GitHub (Dec 24, 2025).

issue

I am creating a plugin tool for converting strings in array format to arrays. After repeated testing and verification, it was found that the method 'creat_json message' can only input 'dict', and if 'list' is input, it will automatically ignore it as null
For example: when entering ['a ','b'] , the plugin should output {"text": "", "files": [], "json": ["a", "b"]} , but in reality it outputs FAIL

background

Name: dify_plugin
Version: 0.6.2
Summary: Dify Plugin SDK
Home-page: https://github.com/langgenius/dify-plugin-sdks.git
Author:
Author-email: langgenius <hello@dify.ai>
License: Apache2.0
Location: C:\Program Files\miniconda3\envs\dify\Lib\site-packages
Requires: dpkt, Flask, gevent, httpx, packaging, pydantic, pydantic_settings, pyyaml, requests, socksio, tiktoken, Werkzeug, yarl
Required-by:

code

py

from collections.abc import Generator
from typing import Any
import json

from dify_plugin import Tool
from dify_plugin.entities.tool import ToolInvokeMessage

import logging
from dify_plugin.config.logger_format import plugin_logger_handler

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(plugin_logger_handler)

class StringToArrayTool(Tool):
    def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]:
        try:
            # Get the input array string
            array_str = tool_parameters.get('string_input', '')
            if not array_str:
                yield self.create_json_message(None)
                return
            
            # Process input string, support both single and double quotes format
            array_str = array_str.strip()
            # logger.info(f"array_str: {array_str}")
            # Convert single quotes to double quotes, support ['a','b','c'] format
            if array_str.startswith("['") and array_str.endswith("']"):
                array_str = array_str.replace("'", '"')
            
            # Try to parse JSON
            parsed_array = json.loads(array_str)
            # Ensure the result is an array
            if isinstance(parsed_array, list):
                yield self.create_json_message(parsed_array)
            else:
                raise ValueError("Input string is not a valid array format")
        except json.JSONDecodeError:
            raise ValueError("Input string is not a valid array format")
        except Exception as e:
            raise ValueError(f"Unknown error occurred: {e}")

** yaml **

outputs:
  type: object
  properties:
    result:
      type: array
      items:
        type: string
      description:
        en_US: "Parsed array result"

log:

[on_tool_execution]
Tool: string-to-array
Outputs: {"type":"json","message":{},"meta":null}

2025-12-25 02:35:32.611 ERROR [Dummy-831] [node.py:329]  - Node 1766625751605 failed to run
Traceback (most recent call last):
  File "/app/api/core/workflow/nodes/base/node.py", line 319, in run
    for event in result:
                 ^^^^^^
  File "/app/api/core/workflow/nodes/tool/tool_node.py", line 132, in _run
    _ = yield from self._transform_message(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/api/core/workflow/nodes/tool/tool_node.py", line 316, in _transform_message
    assert isinstance(message.message, ToolInvokeMessage.JsonMessage)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
Originally created by @xuming9 on GitHub (Dec 24, 2025). ## issue I am creating a plugin tool for converting strings in array format to arrays. After repeated testing and verification, it was found that the method 'creat_json message' can only input 'dict', and if 'list' is input, it will automatically ignore it as null For example: when entering **['a ','b']** , the plugin should output **{"text": "", "files": [], "json": ["a", "b"]}** , but in reality it outputs **FAIL** ## background ``` bash Name: dify_plugin Version: 0.6.2 Summary: Dify Plugin SDK Home-page: https://github.com/langgenius/dify-plugin-sdks.git Author: Author-email: langgenius <hello@dify.ai> License: Apache2.0 Location: C:\Program Files\miniconda3\envs\dify\Lib\site-packages Requires: dpkt, Flask, gevent, httpx, packaging, pydantic, pydantic_settings, pyyaml, requests, socksio, tiktoken, Werkzeug, yarl Required-by: ``` ## code **py** ```python from collections.abc import Generator from typing import Any import json from dify_plugin import Tool from dify_plugin.entities.tool import ToolInvokeMessage import logging from dify_plugin.config.logger_format import plugin_logger_handler logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) logger.addHandler(plugin_logger_handler) class StringToArrayTool(Tool): def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]: try: # Get the input array string array_str = tool_parameters.get('string_input', '') if not array_str: yield self.create_json_message(None) return # Process input string, support both single and double quotes format array_str = array_str.strip() # logger.info(f"array_str: {array_str}") # Convert single quotes to double quotes, support ['a','b','c'] format if array_str.startswith("['") and array_str.endswith("']"): array_str = array_str.replace("'", '"') # Try to parse JSON parsed_array = json.loads(array_str) # Ensure the result is an array if isinstance(parsed_array, list): yield self.create_json_message(parsed_array) else: raise ValueError("Input string is not a valid array format") except json.JSONDecodeError: raise ValueError("Input string is not a valid array format") except Exception as e: raise ValueError(f"Unknown error occurred: {e}") ``` ** yaml ** ```YAML outputs: type: object properties: result: type: array items: type: string description: en_US: "Parsed array result" ``` ## log: ``` [on_tool_execution] Tool: string-to-array Outputs: {"type":"json","message":{},"meta":null} 2025-12-25 02:35:32.611 ERROR [Dummy-831] [node.py:329] - Node 1766625751605 failed to run Traceback (most recent call last): File "/app/api/core/workflow/nodes/base/node.py", line 319, in run for event in result: ^^^^^^ File "/app/api/core/workflow/nodes/tool/tool_node.py", line 132, in _run _ = yield from self._transform_message( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/core/workflow/nodes/tool/tool_node.py", line 316, in _transform_message assert isinstance(message.message, ToolInvokeMessage.JsonMessage) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-sdks#69