Skip to content

fix: recover malformed JSON arguments in write_file tool calls#212

Open
jigangz wants to merge 1 commit intodataelement:mainfrom
jigangz:fix/write-file-path-177
Open

fix: recover malformed JSON arguments in write_file tool calls#212
jigangz wants to merge 1 commit intodataelement:mainfrom
jigangz:fix/write-file-path-177

Conversation

@jigangz
Copy link
Copy Markdown

@jigangz jigangz commented Mar 27, 2026

Summary

Fix write_file tool reporting 'missing path' even when the path parameter is explicitly provided by the LLM.

Problem

When LLMs produce slightly malformed JSON arguments (e.g. trailing commas), json.loads() fails silently and falls back to args = {}. The empty-args guard then returns an error to the LLM saying the path is missing, even though the LLM did provide it.

Changes

  • Better logging: Log the raw argument string and parse error details when JSON parsing fails
  • Fallback cleanup: Attempt to fix common LLM JSON errors (trailing commas before } or ]) before giving up
  • No behavior change for valid JSON — only affects recovery from malformed input

Testing

  • Valid JSON arguments: no change in behavior
  • Malformed JSON with trailing commas: now recovers instead of silently dropping args
  • Completely broken JSON: still falls back to empty args with better logging

Fixes #177

When LLMs produce slightly malformed JSON (trailing commas, etc.),
the argument parser silently falls back to empty args, causing
write_file to report 'missing path' even when the path was provided.

This adds:
1. Detailed logging of JSON parse errors with raw content
2. Fallback cleanup (strip trailing commas) before giving up
3. Better error visibility for debugging

Fixes dataelement#177
@jigangz jigangz marked this pull request as ready for review March 27, 2026 05:20
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.

[Bug] write_file tool returns error about missing path parameter even when it's provided

1 participant