fix(report-agent): tolerate prose/fences around <tool_call> JSON#35
Merged
Conversation
Parse the <tool_call> body with the balanced-brace extractor
(llm_sanitizer.extract_json_block) instead of a lazy
`<tool_call>\s*(\{.*?\})\s*</tool_call>` regex.
The old regex required the JSON object to start immediately after the tag
and end immediately before </tool_call>, so it silently dropped tool calls
where a reasoning model added leading prose, a trailing note, or a ```json
code fence inside the tag. (Clean nested `parameters` already parsed fine --
the </tool_call> anchor backtracks the lazy regex to the outer brace -- so
this is a robustness hardening, not a nested-params fix.)
Adds tests for the leading-text, trailing-text, and fenced-JSON cases (which
fail on the old regex) plus a nested-params guard.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Parses the
<tool_call>…</tool_call>body with the balanced-brace extractor(
app/utils/llm_sanitizer.extract_json_block) instead of the lazy<tool_call>\s*(\{.*?\})\s*</tool_call>regex.Why
The old regex required the JSON object to start immediately after the tag
and end immediately before
</tool_call>. When a reasoning model added textinside the tag around the JSON, the whole tool call was silently dropped:
<tool_call>body{…nestedparameters…}```jsonfenced JSON in tagTests
Adds leading-text, trailing-text, and fenced-JSON cases (each fails on the
old regex, passes now) plus a nested-params guard. Full backend suite: 100 passed.
🤖 Generated with Claude Code