Skip to content

fix(report-agent): tolerate prose/fences around <tool_call> JSON#35

Merged
PRATHAMESH75 merged 1 commit into
mainfrom
fix/report-agent-tool-call-parsing
Jun 21, 2026
Merged

fix(report-agent): tolerate prose/fences around <tool_call> JSON#35
PRATHAMESH75 merged 1 commit into
mainfrom
fix/report-agent-tool-call-parsing

Conversation

@PRATHAMESH75

Copy link
Copy Markdown
Owner

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 text
inside the tag around the JSON, the whole tool call was silently dropped:

<tool_call> body old new
clean {…nested parameters…} ✅ (no change)
JSON + trailing note in tag ❌ dropped ✅ parsed
leading prose before JSON in tag ❌ dropped ✅ parsed
```json fenced JSON in tag ❌ dropped ✅ parsed

Note: this is a robustness hardening, not a nested-parameters fix.
Clean nested objects already parsed — the </tool_call> anchor backtracks the
lazy regex to the outer brace. An earlier diagnosis that nested params were
dropped did not reproduce; a guard test documents that they keep working.

Tests

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

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>
@PRATHAMESH75 PRATHAMESH75 merged commit 3a2e309 into main Jun 21, 2026
2 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.

1 participant