Skip to content

fix(opencode): add JSON validation for tool call arguments#17818

Open
LehaoLin wants to merge 2 commits intoanomalyco:devfrom
LehaoLin:fix/tool-call-json-validation
Open

fix(opencode): add JSON validation for tool call arguments#17818
LehaoLin wants to merge 2 commits intoanomalyco:devfrom
LehaoLin:fix/tool-call-json-validation

Conversation

@LehaoLin
Copy link
Copy Markdown

Issue for this PR

Closes #17750

Type of change

  • Bug fix

What does this PR do?

Problem: SiliconFlow Qwen3-8B model returns tool call arguments with XML tags that break JSON parsing.

Solution: Strip XML artifacts and validate JSON before emitting tool-call events in both streaming and non-streaming modes.

How did you verify your code works?

  • Verified regex pattern for XML tag removal
  • Verified JSON validation logic applied to both modes
  • Verified proper TypeScript syntax and indentation
  • All unit tests and typecheck pass

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Strip XML artifacts and validate JSON before emitting tool-call events

- Fix non-streaming mode (doGenerate)
- Fix streaming mode (flush)
- Strip tool_call XML tags from providers like SiliconFlow
- Validate JSON with isParsableJson before use
- Skip invalid tool calls with warning

Fixes anomalyco#17750
@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found one potentially related PR:

PR #17339: fix(opencode): handle repeated full streamed tool-call arguments
#17339

Why it might be related: Both PRs address tool call argument handling. PR #17339 deals with repeated full streamed tool-call arguments, which could be related to the streaming mode JSON validation fix in PR #17818. However, these appear to be addressing different specific issues - #17339 focuses on repeated arguments in streaming, while #17818 focuses on XML artifact removal and JSON validation.

No duplicate PRs found

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.

Tool call arguments may contain invalid JSON

1 participant