[Chore/Refactor] Conversation variables endpoint should returns a valid JSON value #18151

Closed
opened 2026-02-21 19:44:10 -05:00 by yindo · 0 comments
Owner

Originally created by @AkiraVoid on GitHub (Sep 24, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for refactoring, 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.

Description

Currently, the conversation endpoint GET /conversations/{conversation_id}/variables returns a response like:

{
  ...
  "data": [
    {
      ...
      "value_type": "array<string>"
      "value": "['a', 'b', 'c']"
    }
  ]
}

or:

{
  ...
  "data": [
    {
      ...
      "value_type": "object"
      "value": "{'result': None}"
    }
  ]
}

The values such as ['a', 'b', 'c'] and {'result': None} are not valid JSON value, but Python literals, which causes bad capability across different clients.

According to www.json.org:

"A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested."

Those strings in single quotes, None, True, False, are not considered as valid JSON value.

Motivation

Although some of the clients may be able to parse these Python literals into object in their own contexts, and thus they could do more evaluation on the return values, it's not the best practice to leave this problem to clients. The client may not be able to deal with all scenarios when they implementing their own parsing techniques, for example, a general idea is to simply replace all True to true, False to false, None to null, single quotes to double quotes, and then parse it like a normal JSON value, but for JSON values as below, this mechanism will be broken:

{
  "error": "None of the provided parameters are acceptable." // This is a semantic error title, but None will be replaced to null, unexpectedly.
}

The best practice is, the server returns the standard JSON value, which is widely accepted, and can be easily parsed with built-in parsers for the most of the clients.

Additional Context

If it is possible, DO return the real JSON array of string/number for "value_type": "array<string|number>", return the real JSON object for "value_type": "object|array<object>", return real JSON number for "value_type": "number", so that the clients would have no need to parse it by themselves.

Originally created by @AkiraVoid on GitHub (Sep 24, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for refactoring, 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, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Description Currently, the conversation endpoint `GET /conversations/{conversation_id}/variables` returns a response like: ```json { ... "data": [ { ... "value_type": "array<string>" "value": "['a', 'b', 'c']" } ] } ``` or: ```json { ... "data": [ { ... "value_type": "object" "value": "{'result': None}" } ] } ``` The values such as `['a', 'b', 'c']` and `{'result': None}` are not valid JSON value, but Python literals, which causes bad capability across different clients. According to www.json.org: > "A *value* can be a _string in double quotes_, or a _number_, or _true_ or _false_ or _null_, or an _object_ or an _array_. These structures can be nested." Those _strings in single quotes_, _None_, _True_, _False_, are not considered as valid JSON value. ### Motivation Although some of the clients *may* be able to parse these Python literals into object in their own contexts, and thus they could do more evaluation on the return values, it's not the best practice to leave this problem to clients. The client may not be able to deal with all scenarios when they implementing their own parsing techniques, for example, a general idea is to simply replace all True to true, False to false, None to null, single quotes to double quotes, and then parse it like a normal JSON value, but for JSON values as below, this mechanism will be broken: ```jsonc { "error": "None of the provided parameters are acceptable." // This is a semantic error title, but None will be replaced to null, unexpectedly. } ``` The best practice is, the server returns the standard JSON value, which is widely accepted, and can be easily parsed with built-in parsers for the most of the clients. ### Additional Context If it is possible, **DO** return the real JSON array of string/number for `"value_type": "array<string|number>"`, return the real JSON object for `"value_type": "object|array<object>"`, return real JSON number for `"value_type": "number"`, so that the clients would have no need to parse it by themselves.
yindo added the refactor label 2026-02-21 19:44:10 -05:00
yindo closed this issue 2026-02-21 19:44:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#18151