SyntaxError: Unterminated string in JSON when responses are parsed in the Google ADK Dev Front-End
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
- Access the Google ADK web application "adk web --host 0.0.0.0"
- 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
groundingMetadatawith a reasonable amount ofretrievedContextinformation. In other words, the response should be very long. - Observe the network traffic (e.g., in browser developer tools) for the SSE stream (
/run_sse). - The client-side JavaScript (within
main-JAAWEV7F.js) attempts to parse the incomingdata:events as JSON. - The
JSON.parseoperation fails with the reportedSyntaxErrorat 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.
See google/adk-python#269
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.
Did you fix this?
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.
Regarding this yesterday update, is this right to say that the next adk-python release will fix this bug ?