Skip to content

feat(tools): parse fenced and embedded JSON in filter_tools - #115

Merged
wxai-space merged 2 commits into
wanxingai:mainfrom
wjl8636:fix/filter-tools-markdown-fence
Oct 28, 2026
Merged

wxai-space merged 2 commits into
wanxingai:mainfrom
wjl8636:fix/filter-tools-markdown-fence

Conversation

@wjl8636

@wjl8636 wjl8636 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What

filter_tools() only stripped an exact ``json ... ``` fence beforejson.loads(). LLM tool-reflection output commonly wraps the payload in a plain `` fence (no language tag) or embeds it between prose, which made the call raise ValueError and abort tool filtering.

Why

Add a best-effort _extract_json_payload() that pulls the payload out of a fenced block (with or without the json tag), or from the first JSON object, before falling back to the raw text. Truly invalid input still raises ValueError, preserving documented behavior.

How I verified

  • Added 7 tests in tests/test_tool_schema_validation.py covering plain JSON, json-fenced, plain-fenced, prose-surrounded, prose-embedded, and two failure shapes.
  • Full suite: 372 passed.

wjl8636 and others added 2 commits October 7, 2026 17:40
filter_tools only stripped an exact ```json ... ``` fence before
json.loads(). LLM tool-reflection output commonly wraps the payload in a
plain ``` fence (no language tag) or embeds it between prose, which made
the call raise ValueError and abort tool filtering.

Add a best-effort _extract_json_payload() that pulls the payload out of a
fenced block (with or without the json tag), or from the first JSON object,
before falling back to the raw text. Truly invalid input still raises
ValueError, preserving documented behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@wxai-space

Copy link
Copy Markdown
Collaborator

The contribution is retained in follow-up PR #120 with the original commits and attribution. The follow-up preserves valid JSON containing embedded fences, replaces greedy object extraction with structural decoding, rejects conflicting tool selections, and adds the missing regression coverage. Full local regression: 387 passed, 1 explicitly opt-in backend test skipped. #120 is submitted for review only; neither PR has been merged.

@wxai-space

Copy link
Copy Markdown
Collaborator

The completed fixes have now been appended directly to this original contributor branch at 0cb40e0, preserving the existing commits and attribution. The newly triggered CI run passed all 4 checks: https://github.com/wanxingai/LightAgent/actions/runs/40616538629 . Supplemental PR #120 has been closed as redundant. This original PR remains open and unmerged for your review; main has not been modified.

@wxai-space
wxai-space merged commit 3b13ca2 into wanxingai:main Oct 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants