fix: improve JSON repair handling for markdown code blocks (#841)

* fix: improve JSON repair handling for markdown code blocks

* unified import path

* compress_crawl_udf

* fix

* reverse
This commit is contained in:
Xun
2026-01-30 08:47:23 +08:00
committed by GitHub
parent 756421c3ac
commit 3adb4e90cb
4 changed files with 394 additions and 6 deletions

View File

@@ -332,9 +332,12 @@ def planner_node(
logger.debug(f"Current state messages: {state['messages']}")
logger.info(f"Planner response: {full_response}")
# Clean the response first to handle markdown code blocks (```json, ```ts, etc.)
cleaned_response = repair_json_output(full_response)
# Validate explicitly that response content is valid JSON before proceeding to parse it
if not full_response.strip().startswith('{') and not full_response.strip().startswith('['):
logger.warning("Planner response does not appear to be valid JSON")
if not cleaned_response.strip().startswith('{') and not cleaned_response.strip().startswith('['):
logger.warning("Planner response does not appear to be valid JSON after cleanup")
if plan_iterations > 0:
return Command(
update=preserve_state_meta_fields(state),
@@ -347,7 +350,7 @@ def planner_node(
)
try:
curr_plan = json.loads(repair_json_output(full_response))
curr_plan = json.loads(cleaned_response)
# Need to extract the plan from the full_response
curr_plan_content = extract_plan_content(curr_plan)
# load the current_plan
@@ -1428,4 +1431,4 @@ async def analyst_node(
config,
"analyst",
[], # No tools - pure reasoning
)
)