ragflow icon indicating copy to clipboard operation
ragflow copied to clipboard

[Question]: Text2SQL agent running with error: "the JSON object must be str, bytes or bytearray, not float"

Open mobguang opened this issue 6 months ago • 3 comments

Self Checks

  • [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 (Language Policy).
  • [x] Non-english title submitions will be closed directly ( 非英文标题的提交将会被直接关闭 ) (Language Policy).
  • [x] Please do not modify this template :) and fill in all the required fields.

Describe your problem

Hello,

I launched RagFlow nightly version by docker. And I followed the instruction (https://ragflow.io/docs/v0.19.0/text2sql_agent) to build the text2SQL agent demo.

My system configuration information as following:

  1. Machine is M2 Mac
  2. The chat LLM is deepseek-r1 API
  3. Embedding model is BAAI/bge-large-zh-v1.5

The error "the JSON object must be str, bytes or bytearray, not float" was reported when I run the agent. Please refer to the following screenshot. Please kind provide solution to solve it. Thanks.

Image

mobguang avatar Jun 17 '25 03:06 mobguang

The error "the JSON object must be str, bytes or bytearray, not float" happens when a float value is passed to a JSON function expecting a string. In the Text2SQL agent, this usually means that somewhere in the pipeline, a float (or other non-string type) is ending up in a field—often called "content"—that downstream code expects to always be a string. When the API or UI tries to parse or serialize this, it triggers the error.

This is a known class of issue in RAGFlow. The recommended fix is to ensure that all outputs (especially the "content" field in agent results) are always cast to string before being returned or serialized. The ExeSQL component, for example, should wrap any non-string content in str() before outputting it. This hardens the pipeline against similar type errors elsewhere as well. You can see this pattern in other fixes and discussions for related issues in the repo (example).

If you are already using the latest nightly Docker image and still see this error, double-check any customizations or upstream data sources that might be returning floats or other non-string types as content. If you are using a custom embedding model or have modified the agent pipeline, make sure all returned values are strings where JSON is expected (reference).

If you need to patch locally, look for the place where the agent or ExeSQL component builds its output and wrap the "content" value with str() before returning or serializing it. This should resolve the error.

To reply, just mention @dosu.


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

dosubot[bot] avatar Jun 17 '25 03:06 dosubot[bot]

@dosu,

I just executed a simple query: "售价最高的是哪个商品", but the same error still existed.

Image

The console output as following: 2025-06-17 11:32:10,054 INFO 29 172.18.0.6 - - [17/Jun/2025 11:32:10] "POST /v1/kb/list HTTP/1.1" 200 - 2025-06-17 11:32:10,075 INFO 29 172.18.0.6 - - [17/Jun/2025 11:32:10] "GET /v1/llm/list HTTP/1.1" 200 - 2025-06-17 11:32:37,743 INFO 39 task_executor_24ef5b1d6505_0 reported heartbeat: {"name": "task_executor_24ef5b1d6505_0", "now": "2025-06-17T11:32:37.740+08:00", "boot_at": "2025-06-16T20:05:36.550+08:00", "pending": 0, "lag": 0, "done": 0, "failed": 0, "current": {}} 2025-06-17 11:32:55,758 WARNING 29 /ragflow/agent/component/generate.py:94: FutureWarning: A value is trying to be set on a copy of a DataFrame or Series through chained assignment using an inplace method. The behavior will change in pandas 3.0. This inplace method will never work because the intermediate object on which we are setting values always behaves as a copy.

For example, when doing 'df[col].method(value, inplace=True)', try using 'df.method({col: value}, inplace=True)' or df[col] = df[col].method(value) instead, to perform the operation inplace on the original object.

retrieval_res["empty_response"].fillna("", inplace=True)

2025-06-17 11:32:55,761 ERROR 29 Canvas.run got exception: the JSON object must be str, bytes or bytearray, not float Traceback (most recent call last): File "/ragflow/agent/canvas.py", line 231, in prepare2run ans = cpn.run(self.history, **kwargs) File "/ragflow/agent/component/base.py", line 378, in run raise e File "/ragflow/agent/component/base.py", line 374, in run res = self._run(history, **kwargs) File "/ragflow/agent/component/generate.py", line 230, in _run res = self.set_cite(retrieval_res, ans) File "/ragflow/agent/component/generate.py", line 95, in set_cite chunks = json.loads(retrieval_res["chunks"][0]) File "/usr/lib/python3.10/json/init.py", line 339, in loads raise TypeError(f'the JSON object must be str, bytes or bytearray, ' TypeError: the JSON object must be str, bytes or bytearray, not float Traceback (most recent call last): File "/ragflow/api/apps/canvas_app.py", line 142, in sse for ans in canvas.run(running_hint_text = running_hint_text, stream=True): File "/ragflow/agent/canvas.py", line 280, in run for m in prepare2run(downstream): File "/ragflow/agent/canvas.py", line 236, in prepare2run raise e File "/ragflow/agent/canvas.py", line 231, in prepare2run ans = cpn.run(self.history, **kwargs) File "/ragflow/agent/component/base.py", line 378, in run raise e File "/ragflow/agent/component/base.py", line 374, in run res = self._run(history, **kwargs) File "/ragflow/agent/component/generate.py", line 230, in _run res = self.set_cite(retrieval_res, ans) File "/ragflow/agent/component/generate.py", line 95, in set_cite chunks = json.loads(retrieval_res["chunks"][0]) File "/usr/lib/python3.10/json/init.py", line 339, in loads raise TypeError(f'the JSON object must be str, bytes or bytearray, ' TypeError: the JSON object must be str, bytes or bytearray, not float

mobguang avatar Jun 17 '25 03:06 mobguang

Noted. We're refining and refactoring this part.

KevinHuSh avatar Jun 18 '25 03:06 KevinHuSh

I also unfortunately encountered this problem

Kolo7 avatar Jul 23 '25 15:07 Kolo7