langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Unicode output in Stringify mode is escaped (\uXXXX) instead of readable text

Open tchr-dev opened this issue 1 year ago • 2 comments

Bug Description

When using the ParserComponent in "Stringify" mode, any non-ASCII characters (e.g., Cyrillic, Chinese, etc.) are escaped into Unicode sequences like \u043c, instead of being displayed as readable text. This makes the output hard to read and inappropriate for multilingual applications.

📋 Description When passing a Data object that contains Unicode characters to ParserComponent in "Stringify" mode, the output is not human-readable due to the default behavior of json.dumps() escaping non-ASCII characters.

🧪 Example Input:

{
  "магия": ["Магия требует концентрации"]
}

Current output:

{"\u043c\u0430\u0433\u0438\u044f": ["\u041c\u0430\u0433\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0430\u0446\u0438\u0438"]}

Expected output:

{"магия": ["Магия требует концентрации"]}

Solution:

def _safe_convert(self, data: Any) -> str:
    """Safely convert input data to string."""
    try:
        if isinstance(data, str):
            return data
        if isinstance(data, Message):
            return data.get_text()
        if isinstance(data, Data):
            return json.dumps(data.data, ensure_ascii=False)  # 🔧 Major fix
        if isinstance(data, DataFrame):
            if hasattr(self, "clean_data") and self.clean_data:
                data = data.dropna(how="all")
                data = data.replace(r"^\s*$", "", regex=True)
                data = data.replace(r"\n+", "\n", regex=True)
            return data.to_markdown(index=False)
        return str(data)
    except (ValueError, TypeError, AttributeError) as e:
        msg = f"Error converting data: {e!s}"
        raise ValueError(msg) from e

Reproduction

  1. Use YAML file:
{
  "магия": ["Магия требует концентрации"]
}
  1. Use component File
  2. Use component Parser
  3. Check Parser output:
{"\u043c\u0430\u0433\u0438\u044f": ["\u041c\u0430\u0433\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043d\u0442\u0440\u0430\u0446\u0438\u0438"]}

Expected behavior

Expected output:

{"магия": ["Магия требует концентрации"]}

Who can help?

No response

Operating System

macOS 15.3.2

Langflow Version

1.3.4

Python Version

3.12

Screenshot

No response

Flow File

No response

tchr-dev avatar Apr 16 '25 16:04 tchr-dev

Hello @tchr-dev! I'm Dosu, a bot here to help you solve bugs, answer questions, and guide you as a contributor. I'm ready to assist you while you wait for a human maintainer. Let's tackle this together!

To address the issue of Unicode characters being escaped in "Stringify" mode, you can modify the _safe_convert method in the ParserComponent to ensure that Unicode characters are displayed as readable text. This can be achieved by setting the ensure_ascii parameter to False in the json.dumps function. Here's the updated method:

def _safe_convert(self, data: Any) -> str:
    """Safely convert input data to string."""
    try:
        if isinstance(data, str):
            return data
        if isinstance(data, Message):
            return data.get_text()
        if isinstance(data, Data):
            # Ensure Unicode characters are not escaped
            return json.dumps(data.data, ensure_ascii=False)
        if isinstance(data, DataFrame):
            if hasattr(self, "clean_data") and self.clean_data:
                data = data.dropna(how="all")
                data = data.replace(r"^\s*$", "", regex=True)
                data = data.replace(r"\n+", "\n", regex=True)
            return data.to_markdown(index=False)
        return str(data)
    except (ValueError, TypeError, AttributeError) as e:
        msg = f"Error converting data: {e!s}"
        raise ValueError(msg) from e

By making this change, the json.dumps function will output Unicode characters as they are, rather than escaping them into Unicode sequences [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Apr 16 '25 16:04 dosubot[bot]

Is this still happening?

andifilhohub avatar Feb 13 '26 18:02 andifilhohub