adk-web icon indicating copy to clipboard operation
adk-web copied to clipboard

SyntaxError: Unterminated string in JSON when responses are parsed in the Google ADK Dev Front-End

Open DavidLJz opened this issue 6 months ago • 5 comments

Image

Image

I am consistently encountering a SyntaxError: Unterminated string in JSON when responses are parsed in the Google ADK auto-generated web app's client side code. The error occurs specifically at position 4004 (line 1 column 4005), indicating that the JSON string being received is truncated.

This issue makes testing difficult from correctly processing the full response from the ADK, as the JSON.parse operation fails due to incomplete data.

OS: Windows 11 Python version(python -V): 3.12 ADK version(pip show google-adk): v1.4.1 Google ADK Dev Web App: "adk web --host 0.0.0.0" Google Chrome

Steps to Reproduce

  1. Access the Google ADK web application "adk web --host 0.0.0.0"
  2. Initiate a request that elicits a response from the ADK AND includes information from the RAG which exceeds the 1024 characters. The response from server should include groundingMetadata with a reasonable amount of retrievedContext information. In other words, the response should be very long.
  3. Observe the network traffic (e.g., in browser developer tools) for the SSE stream (/run_sse).
  4. The client-side JavaScript (within main-JAAWEV7F.js) attempts to parse the incoming data: events as JSON.
  5. The JSON.parse operation fails with the reported SyntaxError at column 4005, indicating a truncated JSON string.

Expected Behavior

The Google ADK web app should send complete and valid JSON objects within its SSE data: events and the message must be shown in the application front-end

Actual Behavior

The JSON string received via the SSE stream is truncated at approximately 4004 characters, leading to a SyntaxError: Unterminated string in JSON during parsing.

Relevant Information

  • Error Message:

    main-JAAWEV7F.js:22 ERROR SyntaxError: Unterminated string in JSON at position 4004 (line 1 column 4005)
        at JSON.parse (<anonymous>)
        at e.<anonymous> (main-JAAWEV7F.js:91:2736)
        at Generator.next (<anonymous>)
        at main-JAAWEV7F.js:16:807
        at new M (polyfills-B6TNHZQ6.js:17:2237)
        at Ze (main-JAAWEV7F.js:16:627)
        at Object.next (main-JAAWEV7F.js:91:2638)
        at Dl.next (main-JAAWEV7F.js:18:3112)
        at xo._next (main-JAAWEV7F.js:18:2795)
        at xo.next (main-JAAWEV7F.js:18:2522)
    

I suspect there might be an internal message size limit or buffering issue within the Google ADK's SSE clientside or backend, causing responses exceeding a certain length (around 4KB in this case) to be prematurely truncated before reaching the client's parsing logic. Ensuring that complete JSON objects are sent for each data: event would resolve this problem.

DavidLJz avatar Jun 21 '25 01:06 DavidLJz

See google/adk-python#269

DavidLJz avatar Jun 21 '25 01:06 DavidLJz

I have also met this problem in adk 1.4.2. The error Unterminated string starting at: line 1 column 7764 (char 7763) or json.decoder.JSONDecodeError: Extra data: line 3 column 1 (char 289) would occur at anytime of the output streaming (Most errors occur when generating longer text, and a small portion also occur when generating shorter text). I think some of the information transmitted in the SSE mode might be incomplete and cannot be parsed as the "Event" type.

YangZH1997 avatar Jun 24 '25 10:06 YangZH1997

Did you fix this?

Vihanga22365 avatar Jun 27 '25 01:06 Vihanga22365

Did you fix this?

I had to directly clone the adk-web from newest commit, compile it, serve it and use it in my project.

Because running the adk-web command from the adk-python package uses the oudated version that still has this error.

DavidLJz avatar Jun 28 '25 21:06 DavidLJz

Regarding this yesterday update, is this right to say that the next adk-python release will fix this bug ?

florent-andre avatar Jul 01 '25 16:07 florent-andre