Skip to content

Commit 3ea331d

Browse files
committed
fix(agent): Autofix trailing commas in LLM-generated JSON
1 parent db3b335 commit 3ea331d

File tree

1 file changed

+4
-0
lines changed
  • samples/agent/adk/restaurant_finder

1 file changed

+4
-0
lines changed

samples/agent/adk/restaurant_finder/agent.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import json
1616
import logging
1717
import os
18+
import re
1819
from collections.abc import AsyncIterable
1920
from typing import Any
2021

@@ -226,6 +227,9 @@ async def stream(self, query, session_id) -> AsyncIterable[dict[str, Any]]:
226227
if not json_string_cleaned:
227228
raise ValueError("Cleaned JSON string is empty.")
228229

230+
# Autofix: Remove trailing commas from arrays and objects
231+
json_string_cleaned = re.sub(r",\s*([\]}])", r"\1", json_string_cleaned)
232+
229233
# --- New Validation Steps ---
230234
# 1. Check if it's parsable JSON
231235
parsed_json_data = json.loads(json_string_cleaned)

0 commit comments

Comments
 (0)